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

Contents of /lib/A3C/LDAP.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 40 - (show annotations)
Sun Mar 30 15:02:55 2008 UTC (16 years ago) by dpavlin
File size: 1709 byte(s)
Turn A3C::LDAP into real object which looks more like Jifty::Collection
1 package A3C::LDAP;
2
3 use strict;
4 use warnings;
5
6 use Net::LDAP;
7 use Data::Dump qw/dump/;
8 use base qw(Jifty::Object Class::Accessor::Fast);
9 __PACKAGE__->mk_accessors( qw(ldap server dn password current_search) );
10
11
12 =head1 NAME
13
14 A3C::LDAP
15
16 =head1 DESCRIPTION
17
18 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 {
65 my $self = shift;
66
67 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;

  ViewVC Help
Powered by ViewVC 1.1.26