blib/lib/Net/DSML/Filter.pm

filter: Statementstmt 66.8% 153 / 229 Branchbran 47.6% 62 / 130 Conditioncond 33.3% 7 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 64.2% 18 / 28 Podpod 100% 19 / 19 totaltotal 58.8% 259 / 440 CC 73 SCAR 29.0
CC
73
Cov
58%
extensibleMatch
31.7
subString
28.5
equalityMatch
23.1
CRAP 18.1
« blib/lib/Net/DSML/Control.pm ↑ Summary test.cfg »
1 package Net::DSML::Filter;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use Carp;
6 3 ▶use Class::Std::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use version; $VERSION = version->new('0.002');
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Copyright (c) 2007 Clif Harden <charden@pobox.com>. All rights reserved.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
14  
15 {
16  
17 BEGIN
18 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 @ISA = qw(Exporter);
22 3 @EXPORT = qw();
23 3 %EXPORT_TAGS = ();
24 3 @EXPORT_OK = ();
25  
26 }
27  
28  
29 #
30 # The class filter provides methods for building ldap dsml search filters.
31 #
32 3 my %sfilter;
33 my %debug;
34 3 my %errMsg;
35 3 my %msg;
36  
37 #
38 # initialize the new object.
39 #
40 # Method new
41 #
42 # The new method initializes a new filter object.
43 #
44 # This method has 1 valid option; debug; value of 1 or 0. This will enable
45 # debug messages to standard out.
46 #
47  
48 sub new
49 35 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod documented
50 35 my ($class, $opt) = @_;
51 35 my $self = bless anon_scalar(), $class;
52  
53 35 $sfilter{ident $self} = ""; # Search filter
54 35 ▶ $debug{ident $self} = $opt->{debug} ? 1 : 0; # debug flag
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'debug'} ? : 0 35 35
55 35 $errMsg{ident $self} = ""; # error messages, no error this will be a null string.
56 35 $msg{ident $self} = ""; # general messages
57 35 return $self;
58 }
59  
60 #
61 # inside-out classes have to have a DESTROY subrountine.
62 #
63 sub DESTROY
64 35 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
65 35 my ($dsml) = @_;
66 35 my $id = ident($dsml);
67  
68 35 delete $sfilter{$id};
69 35 delete $debug{$id};
70 35 delete $errMsg{$id};
71 35 delete $msg{$id};
72 35 return;
73 }
74  
75 # Method debug
76 #
77 # The method debug sets or returns the object debug flag.
78 #
79 # If there is one required input option.
80 #
81 # $return = $dsml->debug( 1 );
82 #
83 # Input option: Debug value; 1 or 0. Default is 0.
84 #
85 # Method output; Returns debug value.
86 #
87  
88 sub debug
89 0 ▶{
Subroutine debug: not called CC=2 SCAR=17.9
Pod documented
90 0 my $dsml = shift;
91 0 ▶ $debug{ident $dsml} = shift if ( @_ >= 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ >= 1 0 0 0
92 0 return $debug{ident $dsml};
93 }
94  
95  
96 # Method error
97 #
98 # The error method returns error message that is stored in the
99 # object. Any error message will be associated with the last
100 # filter module operation.
101 #
102 # No input options.
103 #
104 # Example: $filter->error;
105 #
106  
107 sub error
108 0 ▶{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
109 0 my ($dsml) = @_;
110 0 return $errMsg{ident $dsml};
111 }
112  
113  
114 # Method getFilter
115 #
116 # The getFilter method returns the last filter string that was
117 # created.
118 #
119 # No input options.
120 #
121 # Example: $filter->getFilter;
122 #
123  
124 sub getFilter
125 33 ▶{
Subroutine getFilter: called CC=2 SCAR=7.0
Pod documented
126 33 my ($dsml) = @_;
127 33 my $id;
128 33 $id = ident $dsml;
129  
130 33 ▶ if ( !($sfilter{$id} =~ /<filter>/) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($sfilter{$id} =~ /<filter>/) 33 0 33
131 {
132 33 $sfilter{$id} = "<filter>" . $sfilter{$id} . "</filter>";
133 }
134 33 return $sfilter{$id};
135 }
136  
137  
138 # 1. & - &amp;
139 # 2. < - &lt;
140 # 3. > - &gt;
141 # 4. " - &quot;
142 # 5. ' - &#39;
143 #
144 # Convert special characters to xml standards.
145 #
146 sub _specialChar
147 39 ▶{
Subroutine _specialChar: called CC=1 SCAR=0.0
148 39 my ($char) = @_;
149  
150 39 $$char =~ s/&/&amp;/g;
151 39 $$char =~ s/</&lt;/g;
152 39 $$char =~ s/>/&gt;/g;
153 39 $$char =~ s/"/&quot;/g;
154 39 $$char =~ s/'/&#39;/g;
155  
156 }
157  
158 # Method setFilter
159 #
160 # The setFilter method sets the objects filter string. This
161 # could be used as a base to continue building the filter string.
162 #
163 # Example: $filter->setFilter($value);
164 #
165 # There is 1 input option ($value): filter string.
166 #
167  
168 sub setFilter
169 0 ▶{
Subroutine setFilter: not called CC=4 SCAR=30.0
Pod documented
170 0 my ($dsml, $value) = @_;
171 0 my $refvalue;
172 0 ▶ $refvalue = (ref($value) ? ${$value} : $value);
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 0 0 0
173 0 ▶ if ( length($refvalue) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $refvalue > 0) 0 0 0
174 {
175 0 ▶ _specialChar(\$refvalue) if ( $refvalue =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $refvalue =~ /(&||<||>||"||')/ 0 0 0
176 0 $sfilter{ident $dsml} = $refvalue;
177 0 return 1;
178 }
179
180 0 $errMsg{ident $dsml} = "Method setFilter filter value is not defined.";
181 0 return 0;
182  
183 }
184  
185  
186 # Method reset
187 #
188 # The reset method will reset the filter string to a null, or blank,
189 # value.
190 #
191 # No input options.
192 #
193 # Example: $filter->reset;
194 #
195  
196 sub reset
197 0 ▶{
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
198 0 my ($dsml) = @_;
199 0 $sfilter{ident $dsml} = "";
200 0 return 1;
201 }
202  
203 # Method subString
204 #
205 # The method subString sets up a LDAP substring filter.
206 #
207 # There are 3 required input options.
208 #
209 # $return = $filter->subString( type => "initial,
210 # attribute => "cn",
211 # value => "Bugs Bunny" );
212 #
213 # Input option "type": String that contains the type of substring
214 # search that is being preformed; final, any, initial.
215 #
216 # Input option "attribute": String that contains the attribute name
217 # that controls the search.
218 #
219 # Input option "value": String that contains the value of the
220 # attribute.
221 #
222 # Method output; Returns true on success; false on error, error message
223 # can be gotten with error property.
224 #
225  
226 sub subString
227 18 ▶{
Subroutine subString: called CC=13 SCAR=33.5
Pod documented
228 18 my ($dsml, $opt) = @_;
229 18 my $id = ident($dsml);
230 18 my $attribute;
231 my $value;
232 18 my $type;
233 18 $errMsg{$id} = "";
234  
235 18 ▶ $attribute = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 2 16 18
236 18 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 1 17 18
237 18 ▶ $type = (ref($opt->{type}) ? ${$opt->{type}} : $opt->{type});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'type'} ? : 2 16 18
238  
239 18 ▶ if ( defined($opt->{attribute}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{'attribute'} and defined $opt->{'value'} and defined $opt->{'type'}) { } 18 0 18
Condition33%2/6
defined $opt->{"attribute"} and defined $opt->{"value"} and defined $opt->{"type"}
!ll&&!rl&&r
0018
defined $opt->{"attribute"} and defined $opt->{"value"}
!ll&&!rl&&r
0018
MC/DC0%0/3
defined $opt->{"attribute"} and defined $opt->{"value"} and defined $opt->{"type"}
defined $opt->{"attribute"} defined $opt->{"value"} defined $opt->{"type"}
Truth table25%1/4
A and B and C
A= defined $opt->{"attribute"}B= defined $opt->{"value"}C= defined $opt->{"type"}
ABCresult
0XX0
10X0
1100
1111
240 defined($opt->{value}) &&
241 defined($opt->{type}) )
242 {
243 18 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 18 0 18
244 18 $_ = lc($type);
245 18 ▶ if ( /^(final||initial||any)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (/^(final||initial||any)$/) 18 0 18
246 {
247 18 $sfilter{$id} .= "<substrings name=\"" . $attribute . "\"><" . $1 . ">" . $value . "</" . $1 . "></substrings>";
248 18 return 1;
249 }
250  
251 0 $errMsg{$id} = "Requested substring type does not match final, any or initial.";
252 0 return 0;
253  
254 }
255 else
256 {
257 #
258 # Substring error conditions
259 #
260 0 ▶ if ( (@_) < 6 )
Branch: 4 branches
BranchTrueFalseTotal
if (@_ < 6) { } 0 0 0
elsif (CORE::not defined $opt->{'attribute'}) { } 0 0 0
elsif (CORE::not defined $opt->{'value'}) { } 0 0 0
elsif (CORE::not defined $opt->{'type'}) { } 0 0 0
261 {
262 0 $errMsg{$id} = "Subroutine subString did not have enough parameters defined.";
263 }
264 elsif ( !defined($opt->{attribute}) )
265 {
266 0 $errMsg{$id} = "Subroutine subString attribute string is not defined.";
267 }
268 elsif ( !defined($opt->{value}) )
269 {
270 0 $errMsg{$id} = "Subroutine subString value string is not defined.";
271 }
272 elsif ( !defined($opt->{type}) )
273 {
274 0 $errMsg{$id} = "Subroutine subString type string is not defined.";
275 }
276 0 return 0;
277 }
278  
279 }
280  
281  
282 # Method present
283 #
284 # The method present sets up a LDAP present filter.
285 #
286 # There is 1 required input option.
287 #
288 # $return = $filter->present( { attribute => "cn" } );
289 #
290 # Input option "attribute": String that contains the attribute name
291 # that controls the search.
292 #
293 # Method output; Returns true on success; false on error, error message
294 # can be gotten with error property.
295 #
296  
297 sub present
298 4 ▶{
Subroutine present: called CC=3 SCAR=11.2
Pod documented
299 4 my ($dsml, $opt) = @_;
300 4 my $id = ident($dsml);
301 4 my $refvalue;
302  
303 4 $errMsg{$id} = "";
304 4 ▶ $refvalue = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 1 3 4
305 4 ▶ if ( !defined($opt->{attribute}) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opt->{"attribute"}) 0 4 4
306 {
307 0 $errMsg{$id} = "Subroutine present attribute string is not defined.";
308 0 return 0;
309 }
310 4 $sfilter{$id} .= "<present name=\"" . $refvalue . "\"/>";
311 4 return 1;
312 }
313  
314  
315 # Method equalityMatch
316 #
317 # The method equalityMatch sets up a LDAP equality match filter.
318 #
319 # There are 2 required input options.
320 #
321 # $return = $filter->equalityMatch( { attribute => "sn", value => "Bunny" } );
322 #
323 # Input option "attribute": String that contains the attribute name
324 # that controls the search.
325 #
326 # Input option "value": String that contains the attribute value.
327 #
328 # Method output; Returns true on success; false on error, error message
329 # can be gotten with error property.
330 #
331  
332 sub equalityMatch
333 2 ▶{
Subroutine equalityMatch: called CC=9 SCAR=31.4
Pod documented
334 2 my ($dsml, $opt) = @_;
335 2 my $id = ident($dsml);
336 2 my $attribute;
337 my $value;
338 2 $errMsg{$id} = "";
339 0 ▶ $attribute = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 0 2 2
340 0 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 0 2 2
341  
342 2 ▶ if ( defined($opt->{attribute}) && defined($opt->{value}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{'attribute'} and defined $opt->{'value'}) { } 2 0 2
Condition33%1/3
defined $opt->{"attribute"} and defined $opt->{"value"}
!ll&&!rl&&r
002
MC/DC0%0/2
defined $opt->{"attribute"} and defined $opt->{"value"}
defined $opt->{"attribute"} defined $opt->{"value"}
Truth table33%1/3
A and B
A= defined $opt->{"attribute"}B= defined $opt->{"value"}
ABresult
0X0
100
111
343 {
344 2 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 2 0 2
345 2 $sfilter{$id} .= "<equalityMatch name=\"" . $attribute . "\"><value>" . $value . "</value></equalityMatch>";
346  
347 #print $sfilter{$id}, "\n"; # if ( $debug{$id} );
348 2 return 1;
349 }
350 else
351 {
352  
353 0 ▶ if ( (@_) < 2 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ < 2) { } 0 0 0
elsif (CORE::not defined $opt->{'attribute'}) { } 0 0 0
elsif (CORE::not defined $opt->{'value'}) { } 0 0 0
354 {
355 0 $errMsg{$id} = "Subroutine equalityMatch did not have enough parameters defined.";
356 }
357 elsif ( !defined($opt->{attribute}) )
358 {
359 0 $errMsg{$id} = "Subroutine equalityMatch attribute string is not defined.";
360 }
361 elsif ( !defined($opt->{value}) )
362 {
363 0 $errMsg{$id} = "Subroutine equalityMatch value string is not defined.";
364 }
365 0 return 0;
366 }
367 }
368  
369  
370 # Method greaterOrEqual
371 #
372 # The method greaterOrEqual sets up a LDAP greater or equal filter.
373 #
374 # There are 2 required input options.
375 #
376 # $return = $filter->greaterOrEqual( { attribute => "uid", value => "bugs" } );
377 #
378 # Input option "attribute": String that contains the attribute name
379 # that controls the search.
380 #
381 # Input option "value": String that contains the value of the
382 # attribute.
383 #
384 # Method output; Returns true on success; false on error, error message
385 # can be gotten with error property.
386 #
387  
388 sub greaterOrEqual
389 4 ▶{
Subroutine greaterOrEqual: called CC=9 SCAR=27.7
Pod documented
390 4 my ($dsml, $opt) = @_;
391 4 my $id = ident($dsml);
392 4 my $attribute;
393 my $value;
394  
395 4 $errMsg{$id} = "";
396 4 ▶ $attribute = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 1 3 4
397 4 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 1 3 4
398  
399 4 ▶ if ( defined($opt->{attribute}) && defined($opt->{value}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{'attribute'} and defined $opt->{'value'}) { } 4 0 4
Condition33%1/3
defined $opt->{"attribute"} and defined $opt->{"value"}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $opt->{"attribute"} and defined $opt->{"value"}
defined $opt->{"attribute"} defined $opt->{"value"}
Truth table33%1/3
A and B
A= defined $opt->{"attribute"}B= defined $opt->{"value"}
ABresult
0X0
100
111
400 {
401 4 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 4 0 4
402 4 $sfilter{$id} .= "<greaterOrEqual name=\"" . $attribute . "\"><value>" . $value . "</value></greaterOrEqual>";
403 4 return 1;
404 }
405 else
406 {
407 0 ▶ if ( (@_) < 4 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ < 4) { } 0 0 0
elsif (CORE::not defined $opt->{'attribute'}) { } 0 0 0
elsif (CORE::not defined $opt->{'value'}) { } 0 0 0
408 {
409 0 $errMsg{$id} = "Subroutine greaterOrEqual did not have enough parameters defined.";
410 }
411 elsif ( !defined($opt->{attribute}) )
412 {
413 0 $errMsg{$id} = "Subroutine greaterOrEqual attribute string is not defined.";
414 }
415 elsif ( !defined($opt->{value}) )
416 {
417 0 $errMsg{$id} = "Subroutine greaterOrEqual value string is not defined.";
418 }
419 0 return 0;
420 }
421 }
422  
423  
424  
425 # Method lessOrEqual
426 #
427 # The method lessOrEqual sets up a LDAP less or equal filter.
428 #
429 # There are 2 required input options.
430 #
431 # $return = $filter->lessOrEqual( { attribute => "uid", value => "turkey" } );
432 #
433 # Input option "attribute": String that contains the attribute name
434 # that controls the search.
435 #
436 # Input option "value": String that contains the value of the
437 # attribute.
438 #
439 # Method output; Returns true on success; false on error, error message
440 # can be gotten with error property.
441 #
442  
443 sub lessOrEqual
444 4 ▶{
Subroutine lessOrEqual: called CC=9 SCAR=27.7
Pod documented
445 4 my ($dsml, $opt) = @_;
446 4 my $id = ident($dsml);
447 4 my $attribute;
448 my $value;
449 4 $errMsg{$id} = "";
450  
451 4 ▶ $attribute = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 1 3 4
452 4 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 1 3 4
453  
454 4 ▶ if ( defined($opt->{attribute}) && defined($opt->{value}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{'attribute'} and defined $opt->{'value'}) { } 4 0 4
Condition33%1/3
defined $opt->{"attribute"} and defined $opt->{"value"}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $opt->{"attribute"} and defined $opt->{"value"}
defined $opt->{"attribute"} defined $opt->{"value"}
Truth table33%1/3
A and B
A= defined $opt->{"attribute"}B= defined $opt->{"value"}
ABresult
0X0
100
111
455 {
456 4 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 4 0 4
457 4 $sfilter{$id} .= "<lessOrEqual name=\"" . $attribute . "\"><value>" . $value . "</value></lessOrEqual>";
458 4 return 1;
459 }
460 else
461 {
462 0 ▶ if ( (@_) < 4 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ < 4) { } 0 0 0
elsif (CORE::not defined $opt->{'attribute'}) { } 0 0 0
elsif (CORE::not defined $opt->{'value'}) { } 0 0 0
463 {
464 0 $errMsg{$id} = "Subroutine lessOrEqual did not have enough parameters defined.";
465 }
466 elsif ( !defined($opt->{attribute}) )
467 {
468 0 $errMsg{$id} = "Subroutine lessOrEqual attribute string is not defined.";
469 }
470 elsif ( !defined($opt->{value}) )
471 {
472 0 $errMsg{$id} = "Subroutine lessOrEqual value string is not defined.";
473 }
474 0 return 0;
475 }
476 }
477  
478  
479 # Method approxMatch
480 #
481 # The method approxMatch sets up a LDAP approximate match filter.
482 #
483 # There are 2 required input options.
484 #
485 # $return = $filter->approxMatch( { attribute => "uid", value => "bird" } );
486 #
487 # Input option "attribute": String that contains the attribute name
488 # that controls the search.
489 #
490 # Input option "value": String that contains the value of the
491 # attribute.
492 #
493 # Method output; Returns true on success; false on error, error message
494 # can be gotten with error property.
495 #
496  
497 sub approxMatch
498 4 ▶{
Subroutine approxMatch: called CC=9 SCAR=27.7
Pod documented
499 4 my ($dsml, $opt) = @_;
500 4 my $id = ident($dsml);
501 4 my $attribute;
502 my $value;
503 4 $errMsg{$id} = "";
504  
505 4 ▶ $attribute = (ref($opt->{attribute}) ? ${$opt->{attribute}} : $opt->{attribute});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'attribute'} ? : 1 3 4
506 4 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 1 3 4
507  
508 4 ▶ if ( defined($opt->{attribute}) && defined($opt->{value}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{'attribute'} and defined $opt->{'value'}) { } 4 0 4
Condition33%1/3
defined $opt->{"attribute"} and defined $opt->{"value"}
!ll&&!rl&&r
004
MC/DC0%0/2
defined $opt->{"attribute"} and defined $opt->{"value"}
defined $opt->{"attribute"} defined $opt->{"value"}
Truth table33%1/3
A and B
A= defined $opt->{"attribute"}B= defined $opt->{"value"}
ABresult
0X0
100
111
509 {
510 4 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 4 0 4
511 4 $sfilter{$id} .= "<approxMatch name=\"" . $attribute . "\"><value>" . $value . "</value></approxMatch>";
512 4 return 1;
513 }
514 else
515 {
516 0 ▶ if ( (@_) < 4 )
Branch: 3 branches
BranchTrueFalseTotal
if (@_ < 4) { } 0 0 0
elsif (CORE::not defined $opt->{'attribute'}) { } 0 0 0
elsif (CORE::not defined $opt->{'value'}) { } 0 0 0
517 {
518 0 $errMsg{$id} = "Subroutine approxMatch did not have enough parameters defined.";
519 }
520 elsif ( !defined($opt->{attribute}) )
521 {
522 0 $errMsg{$id} = "Subroutine approxMatch attribute string is not defined.";
523 }
524 elsif ( !defined($opt->{value}) )
525 {
526 0 $errMsg{$id} = "Subroutine approxMatch value string is not defined.";
527 }
528 0 return 0;
529 }
530 }
531  
532  
533 # Method extensibleMatch
534 #
535 # The method extensibleMatch sets up a LDAP extensibleMatch filter.
536 #
537 # There is 1 required input options.
538 # Input option "value": String that contains the value of the
539 # attribute.
540 # There are 3 optional options.
541 # Input option "matchingRule": String that contains the value of the
542 # matchingRule.
543 # Input option "dnAttributes": String that contains the boolean value
544 # of true or false
545 # Input option "name": String that contains the name string.
546 #
547 #
548 # $return = $filter->extensibleMatch( { value =>" ",
549 # name => " ",
550 # matchingRule => " ",
551 # dnAttributes => " " } );
552 #
553 # Method output; Returns true on success; false on error, error message
554 # can be gotten with error property.
555 #
556  
557 sub extensibleMatch
558 4 ▶{
Subroutine extensibleMatch: called CC=21 SCAR=34.6
Pod documented
559 4 my ($dsml, $opt) = @_;
560 4 my $id = ident($dsml);
561 4 my $name;
562 my $value;
563 4 my $mrule;
564 4 my $dnAttributes;
565 4 $errMsg{$id} = "";
566  
567 4 ▶ $value = (ref($opt->{value}) ? ${$opt->{value}} : $opt->{value});
Branch: 1 branch
BranchTrueFalseTotal
ref $opt->{'value'} ? : 1 3 4
568 4 ▶ $name = (ref($opt->{name}) ? ${$opt->{name}} : $opt->{name}) if ( $opt->{name});
Branch: 2 branches
BranchTrueFalseTotal
if $opt->{"name"} 3 1 4
ref $opt->{'name'} ? : 1 2 3
569 0 ▶ $mrule = (ref($opt->{matchingRule}) ? ${$opt->{matchingRule}} : $opt->{matchingRule}) if ( $opt->{matchingRule});
Branch: 2 branches
BranchTrueFalseTotal
if $opt->{"matchingRule"} 0 4 4
ref $opt->{'matchingRule'} ? : 0 0 0
570 4 ▶ $dnAttributes = (ref($opt->{dnAttributes}) ? ${$opt->{dnAttributes}} : $opt->{dnAttributes}) if ( defined($opt->{dnAttributes}) );
Branch: 2 branches
BranchTrueFalseTotal
if defined $opt->{"dnAttributes"} 3 1 4
ref $opt->{'dnAttributes'} ? : 1 2 3
571  
572 4 ▶ if ( $opt )
Branch: 1 branch
BranchTrueFalseTotal
if ($opt) { } 4 0 4
573 {
574 4 ▶ if ( !$opt->{value} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"value"}) 0 4 4
575 {
576 0 $errMsg{$id} = "Subroutine extensibleMatch value string is not defined.";
577 0 return 0;
578 }
579  
580 4 ▶ $_ = lc($dnAttributes) if ( defined($opt->{dnAttributes}) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"dnAttributes"} 3 1 4
581  
582 4 ▶ if ( defined($_) && !(/^(true)||(false)$/) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and CORE::not /^(true)||(false)$/) 0 4 4
Condition33%1/3
defined $_ and CORE::not /^(true)||(false)$/
!ll&&!rl&&r
040
MC/DC0%0/2
defined $_ and CORE::not /^(true)||(false)$/
defined $_ CORE::not /^(true)||(false)$/
Truth table33%1/3
A and not(B)
A= defined $_B= CORE::not /^(true)||(false)$/
ABresult
0X0
100
111
583 {
584 0 $errMsg{$id} = "Subroutine extensibleMatch dnAttributes string is not properly defined.";
585 0 return 0;
586 }
587  
588 4 ▶ _specialChar(\$value) if ( $value =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /(&||<||>||"||')/ 4 0 4
589  
590 4 ▶ if ( $opt->{name})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"name"}) 3 1 4
591 {
592 3 ▶ _specialChar(\$name) if ( $name =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /(&||<||>||"||')/ 3 0 3
593 }
594  
595 4 ▶ if ( $opt->{matchingRule})
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"matchingRule"}) 0 4 4
596 {
597 0 ▶ _specialChar(\$mrule) if ( $mrule =~ /(&||<||>||"||')/);
Branch: 1 branch
BranchTrueFalseTotal
if $mrule =~ /(&||<||>||"||')/ 0 0 0
598 }
599  
600 4 $sfilter{$id} .= "<extensibleMatch";
601 4 ▶ $sfilter{$id} .= " name=\"" . $name . "\"" if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 3 1 4
602 4 ▶ $sfilter{$id} .= " dnAttributes=\"" . $dnAttributes . "\"" if ($opt->{dnAttributes});
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"dnAttributes"} 3 1 4
603 4 ▶ $sfilter{$id} .= " matchingRule=\"" . $mrule . "\"" if ($opt->{matchingRule});
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"matchingRule"} 0 4 4
604 4 $sfilter{$id} .= "><value>" . $value . "</value></extensibleMatch>";
605 4 return 1;
606 }
607 else
608 {
609 0 $errMsg{$id} = "Subroutine extensibleMatch had no input options defined.";
610 0 return 0;
611 }
612 }
613  
614 # Method or
615 #
616 # The method or sets up a beginning or element of a LDAP or filter.
617 #
618 # There are no required input options.
619 #
620 # $return = $filter->or();
621 #
622 # Method output; Always returns true for success.
623 #
624  
625 sub or
626 0 ▶{
Subroutine or: not called CC=1 SCAR=6.9
Pod documented
627 0 my ($dsml) = @_;
628 0 $sfilter{ident $dsml} .= "<or>";
629 0 return 1;
630 }
631  
632 # Method endor
633 #
634 # The method endor sets up a ending or element of a LDAP or filter.
635 #
636 # There are no required input options.
637 #
638 # $return = $filter->or();
639 #
640 # Method output; Always returns true for success.
641 #
642  
643 sub endor
644 0 ▶{
Subroutine endor: not called CC=1 SCAR=6.9
Pod documented
645 0 my ($dsml) = @_;
646 0 $sfilter{ident $dsml} .= "</or>";
647 0 return 1;
648 }
649  
650  
651 # Method and
652 #
653 # The method and sets up a beginning and element of a LDAP and filter.
654 #
655 # There are no required input options.
656 #
657 # $return = $filter->and();
658 #
659 # Method output; Always return true for success.
660 #
661  
662 sub and
663 0 ▶{
Subroutine and: not called CC=1 SCAR=6.9
Pod documented
664 0 my ($dsml) = @_;
665 0 $sfilter{ident $dsml} .= "<and>";
666 0 return 1;
667 }
668  
669 # Method endand
670 #
671 # The method endand sets up a ending and element of a LDAP and filter.
672 #
673 # There are no required input options.
674 #
675 # $return = $filter->endand();
676 #
677 # Method output; Always returns true for success.
678 #
679  
680 sub endand
681 0 ▶{
Subroutine endand: not called CC=1 SCAR=6.9
Pod documented
682 0 my ($dsml) = @_;
683 0 $sfilter{ident $dsml} .= "</and>";
684 0 return 1;
685 }
686  
687 # Method not
688 #
689 # The method not sets up a beginning not element of a LDAP not filter.
690 #
691 # There are no required input options.
692 #
693 # $return = $filter->not();
694 #
695 # Method output; Always return true for success.
696 #
697  
698 sub not
699 0 ▶{
Subroutine not: not called CC=1 SCAR=6.9
Pod documented
700 0 my ($dsml) = @_;
701 0 $sfilter{ident $dsml} .= "<not>";
702 0 return 1;
703 }
704  
705 # Method endnot
706 #
707 # The method endnot sets up the ending not element of a LDAP not filter.
708 #
709 # There are no required input options.
710 #
711 # $return = $filter->endnot();
712 #
713 # Method output; Always returns true for success.
714 #
715  
716 sub endnot
717 0 ▶{
Subroutine endnot: not called CC=1 SCAR=6.9
Pod documented
718 0 my ($dsml) = @_;
719 0 $sfilter{ident $dsml} .= "</not>";
720 0 return 1;
721 }
722  
723 }
724  
725  
726 3 1; # Magic true value required at end of module
727  
728 __END__
« blib/lib/Net/DSML/Control.pm ↑ Summary test.cfg »