/[A3C]/lib/A3C/LDAP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/A3C/LDAP.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 36 by dpavlin, Sun Mar 30 00:02:18 2008 UTC revision 40 by dpavlin, Sun Mar 30 15:02:55 2008 UTC
# Line 5  use warnings; Line 5  use warnings;
5    
6  use Net::LDAP;  use Net::LDAP;
7  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
8  use base 'Jifty::Object';  use base qw(Jifty::Object Class::Accessor::Fast);
9    __PACKAGE__->mk_accessors( qw(ldap server dn password current_search) );
10    
 my $ldap_config = Jifty->config->app('LDAP');  
11    
12  Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) );  =head1 NAME
13    
14  my $ldap = Net::LDAP->new( $ldap_config->{Server} ) or die "$@";  A3C::LDAP
15    
16  # an anonymous bind  =head1 DESCRIPTION
 #my $mesg = $ldap->bind;  
 my $mesg = $ldap->bind( $ldap_config->{DN}, password => $ldap_config->{Password} );  
17    
18  Jifty->log->info("Connected to ", $ldap_config->{Server}, " with DN ", $ldap_config->{DN});  This object turn L<Net::LDAP> into something with looks like
19    L<Jifty::Collection>
20    
21    =head1 METHODS
22    
23    =head2 new
24    
25      my $ldap = A3C::LDAP->new;
26    
27    =cut
28    
29    sub new {
30            my $class = shift;
31    
32            my $args = { @_ };
33    
34            my $ldap_config = Jifty->config->app('LDAP');
35            Jifty->log->debug( "config->app(LDAP) = ",dump( $ldap_config ) );
36    
37            $args->{server}         ||= $ldap_config->{Server};
38            $args->{dn}                     ||= $ldap_config->{DN};
39            $args->{password}       ||= $ldap_config->{Password};
40    
41            my $ldap = Net::LDAP->new( $args->{server} ) or die "$@";
42    
43            # an anonymous bind
44            #$ldap->bind;
45            $ldap->bind( $args->{dn}, password => $args->{password} );
46    
47            Jifty->log->info("Connected to ", $args->{server}, " with DN ", $args->{dn});
48    
49            $args->{ldap} = $ldap;
50    
51            $class->SUPER::new( $args );
52    }
53    
54    =head2 search
55    
56      my $msg = A3C::LDAP->search(
57                            base    => 'dc=skole,dc=hr',
58                            filter  => '(objectClass=hrEduOrg)',
59                            sizelimit => 10,
60      );
61    
62    =cut
63    
64  sub search {  sub search {
65          my $self = shift;          my $self = shift;
66    
67          return $ldap->search( @_ );          my $search = $self->ldap->search( @_ );
68            if ( $search->code != 0 ) {
69                    Jifty->log->error( $search->error );
70            }
71            return $self->current_search( $search );
72    }
73    
74    =head2 next
75    
76    Syntaxtic shugar to look more like L<Jifty::DBI::Collection>
77    
78      my $entry = ldap->next;
79    
80    =cut
81    
82    sub next {
83            my $self = shift;
84    
85            die "no current LDAP search" unless $self->current_search;
86    
87            return $self->current_search->shift_entry;
88    }
89    
90    =head2 count
91    
92      my $search_results = $ldap->count;
93    
94    =cut
95    
96    sub count {
97            my $self = shift;
98            $self->current_search->count;
99  }  }
100    
101  1;  1;

Legend:
Removed from v.36  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26