Skip to content

Instantly share code, notes, and snippets.

@AlD
Created March 14, 2013 16:12
Show Gist options
  • Save AlD/5162690 to your computer and use it in GitHub Desktop.
Save AlD/5162690 to your computer and use it in GitHub Desktop.
Add a default search base to Net::LDAP via new(base => $base)
package Net::LDAP::Wrapper;
use strict;
use parent 'Net::LDAP';
my $_base;
sub new {
my $class = shift;
my $host = shift;
my %opts = (@_);
if (exists($opts{base})) {
$_base = $opts{base};
delete $opts{base};
}
my $self = $class->SUPER::new($host, %opts);
return $self;
}
sub search {
my $self = shift;
push(@_, base => $_base) if $_base;
return $self->SUPER::search(@_);
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment