On Jun 18, 2007, at 11:12 AM, [EMAIL PROTECTED] wrote:
Greetings,
I'm trying to add a method to Net::LDAP (through Net::LDAP::Extra)
so I
can ask for the host IP at a later time. I'm using Perl 5.8.4 and
Net::LDAP 0.32 (from Net/LDAP.pm) on a GNU/Linux 3.1 Debian box.
This is my test code:
in /test/Net/LDAP/Extra/host_ip.pm:
package Net::LDAP::Extra::host_ip;
use Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw( &host_ip );
Change that to @EXPORT instead of @EXPORT_OK
Graham.
sub host_ip
{
return shift->{net_ldap_host};
}
1;
in /etc/test.pl:
use Net::LDAP;
use Net::LDAP::Extra qw(host_ip);
use My::Data;
my ( $ip, $port, $binddn, $password ) = My::Data::get_ldap_data();
my $ldap = Net::LDAP->new( $ip, port => $port );
$ldap->bind( $binddn, password => $password );
print "Host: ", $ldap->host_ip, "\n";
__END__
But I get:
Uncaught exception from user code:
Can't locate object method "host_ip" via package
"Net::LDAP" at test.pl line 8
Debugging I see the Net::LDAP::Extra::host_ip::BEGIN/host_ip and
Net::LDAP::Extra::import functions defined... When I define this
function in the debugger when executing Net::LDAP::new, it works
(obviously, as I'm working in the correct package, but it's cheating)
Any pointers to what I'm doing wrong? The reason I'd like to add this
methos is so I can program a backup routine at a later time, where
I am
handed a Net::LDAP object and I test the different LDAPs serving my
program, and make decisions based, among other things, on the IP of
the
host I got a (at least at first) working connection.
The second part is programming a read-write reconnection to another
LDAP
when the one serving me is in read-only mode (and I get a referal,
but I
guess I'll have to play around with callbacks to get this working?)
Thanks for all,
david