blib/lib/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 0.0% 0 / 2 totaltotal 17.4% 30 / 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 blib/lib/QuadPres/WriteContents.pm »
1 package QuadPres::Url;
2 2 $QuadPres::Url::VERSION = '0.28.2';
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::MoreUtils 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 {
25 $Carp::RefArgFormatter = sub {
26 0 ▶ Dumper( [ $_[0] ], );
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 ▶ };
Subroutine _init: not called CC=6 SCAR=37.4
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 {
57 0 ▶ my $self = shift;
Subroutine get_url: not called CC=1 SCAR=6.9
Pod undocumented
58  
59 0 return [ @{ $self->url } ];
60 }
61  
62 sub get_relative_url
63 {
64 0 ▶ my $base = shift;
Subroutine get_relative_url: not called CC=2 SCAR=17.9
Pod undocumented
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 {
73 0 ▶ my $base = shift;
Subroutine _get_url_worker: not called CC=21 SCAR=61.4
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__
165  
166 =pod
167  
168 =encoding UTF-8
169  
170 =head1 VERSION
171  
172 version 0.28.2
173  
174 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
175  
176 =head1 SUPPORT
177  
178 =head2 Websites
179  
180 The following websites have more information about this module, and may be of help to you. As always,
181 in addition to those websites please use your favorite search engine to discover more resources.
182  
183 =over 4
184  
185 =item *
186  
187 MetaCPAN
188  
189 A modern, open-source CPAN search engine, useful to view POD in HTML format.
190  
191 L<https://metacpan.org/release/QuadPres>
192  
193 =item *
194  
195 RT: CPAN's Bug Tracker
196  
197 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
198  
199 L<https://rt.cpan.org/Public/Dist/Display.html?Name=QuadPres>
200  
201 =item *
202  
203 CPANTS
204  
205 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
206  
207 L<http://cpants.cpanauthors.org/dist/QuadPres>
208  
209 =item *
210  
211 CPAN Testers
212  
213 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
214  
215 L<http://www.cpantesters.org/distro/Q/QuadPres>
216  
217 =item *
218  
219 CPAN Testers Matrix
220  
221 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
222  
223 L<http://matrix.cpantesters.org/?dist=QuadPres>
224  
225 =item *
226  
227 CPAN Testers Dependencies
228  
229 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
230  
231 L<http://deps.cpantesters.org/?module=QuadPres>
232  
233 =back
234  
235 =head2 Bugs / Feature Requests
236  
237 Please report any bugs or feature requests by email to C<bug-quadpres at rt.cpan.org>, or through
238 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=QuadPres>. You will be automatically notified of any
239 progress on the request by the system.
240  
241 =head2 Source Code
242  
243 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
244 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
245 from your repository :)
246  
247 L<https://github.com/shlomif/quad-pres>
248  
249 git clone https://github.com/shlomif/quad-pres.git
250  
251 =head1 AUTHOR
252  
253 Shlomi Fish <shlomif@cpan.org>
254  
255 =head1 BUGS
256  
257 Please report any bugs or feature requests on the bugtracker website
258 L<https://github.com/shlomif/quad-pres/issues>
259  
260 When submitting a bug or request, please include a test-file or a
261 patch to an existing test-file that illustrates the bug or desired
262 feature.
263  
264 =head1 COPYRIGHT AND LICENSE
265  
266 This software is Copyright (c) 2019 by Shlomi Fish.
267  
268 This is free software, licensed under:
269  
270 The MIT (X11) License
271  
272 =cut
↑ Summary blib/lib/QuadPres/WriteContents.pm »