blib/lib/Net/LDAP/FilterBuilder.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 66.6% 4 / 6 totaltotal 92.0% 81 / 88 SCAR 23.0
CC
10
Cov
96%
new
9.0
escape
2.0
BEGIN
1.0
CRAP 10.0
↑ Summary
1 package Net::LDAP::FilterBuilder;
2 BEGIN {
3 3 ▶ $Net::LDAP::FilterBuilder::VERSION = '1.200000';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 }
5  
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use overload '""' => \&as_str;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub escape {
12 24 ▶ my $class = shift;
Subroutine escape: called CC=2 SCAR=6.9
Pod undocumented
13 24 my $value = shift;
14 24 for ( $value ) {
15 24 s{\\}{\\}g;
16 24 s{\*}{\\*}g;
17 24 s{\(}{\\(}g;
18 24 s{\)}{\\)}g;
19 24 s{\0}{\\0}g;
20 }
21 24 return $value;
22 }
23  
24 sub new {
25 31 ▶ my $proto = shift;
Subroutine new: called CC=9 SCAR=22.0
Pod undocumented
26 31 ▶ my $class = ref( $proto ) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
8230
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
27  
28 31 my $filter;
29  
30 31 ▶ if ( @_ == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 0 31 31
elsif (@_ == 1) { } 2 29 31
31 0 $filter = '(objectclass=*)';
32 }
33 elsif ( @_ == 1 ) {
34 2 $filter = shift;
35 }
36 else {
37 29 ▶ my $op = @_ % 2 ? shift : '=';
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 10 19 29
38 29 my @parts;
39 29 ▶ while ( my ( $attr, $val ) = splice( @_, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 30 29 59
40 30 ▶ if ( ref( $val ) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 4 26 30
elsif (ref $val eq 'SCALAR') { } 2 24 26
41 4 push @parts, sprintf( '(|%s)', join( q{}, map $class->new( $op, $attr, $_ ), @{ $val } ) );
42 }
43 elsif ( ref( $val ) eq 'SCALAR' ) {
44 2 push @parts, sprintf( '(%s%s%s)', $attr, $op, ${ $val } );
45 }
46 else {
47 24 push @parts, sprintf( '(%s%s%s)', $attr, $op, $class->escape( $val ) );
48 }
49 }
50 29 ▶ if ( @parts > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 1) { } 1 28 29
51 1 $filter = sprintf( '(&%s)', join( q{}, @parts ) );
52 }
53 else {
54 28 $filter = shift @parts;
55 }
56 }
57  
58 31 bless( \$filter, $class );
59 }
60  
61 sub or {
62 3 ▶ my $self = shift;
Subroutine or: called CC=1 SCAR=0.0
Pod documented
63  
64 3 ${ $self } = sprintf( '(|%s%s)', $self, $self->new( @_ ) );
65  
66 3 return $self;
67 }
68  
69 sub and {
70 5 ▶ my $self = shift;
Subroutine and: called CC=1 SCAR=0.0
Pod documented
71  
72 5 ${ $self } = sprintf( '(&%s%s)', $self, $self->new( @_ ) );
73  
74 5 return $self;
75 }
76  
77 sub not {
78 2 ▶ my $self = shift;
Subroutine not: called CC=1 SCAR=0.0
Pod documented
79  
80 2 ${ $self } = sprintf( '(!%s)', $self );
81  
82 2 return $self;
83 }
84  
85 sub as_str {
86 41 ▶ ${ $_[0] };
Subroutine as_str: called CC=1 SCAR=0.0
Pod documented
87 }
88  
89 3 1;
90  
91 # ABSTRACT: Build LDAP filter statements
92  
93  
94 __END__
↑ Summary