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 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 blib/lib/QuadPres/WriteContents.pm »
1 package QuadPres::Url;
2 2 $QuadPres::Url::VERSION = '0.28.4';
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 {
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 documented
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 documented
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 NAME
171  
172 =head1 VERSION
173  
174 version 0.28.4
175  
176 =head1 SYNOPSIS
177  
178 =head1 DESCRIPTION
179  
180 =head1 METHODS
181  
182 =head2 $url->get_relative_url($other_url)
183  
184 =head2 $url->get_url()
185  
186 =head2 $url->mode()
187  
188 =head2 $url->is_dir()
189  
190 =head2 $url->url()
191  
192 =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
193  
194 =head1 SUPPORT
195  
196 =head2 Websites
197  
198 The following websites have more information about this module, and may be of help to you. As always,
199 in addition to those websites please use your favorite search engine to discover more resources.
200  
201 =over 4
202  
203 =item *
204  
205 MetaCPAN
206  
207 A modern, open-source CPAN search engine, useful to view POD in HTML format.
208  
209 L<https://metacpan.org/release/QuadPres>
210  
211 =item *
212  
213 RT: CPAN's Bug Tracker
214  
215 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
216  
217 L<https://rt.cpan.org/Public/Dist/Display.html?Name=QuadPres>
218  
219 =item *
220  
221 CPANTS
222  
223 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
224  
225 L<http://cpants.cpanauthors.org/dist/QuadPres>
226  
227 =item *
228  
229 CPAN Testers
230  
231 The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
232  
233 L<http://www.cpantesters.org/distro/Q/QuadPres>
234  
235 =item *
236  
237 CPAN Testers Matrix
238  
239 The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
240  
241 L<http://matrix.cpantesters.org/?dist=QuadPres>
242  
243 =item *
244  
245 CPAN Testers Dependencies
246  
247 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
248  
249 L<http://deps.cpantesters.org/?module=QuadPres>
250  
251 =back
252  
253 =head2 Bugs / Feature Requests
254  
255 Please report any bugs or feature requests by email to C<bug-quadpres at rt.cpan.org>, or through
256 the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=QuadPres>. You will be automatically notified of any
257 progress on the request by the system.
258  
259 =head2 Source Code
260  
261 The code is open to the world, and available for you to hack on. Please feel free to browse it and play
262 with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
263 from your repository :)
264  
265 L<https://github.com/shlomif/quad-pres>
266  
267 git clone https://github.com/shlomif/quad-pres.git
268  
269 =head1 AUTHOR
270  
271 Shlomi Fish <shlomif@cpan.org>
272  
273 =head1 BUGS
274  
275 Please report any bugs or feature requests on the bugtracker website
276 L<https://github.com/shlomif/quad-pres/issues>
277  
278 When submitting a bug or request, please include a test-file or a
279 patch to an existing test-file that illustrates the bug or desired
280 feature.
281  
282 =head1 COPYRIGHT AND LICENSE
283  
284 This software is Copyright (c) 2019 by Shlomi Fish.
285  
286 This is free software, licensed under:
287  
288 The MIT (X11) License
289  
290 =cut
↑ Summary blib/lib/QuadPres/WriteContents.pm »