Factory/Net/LDAPapi.pm untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 81 CC 5 SCAR 18.4
CC
5
Cov
0%
new
12.0
info
12.0
bind
2.0
CRAP 6.3
1 # Original ResourcePool::Factory::Net::LDAP:
2 #*********************************************************************
3 #*** ResourcePool::Resource::Net::LDAP
4 #*** Copyright (c) 2002,2003 by Markus Winand <mws@fatalmind.com>
5 #*********************************************************************
6  
7 =head1 NAME
8  
9 ResourcePool::Factory::Net::LDAPapi - A L<Net::LDAPapi|Net::LDAPapi> Factory for L<ResourcePool|ResourcePool>
10  
11 =head1 SYNOPSIS
12  
13 use ResourcePool::Factory::Net::LDAPapi;
14
15 my $factory = ResourcePool::Factory::Net::LDAPapi->new([NewOptions]);
16  
17 =head1 DESCRIPTION
18  
19 This class is a factory class for L<Net::LDAPapi|Net::LDAPapi> resources to be used with the L<ResourcePool|ResourcePool>.
20  
21 Please have a look at the L<ResourcePool::Factory|ResourcePool::Factory> documentation to learn about the purpose of such a factory.
22  
23 =head1 API
24  
25 =over 4
26  
27 =cut
28  
29 package ResourcePool::Factory::Net::LDAPapi;
30  
31 use strict;
32 use vars qw($VERSION @ISA);
33  
34 use ResourcePool::Factory;
35 use ResourcePool::Resource::Net::LDAPapi;
36 use Data::Dumper;
37  
38 push @ISA, "ResourcePool::Factory";
39 $VERSION = "1.00";
40  
41 =item S<ResourcePool::Factory::Net::LDAPapi-E<gt>new($hostname)>
42  
43 =item S<ResourcePool::Factory::Net::LDAPapi-E<gt>new($hostname, $port)>
44  
45 =item S<ResourcePool::Factory::Net::LDAPapi-E<gt>new(-host =E<gt> $hostname, -port =E<gt> $port)>
46  
47 =item S<ResourcePool::Factory::Net::LDAPapi-E<gt>new(-url =E<gt> $url)>
48  
49 All parameters passed to C<new()> are passed to C<Net::LDAPapi-E<gt>new()>. See L<Net::LDAPapi|Net::LDAPapi> for full list.
50  
51 =cut
52  
53 ####
54 # Some notes about the singleton behavior of this class.
55 # 1. the constructor does not return a singleton reference!
56 # 2. there is a seperate function called singelton() which will return a
57 # singleton reference
58 # this change was introduces with ResourcePool 0.9909 to allow more flexible
59 # factories (e.g. factories which do not require all parameters to their
60 # constructor) an example of such an factory is the Net::LDAP factory.
61  
62 sub new($@) {
63 my ($proto) = shift;
64 my $class = ref($proto) || $proto;
65 my $self = $class->SUPER::new();
66
67 if (! exists($self->{host})) {
68 if (defined $_[0] && ref($_[0]) ne "ARRAY") {
69 $self->{BindOptions} = [];
70 $self->{NewOptions} = [@_];
71 }
72 }
73
74 bless($self, $class);
75  
76 return $self->bind($self->{BindOptions});
77 }
78  
79 =item S<$factory-E<gt>bind("dn", "password")>
80  
81 =item S<$factory-E<gt>bind(-dn =E<gt> "dn", -password =E<gt> "password")>
82  
83 All parameters passed to C<bind()> are passed to C<Net::LDAPapi-E<gt>bind_s()>. See L<Net::LDAPapi|Net::LDAPapi> for full list.
84  
85 Please note that this module will always do a bind to the LDAP server, if you do not specify any bind arguments the bind will be anonymously. The C<bind()> call is used to check the vitality of the LDAP connection, if it fails L<ResourcePool|ResourcePool> will throw it away..
86  
87 =cut
88  
89 sub bind($@) {
90 my $self = shift;
91 $self->{BindOptions} = [@_];
92 return $self;
93 }
94  
95 sub mk_singleton_key($) {
96 my $d = Data::Dumper->new([$_[0]]);
97 $d->Indent(0);
98 $d->Terse(1);
99 return $d->Dump();
100 }
101  
102  
103 sub create_resource($) {
104 my ($self) = @_;
105 return ResourcePool::Resource::Net::LDAPapi->new($self
106 , $self->{BindOptions}
107 , $self->{NewOptions}
108 );
109 }
110  
111 sub info($) {
112 my ($self) = @_;
113 my $dn;
114  
115 if (scalar(@{$self->{BindOptions}}) % 2 == 0) {
116 # even numer -> old Net::LDAP->bind syntax
117 my %h = @{$self->{BindOptions}};
118 $dn = $h{dn};
119 } else {
120 # odd numer -> new Net::LDAP->bind syntax
121 $dn = $self->{BindOptions}->[0];
122 }
123 # if dn is still undef -> anonymous bind
124 eturn (defined $dn? $dn . "@" : "" ) . $self->{host};
125 }
126  
127 =back
128  
129 =head1 EXAMPLES
130
131 use ResourcePool;
132 use ResourcePool::Factory::Net::LDAPapi;
133
134 my $factory = ResourcePool::Factory::Net::LDAPapi->new(-host => "ldaphost");
135 $factory->bind(-dn => 'cn=admin,dc=example,dc=com', -password => 'secret');
136  
137 =head1 SEE ALSO
138  
139 L<Net::LDAPapi|Net::LDAPapi>,
140 L<ResourcePool|ResourcePool>,
141 L<ResourcePool::Factory|ResourcePool::Factory>,
142 L<ResourcePool::Resource::Net::LDAPapi|ResourcePool::Resource::Net::LDAPapi>
143  
144 =head1 AUTHOR
145  
146 =head2 ResourcePool::Factory::Net::LDAPapi
147  
148 Copyright (C) 2015 by Phillip O'Donnell <podonnell@cpan.org>
149  
150 This program is free software; you can redistribute it and/or
151 modify it under the same terms as Perl itself.
152  
153 =head2 Portions based on L<ResourcePool::Factory::Net::LDAP|ResourcePool::Factory::Net::LDAP>
154  
155 Copyright (C) 2001-2003 by Markus Winand <mws@fatalmind.com>
156  
157 This program is free software; you can redistribute it and/or
158 modify it under the same terms as Perl itself.
159  
160 =cut
161  
162 1;