1POE::Component::Client:U:sLeDrAPC(o3n)tributed Perl DocuPmOeEn:t:aCtoimopnonent::Client::LDAP(3)
2
3
4
6 POE::Component::Client::LDAP - subclass of Net::LDAP which uses POE to
7 speak via sockets in async mode.
8
10 use POE;
11 use POE::Component::Client::LDAP;
12
13 POE::Session->create(
14 inline_states => {
15 _start => sub {
16 my ($heap, $session) = @_[HEAP, SESSION];
17 $heap->{ldap} = POE::Component::Client::LDAP->new(
18 'localhost',
19 callback => $session->postback( 'connect' ),
20 );
21 },
22 connect => sub {
23 my ($heap, $session, $callback_args) = @_[HEAP, SESSION, ARG1];
24 if ( $callback_args->[0] ) {
25 $heap->{ldap}->bind(
26 callback => $session->postback( 'bind' ),
27 );
28 }
29 else {
30 delete $heap->{ldap};
31 print "Connection Failed\n";
32 }
33 },
34 bind => sub {
35 my ($heap, $session) = @_[HEAP, SESSION];
36 $heap->{ldap}->search(
37 base => "ou=People,dc=domain,dc=net",
38 filter => "(objectClass=person)",
39 callback => $session->postback( 'search' ),
40 );
41 },
42 search => sub {
43 my ($heap, $ldap_return) = @_[HEAP, ARG1];
44 my $ldap_search = shift @$ldap_return;
45
46 foreach (@$ldap_return) {
47 print $_->dump;
48 }
49
50 delete $heap->{ldap} if $ldap_search->done;
51 },
52 },
53 );
54
55 POE::Kernel->run();
56
58 POE::Component::Client::LDAP->new() starts up a new POE::Session and
59 POE::Wheel to manage socket communications for an underlying Net::LDAP
60 object, allowing it to be used in async mode properly within a POE
61 program.
62
64 With regards to Net::LDAP, all interfaces are to be used as documented,
65 with the following exceptions.
66
67 POE::Component::Client::LDAP->new( hostname, OPTIONS ) =item
68 POE::Component::Client::LDAP->new( OPTIONS ) =item
69 POE::Component::Client::LDAP->new()
70 A call to new() is non-blocking, always returning an object.
71
72 If a hostname is supplied, new() also acts as though you have called
73 connect(). Please read the docs for connect() to see how the
74 arguments work.
75
76 $object->connect( hostname, OPTIONS ) =item $object->connect( OPTIONS )
77 =item $object->connect()
78 The 'callback' argument has been added and should always be supplied
79 to notify your code when a connection is established.
80
81 Only LDAP connections are supported at this time, LDAPS and LDAPI
82 will be in a future release.
83
84 Connection errors are not handled at this time, again in a future
85 release.
86
87 The 'async' option is always turned on, and whatever value you pass
88 in will be ignored.
89
90 $object->async()
91 Async mode is always turned on and so this call will always return
92 true, if you pass it a value to set it a fatal exception will be
93 raised, even if value is true.
94
95 $object->sync()
96 Async mode is required, this call will cause a fatal exception.
97
98 $object->sock()
99 This call will throw a fatal exception.
100
101 Because POE is being used to handle socket communications I have
102 chosen to not expose the raw socket at this time.
103
105 The callback semantics documented here are for reference, the callbacks
106 are handled by Net::LDAP and I've only documented them for reference
107 here. The exception to this is the callback for new() which does not
108 exist in Net::LDAP, and thus I have defined myself.
109
110 new =item connect
111 No arguments are passed to indicate that an existing connection has
112 been closed.
113
114 The first argument is a boolean indicator of whether a connection has
115 succeeded or failed. The second argument contains the host spec used
116 to attempt the connection.
117
118 In the case of a success the third and fourth arguments contain the
119 address and port connected to respectively.
120
121 In the case of a failure the third argument contains the name of the
122 operation that failed, and the fourth and fifth arguments hold
123 numeric and string values of $! respectively.
124
125 search
126 The first argument is always the Net::LDAP::Search object presiding
127 over this search run. The 'done' method on this object may be
128 consulted to know when all the possible replies have been received.
129
130 The second and following arguments are Net::LDAP::Entry objects
131 returned from the search.
132
133 others
134 Forthcoming
135
137 Failures of many kinds are not very well handled at this time, also
138 canceling running connection requests is not implemented.
139
141 Jonathan Steinert hachi@cpan.org
142
144 Copyright 2004 Jonathan Steinert (hachi@cpan.org)
145
146 This program is free software; you can redistribute it and/or modify it
147 under the same terms as Perl itself.
148
149
150
151perl v5.12.0 2006-01-17 POE::Component::Client::LDAP(3)