Catalyst-Model-LDAP

 view release on metacpan or  search on metacpan

lib/Catalyst/Model/LDAP/Entry.pm  view on Meta::CPAN

package Catalyst::Model::LDAP::Entry;
# ABSTRACT: Convenience methods for Net::LDAP::Entry

use strict;
use warnings;
use base qw/Net::LDAP::Entry Class::Accessor::Fast/;
use Carp qw/croak/;
use MRO::Compat;

__PACKAGE__->mk_accessors(qw/_ldap_client/);


sub new {
    my ( $class, $dn, %attributes ) = @_;

    my $client = delete $attributes{_ldap_client};

    my $self = $class->next::method( $dn, %attributes );

    if ($client) {
        $self->_ldap_client($client);
    }

    return $self;
}


sub update {
    my $self = shift;
    my $client = shift || $self->_ldap_client;
    croak 'No LDAP client provided to update' unless $client;

    return $self->next::method( $client, @_ );
}


sub can {
    my ( $self, $method ) = @_;
    return 0 unless ref($self);
    $self->exists($method) || $self->SUPER::can($method);
}

sub AUTOLOAD {
    my ( $self, @args ) = @_;

    my ($attribute) = ( our $AUTOLOAD =~ /([^:]+)$/ );
    return if $attribute eq 'DESTROY';

    croak qq[Can't locate object method "$attribute" via package "]
      . ref($self) . qq["]
      unless $self->exists($attribute);

    if ( scalar @args ) {
        $self->replace( $attribute, @args );
    }

    return $self->get_value($attribute);
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Catalyst::Model::LDAP::Entry - Convenience methods for Net::LDAP::Entry

=head1 VERSION

version 0.21

=head1 SYNOPSIS

    # In your controller
    my $mesg = $c->model('Person')->search('(cn=Lou Rhodes)');
    my $entry = $mesg->shift_entry;
    print $entry->title;

=head1 DESCRIPTION

This module simplifies use of L<Net::LDAP::Entry> objects in your
application.  It makes accessors and mutators for all attributes on an
entry.  For example:



( run in 0.504 second using v1.01-cache-2.11-cpan-39bf76dae61 )