Getting CurrentUser reference in Users overlay file

Hi,

I intend to filter the results returned by SimpleSearch method in Users.pm
based on the custom field value set in the current user logged in.

I am using Hook::LexWrap in the Users_Local.pm overlay file, to write a
post method to filter the results of SimpleSearch. How can I get a ref of
CurrentUser which in turn will help to fetch the custom field value on that
user?

I tried using
my $user = $self->CurrentUser;

But getting the following error:
[error]: Can’t locate object method “CurrentUser” via package “Privileged”
(perhaps you forgot to load “Privileged”?)

Can anybody suggest what am I doing wrong here?

Thanks in Advance.

-Aniket

My bad, in the above script, the $self was holding the 1st argument, rather
than the reference of RT::Users class.

The original subroutine returns the ref of RT::Users.
As per the documentation of Hook::Lexwrap, the returned value from the
original subroutine should be accessible from the post subroutine using
$_[-1].

When I access $_[-1], using print or warn, I get the warning

  • [warning]: Use of uninitialized value $_[-1] in concatenation (.) or
    string*

Users_Local.pm
package RT::Users;
use strict;
use Hook::LexWrap;
wrap ‘SimpleSearch’ =>
post=> sub {
RT::Logger->info(“accessing return value here $[-1]");
RT::Logger->info("I got the arguments in post: [@
]”);
},
;
1;

Can anybody please help how will I be able to fetch the value returned by
the original subroutine ?
Thanks.On Tue, Jun 21, 2016 at 1:05 PM, aniket tripathy aniket.tripathy@gmail.com wrote:

Hi,

I intend to filter the results returned by SimpleSearch method in Users.pm
based on the custom field value set in the current user logged in.

I am using Hook::LexWrap in the Users_Local.pm overlay file, to write a
post method to filter the results of SimpleSearch. How can I get a ref of
CurrentUser which in turn will help to fetch the custom field value on that
user?

I tried using
my $user = $self->CurrentUser;

But getting the following error:
[error]: Can’t locate object method “CurrentUser” via package “Privileged”
(perhaps you forgot to load “Privileged”?)

Can anybody suggest what am I doing wrong here?

Thanks in Advance.

-Aniket