Model/LDAP/Connection.pm

filter: Statementstmt 45.2% 38 / 84 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 80.0% 12 / 15 Podpod 100% 3 / 3 totaltotal 34.8% 53 / 152 CC 22 SCAR 45.1
CC
22
Cov
30%
search
210.0
bind
42.0
new
20.0
CRAP 91.2
↑ Summary Helper/Model/LDAP.pm »
1 package Catalyst::Model::LDAP::Connection;
2 # ABSTRACT: Convenience methods for Net::LDAP
3  
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use base qw/Net::LDAP Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Catalyst::Model::LDAP::Search;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Data::Page;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Net::LDAP::Constant qw/LDAP_CONTROL_VLVRESPONSE/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Net::LDAP::Control::Sort;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Net::LDAP::Control::VLV;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Net::LDAP::Control::ProxyAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 __PACKAGE__->mk_accessors(qw/base options entry_class/);
18  
19  
20 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
21 0 my ( $class, %args ) = @_;
22  
23 0 my $base = delete $args{base};
24 my %options =
25 0 ▶ %{ ref $args{options} eq 'HASH' ? delete $args{options} : {} };
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'options'} eq 'HASH' ? : 0 0 0
26 my $entry_class = delete $args{entry_class}
27 0 ▶ || 'Catalyst::Model::LDAP::Entry';
Condition0%0/2
delete $args{'entry_class'} || 'Catalyst::Model::LDAP::Entry'
l!l
00
MC/DC0%0/1
delete $args{'entry_class'} || 'Catalyst::Model::LDAP::Entry'
delete $args{'entry_class'}
Truth table0%0/2
A
A= delete $args{'entry_class'}
Aresult
11
00
28  
29 0 my $host = delete $args{host};
30 0 my $self = $class->next::method( $host, %args );
31 0 ▶ croak "Error connecting to $host: $@" unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
32  
33 0 $self->base($base);
34 0 $self->options( \%options );
35 0 $self->entry_class($entry_class);
36  
37 0 return $self;
38 }
39  
40  
41 0 ▶sub bind {
Subroutine bind: not called CC=6 SCAR=37.4
Pod documented
42 0 my ( $self, %args ) = @_;
43  
44 0 delete $args{$_} for qw/host base options connection_class entry_class/;
45  
46 # Bind using TLS if configured
47 0 ▶ if ( delete $args{start_tls} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (delete $args{"start_tls"}) 0 0 0
48 my $mesg =
49 0 ▶ $self->start_tls( %{ delete $args{start_tls_options} || {} }, );
Condition0%0/2
delete $args{'start_tls_options'} || {}
l!l
00
MC/DC0%0/1
delete $args{'start_tls_options'} || {}
delete $args{'start_tls_options'}
Truth table0%0/2
A
A= delete $args{'start_tls_options'}
Aresult
11
00
50 0 ▶ croak 'LDAP TLS error: ' . $mesg->error if $mesg->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $mesg->is_error 0 0 0
51 }
52  
53 # Bind via DN if configured
54 0 my $dn = delete $args{dn};
55  
56 0 ▶ $self->next::method( $dn ? ( $dn, %args ) : %args );
Branch: 1 branch
BranchTrueFalseTotal
$dn ? : 0 0 0
57 }
58  
59  
60 0 ▶sub search {
Subroutine search: not called CC=14 SCAR=53.5
Pod documented
61 0 my $self = shift;
62 0 ▶ my %args = scalar @_ == 1 ? ( filter => shift ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 ? : 0 0 0
63  
64 croak "Cannot use 'page' without 'order_by'"
65 0 ▶ if $args{page} and not $args{order_by};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"page"} and not $args{"order_by"} 0 0 0
Condition0%0/3
$args{"page"} and not $args{"order_by"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"page"} and not $args{"order_by"}
$args{"page"} not $args{"order_by"}
Truth table0%0/3
A and not(B)
A= $args{"page"}B= not $args{"order_by"}
ABresult
0X0
100
111
66  
67 # Use default base
68 %args = (
69 base => $self->base,
70 0 ▶ %{ $self->options || {} },
Condition0%0/2
$self->options || {}
l!l
00
MC/DC0%0/1
$self->options || {}
$self->options
Truth table0%0/2
A
A= $self->options
Aresult
11
00
71 %args,
72 );
73  
74 # Allow ProxyAuth by itself
75 0 ▶ if ( my $authz = delete $args{authz} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $authz = delete $args{"authz"}) 0 0 0
76 0 my $authz =
77 Net::LDAP::Control::ProxyAuth->new( authzID => q{dn:} . $authz );
78 0 ▶ $args{control} = [ @{ $args{control} || [] }, $authz ];
Condition0%0/2
$args{'control'} || []
l!l
00
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
Aresult
11
00
79 }
80  
81 # Handle server-side sorting
82 0 ▶ if ( my $order_by = delete $args{order_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $order_by = delete $args{"order_by"}) 0 0 0
83 0 my $sort = Net::LDAP::Control::Sort->new( order => $order_by );
84  
85 0 ▶ $args{control} = [ @{ $args{control} || [] }, $sort ];
Condition0%0/2
$args{'control'} || []
l!l
00
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
Aresult
11
00
86 }
87  
88 0 my ( $mesg, $pager );
89 0 ▶ if ( my $page = delete $args{page} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $page = delete $args{'page'}) { } 0 0 0
90 0 ▶ my $rows = delete $args{rows} || 25;
Condition0%0/2
delete $args{'rows'} || 25
l!l
00
MC/DC0%0/1
delete $args{'rows'} || 25
delete $args{'rows'}
Truth table0%0/2
A
A= delete $args{'rows'}
Aresult
11
00
91  
92 0 my $vlv = Net::LDAP::Control::VLV->new(
93 before => 0,
94 after => $rows - 1,
95 content => 0,
96 offset => ( $rows * $page ) - $rows + 1,
97 );
98  
99 0 ▶ $args{control} = [ @{ $args{control} || [] }, $vlv ];
Condition0%0/2
$args{'control'} || []
l!l
00
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
Aresult
11
00
100  
101 0 $mesg = $self->next::method(%args);
102 0 ▶ my @resp = $mesg->control(LDAP_CONTROL_VLVRESPONSE)
Branch: 1 branch
BranchTrueFalseTotal
my(@resp) = $mesg->control("2.16.840.1.113730.3.4.10") or croak('Could not get pager from LDAP response: ' . $mesg->server_error) 0 0 0
103 or croak 'Could not get pager from LDAP response: '
104 . $mesg->server_error;
105 0 $pager = Data::Page->new( $resp[0]->content, $rows, $page );
106 }
107 else {
108 0 $mesg = $self->next::method(%args);
109 }
110  
111 0 bless $mesg, 'Catalyst::Model::LDAP::Search';
112 0 $mesg->init( $self->entry_class );
113  
114 0 ▶ return ( $pager ? ( $mesg, $pager ) : $mesg );
Branch: 1 branch
BranchTrueFalseTotal
$pager ? : 0 0 0
115 }
116  
117  
118 5 1;
119  
120 __END__
↑ Summary Helper/Model/LDAP.pm »