/[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

Annotation of /lib/A3C/LDAP.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (hide annotations)
Sun Mar 30 15:23:35 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 1858 byte(s)
document internal method
1 dpavlin 36 package A3C::LDAP;
2    
3     use strict;
4     use warnings;
5    
6     use Net::LDAP;
7     use Data::Dump qw/dump/;
8 dpavlin 40 use base qw(Jifty::Object Class::Accessor::Fast);
9     __PACKAGE__->mk_accessors( qw(ldap server dn password current_search) );
10 dpavlin 36
11    
12 dpavlin 40 =head1 NAME
13 dpavlin 36
14 dpavlin 40 A3C::LDAP
15 dpavlin 36
16 dpavlin 40 =head1 DESCRIPTION
17 dpavlin 36
18 dpavlin 40 This object turn L<Net::LDAP> into something with looks like
19     L<Jifty::Collection>
20 dpavlin 36
21 dpavlin 40 =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 dpavlin 36 sub search {
65     my $self = shift;
66    
67 dpavlin 40 my $search = $self->ldap->search( @_ );
68     if ( $search->code != 0 ) {
69     Jifty->log->error( $search->error );
70     }
71     return $self->current_search( $search );
72 dpavlin 36 }
73    
74 dpavlin 40 =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 dpavlin 41 =head1 INTERNAL METHODS
102    
103     Following methods map directly into L<Net::LDAP>
104    
105     =head2 current_search
106    
107     Result of last C<< $ldap->search >> request
108    
109     =cut
110    
111 dpavlin 36 1;

  ViewVC Help
Powered by ViewVC 1.1.26