QuadPres/Url.pm

filter: Statementstmt 27.0% 23 / 85 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 53.8% 7 / 13 Podpod 100% 2 / 2 totaltotal 18.6% 32 / 172 CC 27 SCAR 55.4
CC
27
Cov
16%
_get_url_worker
462.0
_init
42.0
get_relative_url
6.0
CRAP 255.9
↑ Summary QuadPres/WriteContents.pm »
1 package QuadPres::Url;
2 2 $QuadPres::Url::VERSION = '0.32.0';
3 2 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use List::Util 1.34 qw( notall );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use parent 'QuadPres::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Dumper qw/ Dumper /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 __PACKAGE__->mk_acc_ref(
14 [
15 qw(
16 is_dir
17 mode
18 url
19 )
20 ]
21 );
22  
23 sub _init
24 0 ▶{
Subroutine _init: not called CC=6 SCAR=37.4
25 0 ▶ $Carp::RefArgFormatter = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 0 Dumper( [ $_[0] ], );
27 0 };
28 0 my $self = shift;
29  
30 0 my $url = shift;
31  
32 0 ▶ if ( !defined($url) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $url) 0 0 0
33 {
34 0 Carp::confess("URL passed undef.");
35 }
36  
37 0 ▶ if ( ref($url) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $url eq 'ARRAY') { } 0 0 0
38 {
39 0 ▶ if ( notall { defined } @$url )
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&notall(sub { defined $_; } , @$url)) 0 0 0
40 {
41 0 Carp::confess("URL passed FOOundef.");
42 }
43 0 $self->url( [@$url] );
44 }
45 else
46 {
47 0 $self->url( [ split( /\//, $url ) ] );
48 }
49 0 ▶ $self->is_dir( shift || 0 );
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
50 0 ▶ $self->mode( shift || 'server' );
Condition0%0/2
shift() || 'server'
l!l
00
MC/DC0%0/1
shift() || 'server'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
51  
52 0 return 0;
53 }
54  
55 sub get_url
56 0 ▶{
Subroutine get_url: not called CC=1 SCAR=6.9
Pod documented
57 0 my $self = shift;
58  
59 0 return [ @{ $self->url } ];
60 }
61  
62 sub get_relative_url
63 0 ▶{
Subroutine get_relative_url: not called CC=2 SCAR=17.9
Pod documented
64 0 my $base = shift;
65  
66 0 my $url = $base->_get_url_worker(@_);
67  
68 0 ▶ return ( ( $url eq "" ) ? "./" : $url );
Branch: 1 branch
BranchTrueFalseTotal
$url eq '' ? : 0 0 0
69 }
70  
71 sub _get_url_worker
72 0 ▶{
Subroutine _get_url_worker: not called CC=21 SCAR=61.4
73 0 my $base = shift;
74 0 my $to = shift;
75 0 my $slash_terminated = shift;
76  
77 0 my $prefix = "";
78  
79 0 my @this_url = @{ $base->get_url() };
80 0 my @other_url = @{ $to->get_url() };
81  
82 0 my $ret;
83  
84 0 my @this_url_bak = @this_url;
85 0 my @other_url_bak = @other_url;
86  
87 0 ▶ while (scalar(@this_url)
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]) 0 0 0
Condition0%0/5
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
!ll&&!rl&&r
000
scalar @this_url and scalar @other_url
!ll
00
MC/DC0%0/2
scalar @this_url and scalar @other_url and $this_url[0] eq $other_url[0]
scalar @this_url $this_url[0] eq $other_url[0]
Truth table0%0/3
A and B
A= scalar @this_urlB= $this_url[0] eq $other_url[0]
ABresult
0X0
100
111
88 && scalar(@other_url)
89 && ( $this_url[0] eq $other_url[0] ) )
90 {
91 0 shift(@this_url);
92 0 shift(@other_url);
93 }
94  
95 0 ▶ if ( ( !@this_url ) && ( !@other_url ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (@this_url or @other_url) 0 0 0
Condition0%0/3
@this_url or @other_url
l!l&&r!l&&!r
000
MC/DC0%0/2
@this_url or @other_url
@this_url @other_url
Truth table0%0/3
A or B
A= @this_urlB= @other_url
ABresult
1X1
011
000
96 {
97 0 ▶ if ( ( !$base->is_dir() ) ne ( !$to->is_dir() ) )
Branch: 1 branch
BranchTrueFalseTotal
if ((!$base->is_dir) ne !$to->is_dir) 0 0 0
98 {
99 0 Carp::confess("Two identical URLs with non-matching is_dir()'s");
100 }
101 0 ▶ if ( !$base->is_dir() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($base->is_dir) 0 0 0
102 {
103 0 ▶ if ( scalar(@this_url_bak) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @this_url_bak) { } 0 0 0
104 {
105 0 return $prefix . $this_url_bak[-1];
106 }
107 else
108 {
109 0 die "Root URL is not a directory";
110 }
111 }
112 }
113  
114 0 ▶ if ( ( $base->mode eq "harddisk" ) && ( $to->is_dir() ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($base->mode eq "harddisk" and $to->is_dir) 0 0 0
Condition0%0/3
$base->mode eq "harddisk" and $to->is_dir
!ll&&!rl&&r
000
MC/DC0%0/2
$base->mode eq "harddisk" and $to->is_dir
$base->mode eq "harddisk" $to->is_dir
Truth table0%0/3
A and B
A= $base->mode eq "harddisk"B= $to->is_dir
ABresult
0X0
100
111
115 {
116 0 push @other_url, "index.html";
117 }
118  
119 0 $ret = "";
120  
121 0 ▶ if ($slash_terminated)
Branch: 1 branch
BranchTrueFalseTotal
if ($slash_terminated) { } 0 0 0
122 {
123 0 ▶ if ( ( scalar(@this_url) == 0 ) && ( scalar(@other_url) == 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @this_url == 0 and scalar @other_url == 0) { } 0 0 0
Condition0%0/3
scalar @this_url == 0 and scalar @other_url == 0
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @this_url == 0 and scalar @other_url == 0
scalar @this_url == 0 scalar @other_url == 0
Truth table0%0/3
A and B
A= scalar @this_url == 0B= scalar @other_url == 0
ABresult
0X0
100
111
124 {
125 0 $ret = $prefix;
126 }
127 else
128 {
129 0 ▶ if ( !$base->is_dir() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($base->is_dir) 0 0 0
130 {
131 0 pop(@this_url);
132 }
133 0 $ret .= join( "/", ( map { ".." } @this_url ), @other_url );
134 0 ▶ if ( $to->is_dir() && ( $base->mode ne "harddisk" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($to->is_dir and $base->mode ne "harddisk") 0 0 0
Condition0%0/3
$to->is_dir and $base->mode ne "harddisk"
!ll&&!rl&&r
000
MC/DC0%0/2
$to->is_dir and $base->mode ne "harddisk"
$to->is_dir $base->mode ne "harddisk"
Truth table0%0/3
A and B
A= $to->is_dirB= $base->mode ne "harddisk"
ABresult
0X0
100
111
135 {
136 0 $ret .= "/";
137 }
138 }
139 }
140 else
141 {
142 0 $ret .= $prefix;
143  
144 0 my @components;
145 0 ▶ push @components,
Branch: 1 branch
BranchTrueFalseTotal
$base->is_dir ? : 0 0 0
146 ( ("..") x ( $base->is_dir ? @this_url : @this_url - 1 ) );
147 0 push @components, @other_url;
148 0 $ret .= join( "/", @components );
149 0 ▶ if ( ( $to->is_dir() )
Branch: 1 branch
BranchTrueFalseTotal
if ($to->is_dir and $base->mode ne "harddisk" and scalar @components) 0 0 0
Condition0%0/5
$to->is_dir and $base->mode ne "harddisk" and scalar @components
!ll
00
$to->is_dir and $base->mode ne "harddisk"
!ll&&!rl&&r
000
MC/DC0%0/2
$to->is_dir and $base->mode ne "harddisk" and scalar @components
$to->is_dir $base->mode ne "harddisk"
Truth table0%0/3
A and B
A= $to->is_dirB= $base->mode ne "harddisk"
ABresult
0X0
100
111
150 && ( $base->mode ne "harddisk" )
151 && scalar(@components) )
152 {
153 0 $ret .= "/";
154 }
155 }
156  
157 #if (($to->is_dir()) && (scalar(@other_url) || $slash_terminated))
158  
159 0 return $ret;
160 }
161  
162 2 1;
163  
164 __END__
↑ Summary QuadPres/WriteContents.pm »