File Coverage

blib/lib/ResourcePool/Resource/Net/LDAP.pm
Criterion Covered Total %
statement 27 59 45.7
branch 3 14 21.4
condition 1 3 33.3
subroutine 6 13 46.1
pod 4 8 50.0
total 41 97 42.2


line stmt bran cond sub pod time code
1             #*********************************************************************
2             #*** ResourcePool::Resource::Net::LDAP
3             #*** Copyright (c) 2002,2003 by Markus Winand
4             #*** $Id: LDAP.pm,v 1.5 2003/09/25 17:34:08 mws Exp $
5             #*********************************************************************
6              
7             package ResourcePool::Resource::Net::LDAP;
8              
9 4     4   20 use vars qw($VERSION @ISA);
  4         9  
  4         204  
10 4     4   19 use strict;
  4         7  
  4         147  
11 4     4   24 use Net::LDAP qw(LDAP_SUCCESS);
  4         6  
  4         32  
12 4     4   283 use ResourcePool::Resource;
  4         9  
  4         3010  
13              
14             $VERSION = "1.0002";
15             push @ISA, "ResourcePool::Resource";
16              
17             sub new($$$@) {
18 2     2 0 6 my $proto = shift;
19 2   33     14 my $class = ref($proto) || $proto;
20 2         21 my $self = $class->SUPER::new();
21 2         40 $self->{Factory} = shift;
22 2         5 my $host = shift;
23 2 50       12 $self->{BindOptions} = defined $_[0] ? shift: [];
24 2 50       8 my $NewOptions = defined $_[0] ? shift: [];
25 2         8 $self->{start_tlsOptions} = shift;
26              
27 2         4 $self->{ldaph} = Net::LDAP->new($host, @{$NewOptions});
  2         21  
28 2 50       7453 if (! defined $self->{ldaph}) {
29 2         25 swarn("ResourcePool::Resource::Net::LDAP: ".
30             "Connect to '%s' failed: $@\n",
31             $self->{Factory}->info());
32 2         16 return undef;
33             }
34            
35 0         0 bless($self, $class);
36              
37 0 0       0 if (! defined $self->start_tls($self->{start_tlsOptions})) {
38 0         0 return undef;
39             }
40             # bind returns $self on success
41 0         0 return $self->bind($self->{BindOptions});
42             }
43              
44             sub close($) {
45 0     0 1 0 my ($self) = @_;
46             #$self->{ldaph}->unbind();
47             }
48              
49             sub fail_close($) {
50 0     0 1 0 my ($self) = @_;
51 0         0 swarn("ResourcePool::Resource::Net::LDAP: ".
52             "closing failed connection to '%s'.\n",
53             $self->{Factory}->info());
54             }
55              
56             sub get_plain_resource($) {
57 0     0 1 0 my ($self) = @_;
58 0         0 return $self->{ldaph};
59             }
60              
61             sub DESTROY($) {
62 0     0   0 my ($self) = @_;
63 0         0 $self->close();
64             }
65              
66             sub precheck($) {
67 0     0 1 0 my ($self) = @_;
68 0         0 return $self->bind($self->{BindOptions});
69             }
70              
71             sub start_tls($$) {
72 0     0 0 0 my ($self, $tlsoptions) = @_;
73 0 0       0 if (defined $tlsoptions) {
74 0         0 my $rc = $self->{ldaph}->start_tls(@{$tlsoptions});
  0         0  
75 0 0       0 if ($rc->code != LDAP_SUCCESS) {
76 0         0 swarn("ResourcePool::Resource::Net::LDAP: "
77             . "start_tls to '%s' failed: %s\n"
78             , $self->{Factory}->info()
79             , $rc->error()
80             );
81 0         0 delete $self->{ldaph};
82 0         0 return undef;
83             }
84             }
85 0         0 return $self;
86             }
87              
88              
89             sub bind($$) {
90 0     0 0 0 my ($self, $bindopts) = @_;
91 0         0 my @BindOptions = @{$bindopts};
  0         0  
92 0         0 my $rc;
93            
94 0         0 $rc = $self->{ldaph}->bind(@BindOptions);
95              
96 0 0       0 if ($rc->code != LDAP_SUCCESS) {
97 0         0 swarn("ResourcePool::Resource::Net::LDAP: ".
98             "Bind to '%s' failed: %s\n",
99             $self->{Factory}->info(),
100             $rc->error());
101 0         0 delete $self->{ldaph};
102 0         0 return undef;
103             }
104              
105 0         0 return $self;
106             }
107              
108              
109             sub swarn($@) {
110 2     2 0 4 my $fmt = shift;
111 2         33 warn sprintf($fmt, @_);
112             }
113             1;