Re: Net::LDAP object inside a callback function

[email protected] (Chris Ridd) Mon, 30 Mar 2015 19:33:24 +0100
Newsgroups perl.ldap
Message-ID <[email protected]>
> On 30 Mar 2015, at 19:01, T=C3=A9ssio Fechine <[email protected]> =
wrote:
>=20
> Hi,
>=20
> I want to pass a callback function to a search command. My function, =
compare_attributes, uses the method compare on the entry object passed =
as the 2th parameter. Is there a way to use the method compare without =
making the Net::LDAP object a global?
>=20
> sub compare_attributes
> (...)
> foreach my $a (keys %ATTR) {
> $mesg =3D $LDAP->compare($entry, attr =3D> $a, value =3D> $ATTR{$a});
> (...)

I haven't looked in the debugger yet to verify, but I think you can call =
->parent on the first argument passed to the callback to get the =
Net::LDAP object.

This is only based on looking at 'sub entry' and 'sub decode' in =
Search.pm - the latter shows how the callback is called, and the former =
shows us using ->parent.

HTH!

Chris=