Resource/Net/LDAPapi.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Factory/Net/LDAPapi.pm ↑ Summary
1 # Original ResourcePool::Resource::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::Resource::Net::LDAPapi - A L<ResourcePool|ResourcePool> wrapper for L<Net::LDAPapi|Net::LDAPapi>
10  
11 =head1 SYNOPSIS
12
13 use ResourcePool::Resource::Net::LDAPapi;
14
15 my $resource = ResourcePool::Resource::Net::LDAPapi->new(
16 $factory,
17 [@NamedBindOptions],
18 [@NamedNewOptions]);
19  
20 =head1 DESCRIPTION
21  
22 This class is used by the L<ResourcePool|ResourcePool> internally to create L<Net::LDAPapi|Net::LDAPapi> connections. It's called by the corresponding L<ResourcePool::Factory::Net::LDAPapi|ResourcePool::Factory::Net::LDAPapi> object which passes the parameters needed to establish the L<Net::LDAPapi|Net::LDAPapi> connection.
23  
24 The only thing which has to been known by an application developer about this class is the implementation of the L<precheck()|/precheck> and L<postcheck()|/postcheck> methods:
25  
26 =head1 API
27  
28 =over 4
29  
30 =cut
31  
32 package ResourcePool::Resource::Net::LDAPapi;
33  
34 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 0 ▶use Net::LDAPapi qw(LDAP_SUCCESS);
Subroutine BEGIN: called CC=1 SCAR=2.6
37 use ResourcePool::Resource;
38  
39 $VERSION = "1.00";
40 push @ISA, "ResourcePool::Resource";
41  
42 sub new($$$@) {
43 my $proto = shift;
44 my $class = ref($proto) || $proto;
45 my $self = $class->SUPER::new();
46  
47 $self->{Factory} = shift;
48 $self->{BindOptions} = defined $_[0] ? shift: [];
49 my $NewOptions = defined $_[0] ? shift: [];
50  
51 $self->{ldaph} = Net::LDAPapi->new(@{$NewOptions});
52 if (! defined $self->{ldaph}) {
53 swarn("ResourcePool::Resource::Net::LDAPapi: ".
54 "Connect to '%s' failed: $@\n",
55 $self->{Factory}->info());
56 return undef;
57 }
58
59 bless($self, $class);
60  
61 # bind returns $self on success
62 return $self->bind($self->{BindOptions});
63 }
64  
65 sub close($) {
66 my ($self) = @_;
67 #$self->{ldaph}->unbind();
68 }
69  
70 sub fail_close($) {
71 my ($self) = @_;
72 swarn("ResourcePool::Resource::Net::LDAPapi: ".
73 "closing failed connection to '%s'.\n",
74 $self->{Factory}->info());
75 }
76  
77 sub get_plain_resource($) {
78 my ($self) = @_;
79 return $self->{ldaph};
80 }
81  
82 sub DESTROY($) {
83 my ($self) = @_;
84 $self->close();
85 }
86  
87 =item S<$resource-E<gt>precheck>
88  
89 Performs a bind(), either anonymous or with dn and password (depends on the arguments to L<ResourcePool::Factory::Net::LDAPapi|ResourcePool::Factory::Net::LDAPapi>).
90  
91 Returns true on success and false if the bind failed (regardless of the reason)
92  
93 =cut
94  
95 sub precheck($) {
96 my ($self) = @_;
97 return $self->bind($self->{BindOptions});
98 }
99  
100 =item S<$resource-E<gt>postcheck>
101  
102 Does not implement any postcheck().
103  
104 Returns always true
105  
106 =cut
107  
108 sub bind($$) {
109 my ($self, $bindopts) = @_;
110 my @BindOptions = @{$bindopts};
111
112 if ($self->{ldaph}->bind_s(@BindOptions) != LDAP_SUCCESS) {
113 swarn("ResourcePool::Resource::Net::LDAPapi: ".
114 "Bind to '%s' failed: %s\n", $self->{Factory}->info(), $self->{ldaph}->errstring);
115 delete $self->{ldaph};
116 return undef;
117 }
118 return $self;
119 }
120  
121  
122 sub swarn($@) {
123 my $fmt = shift;
124 warn sprintf($fmt, @_);
125 }
126  
127 =back
128  
129 =head1 SEE ALSO
130  
131 L<Net::LDAPapi|Net::LDAPapi>,
132 L<ResourcePool|ResourcePool>,
133 L<ResourcePool::Resource|ResourcePool::Resource>,
134 L<ResourcePool::Factory::Net::LDAPapi|ResourcePool::Factory::Net::LDAPapi>
135  
136 =head1 AUTHOR
137  
138 =head2 ResourcePool::Resource::Net::LDAPapi
139  
140 Copyright (C) 2015 by Phillip O'Donnell <podonnell@cpan.org>
141  
142 This program is free software; you can redistribute it and/or
143 modify it under the same terms as Perl itself.
144  
145 =head2 Portions based on L<ResourcePool::Resource::Net::LDAP|ResourcePool::Resource::Net::LDAP>
146  
147 Copyright (C) 2001-2003 by Markus Winand <mws@fatalmind.com>
148  
149 This program is free software; you can redistribute it and/or
150 modify it under the same terms as Perl itself.
151  
152 =cut
153  
154
155 1;
« Factory/Net/LDAPapi.pm ↑ Summary