package Example; use Moose; use Net::LDAP; # Options related to SSH has [qw( host user )] => ( is => "ro", isa => "Str", required => 1, ); has ldap_class => ( is => "ro", builder => "_build_ldap_class", ); has ldap => ( is => "ro", lazy => 1, builder => "_build_ldap", ); has error => ( is => "rw", isa => "Str", ); sub _build_ldap_class { return "Net::LDAP"; } sub _build_ldap { my $self = shift; return $self->ldap_class->new( $self->host ); } sub get_user { my $self = shift; my $user = $self->user; my $host = $self->host; my $mesg = $self->ldap->bind; $mesg = $self->ldap->search(filter => "(uid=$user)"); ... }