blib/lib/URLprocessor.pm

filter: Statementstmt 96.8% 153 / 158 Branchbran 79.1% 76 / 96 Conditioncond 55.5% 40 / 72 MC/DCmcdc 31.1% 14 / 45 Subroutinesub 96.6% 29 / 30 Podpod 100% 20 / 20 totaltotal 78.8% 332 / 421 CC 74 SCAR 29.9
CC
74
Cov
83%
_is_valid
62.4
_prepare_url
12.6
_parse_params
8.0
CRAP 20.0
↑ Summary
1 package URLprocessor;
2  
3 # h2xs -XA -n URLprocessor
4  
5 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use warnings;
8  
9 1 require Exporter;
10  
11 1 our @ISA = qw(Exporter);
12  
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16  
17 # This allows declaration use URLprocessor ':all';
18 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19 # will save memory.
20 1 our %EXPORT_TAGS = ( 'all' => [ qw(
21
22 ) ] );
23  
24 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25  
26 1 our @EXPORT = qw(
27  
28 );
29  
30 1 our $VERSION = '0.02';
31  
32  
33 # Let's rock.
34  
35 ##########################################################################################
36 ### Public interface.
37 ##########################################################################################
38  
39 3 ▶sub new {
Subroutine new: called CC=4 SCAR=14.4
Pod documented
40 3 my $class = shift;
41 3 my $self = {
42 URL => undef,
43 GLOBAL_PART => undef,
44 LOCAL_PART => undef,
45 #---
46 PROTOCOL => undef,
47 LOGIN => undef,
48 PASSWD => undef,
49 HOST => undef,
50 PORT => undef,
51 LOCAL_PATH => undef,
52 PARAMS => {}, # hash representation of params.
53 FRAGMENT => undef, # after sign #
54 #--
55 PARAMS_VALID => undef,
56 };
57 3 bless($self, $class);
58
59 3 ▶ $self->{URL} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 0 3
60  
61 # Parsing (lower case) url.
62 3 ▶ if (defined $self->{URL} and $self->{URL} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"URL"} and $self->{"URL"} ne "") 3 0 3
Condition33%1/3
defined $self->{"URL"} and $self->{"URL"} ne ""
!ll&&!rl&&r
003
MC/DC0%0/2
defined $self->{"URL"} and $self->{"URL"} ne ""
defined $self->{"URL"} $self->{"URL"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"URL"}B= $self->{"URL"} ne ""
ABresult
0X0
100
111
63 3 $self->{URL} =~ s/^\s+//g;
64 3 $self->{URL} =~ s/\s+$//g;
65 3 $self->{URL} = lc $self->{URL};
66 3 $self->_parse_url;
67 }
68
69 3 return $self;
70 }
71  
72  
73 6 ▶sub url {
Subroutine url: called CC=1 SCAR=0.0
Pod documented
74 6 my $self = shift;
75 6 $self->_prepare_url;
76 6 return $self->{URL}; # String of URL.
77 }
78  
79  
80 1 ▶sub url_global_part {
Subroutine url_global_part: called CC=1 SCAR=0.0
Pod documented
81 1 my $self = shift;
82 1 return $self->{GLOBAL_PART};
83 }
84  
85  
86 1 ▶sub url_local_part {
Subroutine url_local_part: called CC=1 SCAR=0.0
Pod documented
87 1 my $self = shift;
88 1 return $self->{LOCAL_PART};
89 }
90  
91  
92 5 ▶sub protocol {
Subroutine protocol: called CC=3 SCAR=11.0
Pod documented
93 5 my $self = shift;
94 5 ▶ return $self->{PROTOCOL} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 2 5
95
96 2 $self->{PROTOCOL} = shift;
97 2 ▶ $self->{PROTOCOL} = lc $self->{PROTOCOL} if defined $self->{PROTOCOL};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"PROTOCOL"} 1 1 2
98 }
99  
100 6 ▶sub login {
Subroutine login: called CC=2 SCAR=6.9
Pod documented
101 6 my $self = shift;
102 6 ▶ return $self->{LOGIN} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 2 6
103
104 2 $self->{LOGIN} = shift;
105 }
106  
107 6 ▶sub passwd {
Subroutine passwd: called CC=2 SCAR=6.9
Pod documented
108 6 my $self = shift;
109 6 ▶ return $self->{PASSWD} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 2 6
110
111 2 $self->{PASSWD} = shift;
112 }
113  
114 5 ▶sub host {
Subroutine host: called CC=3 SCAR=11.0
Pod documented
115 5 my $self = shift;
116 5 ▶ return $self->{HOST} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 2 5
117
118 2 $self->{HOST} = shift;
119 2 ▶ $self->{HOST} = lc $self->{HOST} if defined $self->{HOST};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"HOST"} 1 1 2
120 }
121  
122 10 ▶sub port {
Subroutine port: called CC=2 SCAR=6.9
Pod documented
123 10 my $self = shift;
124 10 ▶ return $self->{PORT} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 6 4 10
125
126 4 $self->{PORT} = shift;
127 }
128  
129 16 ▶sub localpath {
Subroutine localpath: called CC=6 SCAR=17.9
Pod documented
130 16 my $self = shift;
131 16 ▶ return $self->{LOCAL_PATH} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 11 5 16
132
133 5 my $path = shift;
134 # Only SCALAR, ARRAY and undef are allowed.
135 5 ▶ if (ref $path eq '' or ref $path eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path eq '' or ref $path eq 'SCALAR') { } 2 3 5
elsif (ref $path eq 'ARRAY') { } 2 1 3
Condition66%2/3
ref $path eq "" or ref $path eq "SCALAR"
l!l&&r!l&&!r
203
MC/DC50%1/2
ref $path eq "" or ref $path eq "SCALAR"
ref $path eq "" ref $path eq "SCALAR"
Truth table66%2/3
A or B
A= ref $path eq ""B= ref $path eq "SCALAR"
ABresult
1X1
011
000
136 2 $self->{LOCAL_PATH} = $path;
137 }
138 elsif (ref $path eq 'ARRAY') {
139 2 $self->{LOCAL_PATH} = join '/', @{$path};
140 }
141
142 5 ▶ return unless defined $self->{LOCAL_PATH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"LOCAL_PATH"} 1 4 5
143 4 $self->{LOCAL_PATH} = '/'.$self->{LOCAL_PATH};
144 4 $self->{LOCAL_PATH} =~ s/^\/+/\//;
145 # $self->{LOCAL_PATH} = lc $self->{LOCAL_PATH};
146  
147 }
148  
149 3 ▶sub localpath_array {
Subroutine localpath_array: called CC=1 SCAR=0.0
Pod documented
150 3 my $self = shift;
151 3 my $path = $self->localpath;
152 3 $path =~ s/^\///;
153
154 3 return split '/', $path;
155 }
156  
157 6 ▶sub fragment {
Subroutine fragment: called CC=2 SCAR=6.9
Pod documented
158 6 my $self = shift;
159 6 ▶ return $self->{FRAGMENT} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 2 6
160
161 2 $self->{FRAGMENT} = shift;
162 }
163  
164  
165  
166 ##########################################################################################
167 ### Params methods.
168 ##########################################################################################
169  
170 1 ▶sub params_hash {
Subroutine params_hash: called CC=2 SCAR=8.1
Pod documented
171 1 my $self = shift;
172 1 ▶ return $self->{PARAMS} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 0 1
173
174 0 $self->{PARAMS} = shift;
175 }
176  
177  
178 10 ▶sub params_string {
Subroutine params_string: called CC=3 SCAR=11.0
Pod documented
179 10 my $self = shift;
180 10 ▶ my $userDelimiter = (@_) ? shift : '&'; # & - default value
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 9 10
181
182 10 my $params = '';
183 10 my $delimiter = '';
184 10 ▶ while(my($k, $v) = each %{$self->{PARAMS}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"PARAMS"};}) 16 10 26
185 16 $params .= "$delimiter$k=$v";
186 16 $delimiter = $userDelimiter;
187 }
188 10 return $params;
189 }
190  
191  
192 5 ▶sub param_value {
Subroutine param_value: called CC=3 SCAR=11.0
Pod documented
193 5 my $self = shift;
194 5 my $param = shift;
195
196 5 ▶ return $self->{PARAMS}->{$param} if defined $param and exists $self->{PARAMS}->{$param};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param and exists $self->{"PARAMS"}{$param} 2 3 5
Condition100%3/3
defined $param and exists $self->{"PARAMS"}{$param}
!ll&&!rl&&r
122
MC/DC100%2/2
defined $param and exists $self->{"PARAMS"}{$param}
defined $param exists $self->{"PARAMS"}{$param}
Truth table100%3/3
A and B
A= defined $paramB= exists $self->{"PARAMS"}{$param}
ABresult
0X0
100
111
197 3 return undef;
198 }
199  
200  
201 # Pay attention with arguments order!
202 # This function may generate hidden errors.
203 3 ▶sub param_add {
Subroutine param_add: called CC=3 SCAR=12.0
Pod documented
204 3 my $self = shift;
205 3 my $param = shift;
206 3 my $val = shift;
207
208 3 ▶ $self->{PARAMS}->{$param} = $val if defined $param and defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $param and defined $val 3 0 3
Condition33%1/3
defined $param and defined $val
!ll&&!rl&&r
003
MC/DC0%0/2
defined $param and defined $val
defined $param defined $val
Truth table33%1/3
A and B
A= defined $paramB= defined $val
ABresult
0X0
100
111
209 }
210  
211 2 ▶sub param_del {
Subroutine param_del: called CC=2 SCAR=7.1
Pod documented
212 2 my $self = shift;
213 2 my $param = shift;
214
215 2 ▶ delete $self->{PARAMS}->{$param} if defined $param;
Branch: 1 branch
BranchTrueFalseTotal
if defined $param 2 0 2
216 }
217  
218 # Check parameter existence.
219 3 ▶sub param_exist {
Subroutine param_exist: called CC=3 SCAR=11.0
Pod documented
220 3 my $self = shift;
221 3 my $param = shift;
222  
223 3 ▶ return 1 if defined $param and exists $self->{PARAMS}->{$param};
Branch: 1 branch
BranchTrueFalseTotal
if defined $param and exists $self->{"PARAMS"}{$param} 1 2 3
Condition66%2/3
defined $param and exists $self->{"PARAMS"}{$param}
!ll&&!rl&&r
021
MC/DC50%1/2
defined $param and exists $self->{"PARAMS"}{$param}
defined $param exists $self->{"PARAMS"}{$param}
Truth table66%2/3
A and B
A= defined $paramB= exists $self->{"PARAMS"}{$param}
ABresult
0X0
100
111
224 2 return 0;
225 }
226  
227 # There is no way to set string of params from outside. It is bad idea, but it isn't rule.
228 # In the future it will may be implemented it.
229  
230  
231 ##########################################################################################
232 ### Parsing "private" methods.
233 ##########################################################################################
234  
235 6 ▶sub _prepare_url {
Subroutine _prepare_url: called CC=11 SCAR=25.3
236 6 my $self = shift;
237 6 $self->{URL} = '';
238 6 ▶ $self->{URL} = "$self->{PROTOCOL}://" if defined $self->{PROTOCOL};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"PROTOCOL"} 6 0 6
239 6 ▶ $self->{URL} .= "$self->{LOGIN}:$self->{PASSWD}@" if defined $self->{LOGIN} and defined $self->{PASSWD};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"LOGIN"} and defined $self->{"PASSWD"} 5 1 6
Condition66%2/3
defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
!ll&&!rl&&r
105
MC/DC50%1/2
defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
defined $self->{"LOGIN"} defined $self->{"PASSWD"}
Truth table66%2/3
A and B
A= defined $self->{"LOGIN"}B= defined $self->{"PASSWD"}
ABresult
0X0
100
111
240 6 ▶ $self->{URL} .= $self->{HOST} if defined $self->{HOST};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"HOST"} 6 0 6
241 6 ▶ $self->{URL} .= ":$self->{PORT}" if defined $self->{PORT};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"PORT"} 5 1 6
242 6 ▶ if (defined $self->{LOCAL_PATH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"LOCAL_PATH"}) 6 0 6
243 6 ▶ $self->{URL} .= '/' if $self->{LOCAL_PATH} !~ /^\//;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"LOCAL_PATH"} =~ m[^/] 0 6 6
244 6 $self->{URL} .= $self->{LOCAL_PATH}; # Sign '/' is not required on the end because the localpath may contains a file.
245 6 my $params_str = $self->params_string;
246 6 ▶ $self->{URL} .= "?$params_str" if $params_str ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $params_str ne "" 4 2 6
247 6 ▶ $self->{URL} .= "#$self->{FRAGMENT}" if defined $self->{FRAGMENT} and $self->{FRAGMENT} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"FRAGMENT"} and $self->{"FRAGMENT"} ne "" 6 0 6
Condition33%1/3
defined $self->{"FRAGMENT"} and $self->{"FRAGMENT"} ne ""
!ll&&!rl&&r
006
MC/DC0%0/2
defined $self->{"FRAGMENT"} and $self->{"FRAGMENT"} ne ""
defined $self->{"FRAGMENT"} $self->{"FRAGMENT"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"FRAGMENT"}B= $self->{"FRAGMENT"} ne ""
ABresult
0X0
100
111
248 }
249 }
250  
251  
252 12 ▶sub _split_url {
Subroutine _split_url: called CC=1 SCAR=0.0
253 12 my $self = shift;
254 # global_part local_part
255 12 return $self->{URL} =~ m|^(\w*?://[^/?&#]+)(?:(.+))?|;
256 }
257  
258  
259 17 ▶sub _parse_global_part {
Subroutine _parse_global_part: called CC=1 SCAR=0.0
260 17 my $self = shift;
261 # protocol auth host port
262 17 return $self->{GLOBAL_PART} =~ m|^(\w*)://(?:([^@/]+)@)?([^:@/?#]*)(?:\:(.+))?|;
263 # If host has a + instead of * then it isn't working correctly.
264 }
265  
266  
267 18 ▶sub _parse_local_part {
Subroutine _parse_local_part: called CC=1 SCAR=0.0
268 18 my $self = shift;
269 # localpath params fragment
270 18 return $self->{LOCAL_PART} =~ m|^(/[^?&#]*)(?:\?([^#]*))?(?:#(.+))?|;
271 }
272  
273  
274 # This is normal function, not method. It isn't working on object attributes.
275 # Return PARAMS_VALID, \%PARAMS
276 # PARAMS_VALID == 0 - error
277 # PARAMS_VALID == 1 - ok
278 17 ▶sub _parse_params {
Subroutine _parse_params: called CC=8 SCAR=20.8
279 17 my $params = shift;
280 17 my $separator = shift;
281  
282 # Params is empty.
283 17 ▶ if (!defined $params or $params eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $params or $params eq "") 3 14 17
Condition100%3/3
not defined $params or $params eq ""
l!l&&r!l&&!r
2114
MC/DC100%2/2
not defined $params or $params eq ""
not defined $params $params eq ""
Truth table100%3/3
not(A) or B
A= not defined $paramsB= $params eq ""
ABresult
1X1
011
000
284 3 return (1, undef);
285 }
286  
287 14 my $params_ref = {};
288 14 my $valid_status = 0;
289 # Split by pairs param=val
290 14 foreach (split $separator, $params) {
291 19 ▶ return (0, undef) if $_ eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "" 3 16 19
292
293 16 my @param_val = split '=', $_;
294 16 ▶ if(scalar(@param_val) == 2 and $param_val[0] ne '' and $param_val[1] ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @param_val == 2 and $param_val[0] ne '' and $param_val[1] ne '') { } 11 5 16
Condition66%4/6
scalar @param_val == 2 and $param_val[0] ne "" and $param_val[1] ne ""
!ll&&!rl&&r
5011
scalar @param_val == 2 and $param_val[0] ne ""
!ll&&!rl&&r
5011
MC/DC33%1/3
scalar @param_val == 2 and $param_val[0] ne "" and $param_val[1] ne ""
scalar @param_val == 2 $param_val[0] ne "" $param_val[1] ne ""
Truth table50%2/4
A and B and C
A= scalar @param_val == 2B= $param_val[0] ne ""C= $param_val[1] ne ""
ABCresult
0XX0
10X0
1100
1111
295 11 $params_ref->{$param_val[0]} = $param_val[1];
296 11 $valid_status = 1;
297 } else {
298 5 return (0, undef);
299 }
300 }
301
302 6 return ($valid_status, $params_ref);
303 }
304  
305  
306 # Parse URL string and save those parts.
307 # This method sets attributes.
308 3 ▶sub _parse_url {
Subroutine _parse_url: called CC=5 SCAR=16.3
309 3 my $self = shift;
310
311 # Split URL to global part and optionally localpath.
312 3 ($self->{GLOBAL_PART}, $self->{LOCAL_PART}) = $self->_split_url;
313
314 # Parse global part.
315 3 ▶ return unless defined $self->{GLOBAL_PART};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"GLOBAL_PART"} 0 3 3
316 3 my $auth;
317 3 ($self->{PROTOCOL}, $auth, $self->{HOST}, $self->{PORT}) = $self->_parse_global_part;
318  
319 # In global part: parse login and passwd.
320 3 ▶ ($self->{LOGIN}, $self->{PASSWD}) = split(':', $auth) if (defined $auth and $auth ne '');
Branch: 1 branch
BranchTrueFalseTotal
if defined $auth and $auth ne "" 2 1 3
Condition66%2/3
defined $auth and $auth ne ""
!ll&&!rl&&r
102
MC/DC50%1/2
defined $auth and $auth ne ""
defined $auth $auth ne ""
Truth table66%2/3
A and B
A= defined $authB= $auth ne ""
ABresult
0X0
100
111
321  
322 # Parse local part.
323 3 ▶ return unless defined $self->{LOCAL_PART};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"LOCAL_PART"} 0 3 3
324 3 my $params;
325 3 ($self->{LOCAL_PATH}, $params, $self->{FRAGMENT}) = $self->_parse_local_part;
326  
327 # Parse params.
328 3 ($self->{PARAMS_VALID}, $self->{PARAMS}) = _parse_params($params, '&'); # & - separator.
329  
330 }
331  
332  
333  
334  
335 ##########################################################################################
336 ### Validating methods.
337 ##########################################################################################
338  
339 11 ▶sub _is_valid {
Subroutine _is_valid: called CC=27 SCAR=41.3
340 11 my $self = shift;
341 11 my $msg = ''; # Message container
342
343 11 ▶ $msg .= "Global part is undef\n" if !defined $self->{GLOBAL_PART};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"GLOBAL_PART"} 0 11 11
344
345 11 ▶ $msg .= "Protocol is empty\n" if !defined $self->{PROTOCOL} or $self->{PROTOCOL} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"PROTOCOL"} or $self->{"PROTOCOL"} eq "" 1 10 11
Condition66%2/3
not defined $self->{"PROTOCOL"} or $self->{"PROTOCOL"} eq ""
l!l&&r!l&&!r
1010
MC/DC50%1/2
not defined $self->{"PROTOCOL"} or $self->{"PROTOCOL"} eq ""
not defined $self->{"PROTOCOL"} $self->{"PROTOCOL"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"PROTOCOL"}B= $self->{"PROTOCOL"} eq ""
ABresult
1X1
011
000
346 11 ▶ $msg .= "Login is undef\n" if !defined $self->{LOGIN} and defined $self->{PASSWD};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"LOGIN"} and defined $self->{"PASSWD"} 0 11 11
Condition66%2/3
not defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
!ll&&!rl&&r
740
MC/DC0%0/2
not defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
not defined $self->{"LOGIN"} defined $self->{"PASSWD"}
Truth table66%2/3
not(A) and B
A= not defined $self->{"LOGIN"}B= defined $self->{"PASSWD"}
ABresult
0X0
100
111
347 11 ▶ $msg .= "Passwd is undef\n" if defined $self->{LOGIN} and !defined $self->{PASSWD};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"LOGIN"} and not defined $self->{"PASSWD"} 0 11 11
Condition66%2/3
defined $self->{"LOGIN"} and not defined $self->{"PASSWD"}
!ll&&!rl&&r
470
MC/DC0%0/2
defined $self->{"LOGIN"} and not defined $self->{"PASSWD"}
defined $self->{"LOGIN"} not defined $self->{"PASSWD"}
Truth table66%2/3
A and not(B)
A= defined $self->{"LOGIN"}B= not defined $self->{"PASSWD"}
ABresult
0X0
100
111
348 11 ▶ if (defined $self->{LOGIN} and defined $self->{PASSWD}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"LOGIN"} and defined $self->{"PASSWD"}) 7 4 11
Condition66%2/3
defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
!ll&&!rl&&r
407
MC/DC50%1/2
defined $self->{"LOGIN"} and defined $self->{"PASSWD"}
defined $self->{"LOGIN"} defined $self->{"PASSWD"}
Truth table66%2/3
A and B
A= defined $self->{"LOGIN"}B= defined $self->{"PASSWD"}
ABresult
0X0
100
111
349 7 ▶ $msg .= "Login is empty\n" if $self->{LOGIN} eq '' and $self->{PASSWD} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOGIN"} eq "" and $self->{"PASSWD"} ne "" 0 7 7
Condition33%1/3
$self->{"LOGIN"} eq "" and $self->{"PASSWD"} ne ""
!ll&&!rl&&r
700
MC/DC0%0/2
$self->{"LOGIN"} eq "" and $self->{"PASSWD"} ne ""
$self->{"LOGIN"} eq "" $self->{"PASSWD"} ne ""
Truth table33%1/3
A and B
A= $self->{"LOGIN"} eq ""B= $self->{"PASSWD"} ne ""
ABresult
0X0
100
111
350 7 ▶ $msg .= "Passwd is empty\n" if $self->{LOGIN} ne '' and $self->{PASSWD} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOGIN"} ne "" and $self->{"PASSWD"} eq "" 0 7 7
Condition33%1/3
$self->{"LOGIN"} ne "" and $self->{"PASSWD"} eq ""
!ll&&!rl&&r
070
MC/DC0%0/2
$self->{"LOGIN"} ne "" and $self->{"PASSWD"} eq ""
$self->{"LOGIN"} ne "" $self->{"PASSWD"} eq ""
Truth table33%1/3
A and B
A= $self->{"LOGIN"} ne ""B= $self->{"PASSWD"} eq ""
ABresult
0X0
100
111
351 }
352  
353 11 ▶ $msg .= "Host is empty\n" if !defined $self->{HOST} or $self->{HOST} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"HOST"} or $self->{"HOST"} eq "" 1 10 11
Condition66%2/3
not defined $self->{"HOST"} or $self->{"HOST"} eq ""
l!l&&r!l&&!r
1010
MC/DC50%1/2
not defined $self->{"HOST"} or $self->{"HOST"} eq ""
not defined $self->{"HOST"} $self->{"HOST"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->{"HOST"}B= $self->{"HOST"} eq ""
ABresult
1X1
011
000
354 11 ▶ $msg .= "Port must be numeric value\n" if defined $self->{PORT} and $self->{PORT} !~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"PORT"} and not $self->{"PORT"} =~ /^\d+$/ 3 8 11
Condition100%3/3
defined $self->{"PORT"} and not $self->{"PORT"} =~ /^\d+$/
!ll&&!rl&&r
263
MC/DC100%2/2
defined $self->{"PORT"} and not $self->{"PORT"} =~ /^\d+$/
defined $self->{"PORT"} not $self->{"PORT"} =~ /^\d+$/
Truth table100%3/3
A and not(B)
A= defined $self->{"PORT"}B= not $self->{"PORT"} =~ /^\d+$/
ABresult
0X0
100
111
355 11 ▶ if (defined $self->{LOCAL_PART} and length $self->{LOCAL_PART} > 0 and !defined $self->{LOCAL_PATH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"LOCAL_PART"} and length $self->{"LOCAL_PART"} > 0 and not defined $self->{"LOCAL_PATH"}) 0 11 11
Condition33%2/6
defined $self->{"LOCAL_PART"} and length $self->{"LOCAL_PART"} > 0 and not defined $self->{"LOCAL_PATH"}
!ll&&!rl&&r
0110
defined $self->{"LOCAL_PART"} and length $self->{"LOCAL_PART"} > 0
!ll&&!rl&&r
0011
MC/DC0%0/3
defined $self->{"LOCAL_PART"} and length $self->{"LOCAL_PART"} > 0 and not defined $self->{"LOCAL_PATH"}
defined $self->{"LOCAL_PART"} length $self->{"LOCAL_PART"} > 0 not defined $self->{"LOCAL_PATH"}
Truth table25%1/4
A and B and not(C)
A= defined $self->{"LOCAL_PART"}B= length $self->{"LOCAL_PART"} > 0C= not defined $self->{"LOCAL_PATH"}
ABCresult
0XX0
10X0
1100
1111
356 # Chcek only defined localpath because params and fragmet are functional dependend by localpath.
357 0 $msg .= "Local part is set but localpath, parameters and fragment are undef\n";
358 }
359 0 ▶ if (!defined $self->{LOCAL_PATH} and (scalar keys %{$self->{PARAMS}} or defined $self->{FRAGMENT})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"LOCAL_PATH"} and scalar keys %{$$self{"PARAMS"};} || defined $self->{"FRAGMENT"}) 0 11 11
Condition16%1/6
not defined $self->{"LOCAL_PATH"} and scalar keys %{$$self{"PARAMS"};} || defined $self->{"FRAGMENT"}
!ll&&!rl&&r
1100
scalar keys %{$$self{"PARAMS"};} or defined $self->{"FRAGMENT"}
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $self->{"LOCAL_PATH"} and scalar keys %{$$self{"PARAMS"};} || defined $self->{"FRAGMENT"}
not defined $self->{"LOCAL_PATH"} scalar keys %{$$self{"PARAMS"};} defined $self->{"FRAGMENT"}
Truth table25%1/4
not(A) and B or C
A= not defined $self->{"LOCAL_PATH"}B= scalar keys %{$$self{"PARAMS"};}C= defined $self->{"FRAGMENT"}
ABCresult
0XX0
1000
11X1
1011
360 0 $msg .= "Localpath cannot be undef when parameters or fragment is set\n";
361 }
362
363 11 ▶ $msg .= "Badly parameters\n" if defined $self->{PARAMS_VALID} and $self->{PARAMS_VALID} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"PARAMS_VALID"} and $self->{"PARAMS_VALID"} == 0 0 11 11
Condition33%1/3
defined $self->{"PARAMS_VALID"} and $self->{"PARAMS_VALID"} == 0
!ll&&!rl&&r
0110
MC/DC0%0/2
defined $self->{"PARAMS_VALID"} and $self->{"PARAMS_VALID"} == 0
defined $self->{"PARAMS_VALID"} $self->{"PARAMS_VALID"} == 0
Truth table33%1/3
A and B
A= defined $self->{"PARAMS_VALID"}B= $self->{"PARAMS_VALID"} == 0
ABresult
0X0
100
111
364  
365 11 ▶ return (1, "OK") if $msg eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $msg eq "" 6 5 11
366 5 $msg =~ s/\n$//;
367 5 return (0, $msg); # 0 - invalid URL.
368 }
369  
370  
371 8 ▶sub valid_status {
Subroutine valid_status: called CC=1 SCAR=0.0
Pod documented
372 8 my $self = shift;
373  
374 8 return ($self->_is_valid)[0];
375 }
376  
377  
378 3 ▶sub valid_msg {
Subroutine valid_msg: called CC=1 SCAR=0.0
Pod documented
379 3 my $self = shift;
380  
381 3 return ($self->_is_valid)[1];
382 }
383  
384  
385  
386  
387 ##########################################################################################
388 ### Additional and useful "private" functions.
389 ##########################################################################################
390  
391 0 ▶sub _here_im {
Subroutine _here_im: not called CC=1 SCAR=6.9
392 0 return (caller(1))[3];
393 }
394  
395  
396 1 1;
397 __END__
↑ Summary