URI/_ldap.pm

filter: Statementstmt 94.4% 85 / 90 Branchbran 80.0% 32 / 40 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 6 totaltotal 81.1% 133 / 164 CC 25 SCAR 15.6
CC
25
Cov
86%
canonical
9.6
extensions
5.0
_ldap_elem
4.0
CRAP 4.8
« URI/news.pm ↑ Summary URI/gopher.pm »
1 # Copyright (c) 1998 Graham Barr <gbarr@pobox.com>. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
4  
5 package URI::_ldap;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '5.40';
11  
12 1 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 39 ▶sub _ldap_elem {
Subroutine _ldap_elem: called CC=4 SCAR=13.9
15 39 my $self = shift;
16 39 my $elem = shift;
17 39 my $query = $self->query;
18 39 ▶ my @bits = (split(/\?/, defined($query) ? $query : ""), ("") x 4);
Branch: 1 branch
BranchTrueFalseTotal
defined $query ? : 31 8 39
19 39 my $old = $bits[$elem];
20  
21 39 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 17 22 39
22 17 my $new = shift;
23 17 $new =~ s/\?/%3F/g;
24 17 $bits[$elem] = $new;
25 17 $query = join("?", @bits);
26 17 $query =~ s/\?+$//;
27 17 ▶ $query = undef unless length($query);
Branch: 1 branch
BranchTrueFalseTotal
unless length $query 3 14 17
28 17 $self->query($query);
29 }
30  
31 39 $old;
32 }
33  
34 8 ▶sub dn {
Subroutine dn: called CC=1 SCAR=0.0
Pod undocumented
35 8 my $old = shift->path(@_);
36 8 $old =~ s:^/::;
37 8 uri_unescape($old);
38 }
39  
40 11 ▶sub attributes {
Subroutine attributes: called CC=3 SCAR=11.0
Pod undocumented
41 11 my $self = shift;
42 my $old = _ldap_elem($self, 0,
43 11 ▶ @_ ? join(",", map { my $tmp = $_; $tmp =~ s/,/%2C/g; $tmp } @_) : ());
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 5 6 11
44 11 ▶ return $old unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 6 5 11
45 5 map { uri_unescape($_) } split(/,/, $old);
46 }
47  
48 10 ▶sub _scope {
Subroutine _scope: called CC=3 SCAR=12.0
49 10 my $self = shift;
50 10 my $old = _ldap_elem($self, 1, @_);
51 10 ▶ return undef unless defined wantarray && defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray and defined $old 0 10 10
Condition33%1/3
defined wantarray and defined $old
!ll&&!rl&&r
0010
MC/DC0%0/2
defined wantarray and defined $old
defined wantarray defined $old
Truth table33%1/3
A and B
A= defined wantarrayB= defined $old
ABresult
0X0
100
111
52 10 uri_unescape($old);
53 }
54  
55 9 ▶sub scope {
Subroutine scope: called CC=2 SCAR=6.9
Pod undocumented
56 9 my $old = &_scope;
57 9 ▶ $old = "base" unless length $old;
Branch: 1 branch
BranchTrueFalseTotal
unless length $old 2 7 9
58 9 $old;
59 }
60  
61 11 ▶sub _filter {
Subroutine _filter: called CC=3 SCAR=12.0
62 11 my $self = shift;
63 11 my $old = _ldap_elem($self, 2, @_);
64 11 ▶ return undef unless defined wantarray && defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray and defined $old 0 11 11
Condition33%1/3
defined wantarray and defined $old
!ll&&!rl&&r
0011
MC/DC0%0/2
defined wantarray and defined $old
defined wantarray defined $old
Truth table33%1/3
A and B
A= defined wantarrayB= defined $old
ABresult
0X0
100
111
65 11 uri_unescape($old); # || "(objectClass=*)";
66 }
67  
68 10 ▶sub filter {
Subroutine filter: called CC=2 SCAR=6.9
Pod undocumented
69 10 my $old = &_filter;
70 10 ▶ $old = "(objectClass=*)" unless length $old;
Branch: 1 branch
BranchTrueFalseTotal
unless length $old 2 8 10
71 10 $old;
72 }
73  
74 7 ▶sub extensions {
Subroutine extensions: called CC=5 SCAR=16.1
Pod undocumented
75 7 my $self = shift;
76 7 my @ext;
77 7 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 7 12
78 5 my $key = shift;
79 5 my $value = shift;
80 push(
81 @ext,
82 join("=",
83 5 ▶ map { $_ = "" unless defined; s/,/%2C/g; $_ } $key, $value)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 10 10
84 );
85 }
86 7 ▶ @ext = join(",", @ext) if @ext;
Branch: 1 branch
BranchTrueFalseTotal
if @ext 3 4 7
87 7 my $old = _ldap_elem($self, 3, @ext);
88 7 ▶ return $old unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 3 4 7
89 4 map { uri_unescape($_) } map {/^([^=]+)=(.*)$/} split(/,/, $old);
90 }
91  
92 2 ▶sub canonical {
Subroutine canonical: called CC=9 SCAR=22.7
Pod undocumented
93 2 my $self = shift;
94 2 my $other = $self->_nonldap_canonical;
95  
96 # The stuff below is not as efficient as one might hope...
97  
98 2 ▶ $other = $other->clone if $other == $self;
Branch: 1 branch
BranchTrueFalseTotal
if $other == $self 0 2 2
99  
100 2 $other->dn(_normalize_dn($other->dn));
101  
102 # Should really know about mixed case "postalAddress", etc...
103 2 $other->attributes(map lc, $other->attributes);
104  
105 # Lowercase scope, remove default
106 2 my $old_scope = $other->scope;
107 2 my $new_scope = lc($old_scope);
108 2 ▶ $new_scope = "" if $new_scope eq "base";
Branch: 1 branch
BranchTrueFalseTotal
if $new_scope eq "base" 2 0 2
109 2 ▶ $other->scope($new_scope) if $new_scope ne $old_scope;
Branch: 1 branch
BranchTrueFalseTotal
if $new_scope ne $old_scope 2 0 2
110  
111 # Remove filter if default
112 2 my $old_filter = $other->filter;
113 2 ▶ $other->filter("")
Branch: 1 branch
BranchTrueFalseTotal
if lc $old_filter eq "(objectclass=*)" or lc $old_filter eq "objectclass=*" 2 0 2
Condition33%1/3
lc $old_filter eq "(objectclass=*)" or lc $old_filter eq "objectclass=*"
l!l&&r!l&&!r
020
MC/DC0%0/2
lc $old_filter eq "(objectclass=*)" or lc $old_filter eq "objectclass=*"
lc $old_filter eq "(objectclass=*)" lc $old_filter eq "objectclass=*"
Truth table33%1/3
A or B
A= lc $old_filter eq "(objectclass=*)"B= lc $old_filter eq "objectclass=*"
ABresult
1X1
011
000
114 if lc($old_filter) eq "(objectclass=*)"
115 || lc($old_filter) eq "objectclass=*";
116  
117 # Lowercase extensions types and deal with known extension values
118 2 my @ext = $other->extensions;
119 2 ▶ for (my $i = 0; $i < @ext; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @ext) 4 2 6
120 4 my $etype = $ext[$i] = lc($ext[$i]);
121 4 ▶ if ($etype =~ /^!?bindname$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($etype =~ /^!?bindname$/) 2 2 4
122 2 $ext[$i + 1] = _normalize_dn($ext[$i + 1]);
123 }
124 }
125 2 ▶ $other->extensions(@ext) if @ext;
Branch: 1 branch
BranchTrueFalseTotal
if @ext 2 0 2
126  
127 2 $other;
128 }
129  
130 sub _normalize_dn # RFC 2253
131 4 ▶{
Subroutine _normalize_dn: called CC=2 SCAR=12.4
132 4 my $dn = shift;
133  
134 4 return $dn;
135  
136 # The code below will fail if the "+" or "," is embedding in a quoted
137 # string or simply escaped...
138  
139 0 my @dn = split(/([+,])/, $dn);
140 0 for (@dn) {
141 0 s/^([a-zA-Z]+=)/lc($1)/e;
142 }
143 0 join("", @dn);
144 }
145  
146 1 1;
« URI/news.pm ↑ Summary URI/gopher.pm »