URI/file/Mac.pm

filter: Statementstmt 90.2% 74 / 82 Branchbran 72.0% 36 / 50 Conditioncond 88.8% 8 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 2 totaltotal 82.0% 128 / 156 CC 33 SCAR 28.6
CC
33
Cov
84%
file
24.5
dir
12.0
_file_extract_path
9.0
CRAP 17.5
« URI/Heuristic.pm ↑ Summary URI/file.pm »
1 package URI::file::Mac;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent 'URI::file::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our $VERSION = '5.40';
11  
12 18 ▶sub _file_extract_path {
Subroutine _file_extract_path: called CC=9 SCAR=22.0
13 18 shift; # $class
14 18 my $path = shift;
15  
16 18 my @pre;
17 18 ▶ if ($path =~ s/^(:+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s/^(:+)//) { } 10 8 18
18 10 ▶ if (length($1) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $1 == 1) { } 6 4 10
19 6 ▶ @pre = (".") unless length($path);
Branch: 1 branch
BranchTrueFalseTotal
unless length $path 2 4 6
20 }
21 else {
22 4 @pre = ("..") x (length($1) - 1);
23 }
24 }
25 else { #absolute
26 8 $pre[0] = "";
27 }
28  
29 18 my $isdir = ($path =~ s/:$//);
30 18 $path =~ s,([%/;\t\n\f\r\x0b ]), URI::Escape::escape_char($1),eg;
31  
32 18 my @path = split(/:/, $path, -1);
33 18 for (@path) {
34 24 ▶ if ($_ eq "." || $_ eq "..") {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "." or $_ eq "..") 4 20 24
Condition100%3/3
$_ eq "." or $_ eq ".."
l!l&&r!l&&!r
2220
MC/DC100%2/2
$_ eq "." or $_ eq ".."
$_ eq "." $_ eq ".."
Truth table100%3/3
A or B
A= $_ eq "."B= $_ eq ".."
ABresult
1X1
011
000
35 4 $_ = "%2E" x length($_);
36 }
37 24 ▶ $_ = ".." unless length($_);
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 24 24
38 }
39 18 ▶ push(@path, "") if $isdir;
Branch: 1 branch
BranchTrueFalseTotal
if $isdir 0 18 18
40 18 (join("/", @pre, @path), 1);
41 }
42  
43  
44 33 ▶sub file {
Subroutine file: called CC=23 SCAR=32.0
Pod undocumented
45 33 my $class = shift;
46 33 my $uri = shift;
47 33 my @path;
48  
49 33 my $auth = $uri->authority;
50 33 ▶ if (defined $auth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auth) 11 22 33
51 11 ▶ if (lc($auth) ne "localhost" && $auth ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $auth ne "localhost" and $auth ne "") 5 6 11
Condition100%3/3
lc $auth ne "localhost" and $auth ne ""
!ll&&!rl&&r
245
MC/DC100%2/2
lc $auth ne "localhost" and $auth ne ""
lc $auth ne "localhost" $auth ne ""
Truth table100%3/3
A and B
A= lc $auth ne "localhost"B= $auth ne ""
ABresult
0X0
100
111
52 5 my $u_auth = uri_unescape($auth);
53 5 ▶ if (!$class->_file_is_localhost($u_auth)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->_file_is_localhost($u_auth)) 5 0 5
54  
55 # some other host (use it as volume name)
56 5 @path = ("", $auth);
57  
58 # XXX or just return to make it illegal;
59 }
60 }
61 }
62 33 my @ps = split("/", $uri->path, -1);
63 33 ▶ shift @ps if @path;
Branch: 1 branch
BranchTrueFalseTotal
if @path 5 28 33
64 33 push(@path, @ps);
65  
66 33 my $pre = "";
67 33 ▶ if (!@path) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @path) { } 0 33 33
elsif ($path[0] eq '') { } 22 11 33
68 0 return; # empty path; XXX return ":" instead?
69 }
70 elsif ($path[0] eq "") {
71  
72 # absolute
73 22 shift(@path);
74 22 ▶ if (@path == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path == 1) 2 20 22
75 2 ▶ return if $path[0] eq ""; # not root directory
Branch: 1 branch
BranchTrueFalseTotal
if $path[0] eq "" 2 0 2
76 0 push(@path, ""); # volume only, effectively append ":"
77 }
78 20 @ps = @path;
79 20 @path = ();
80 20 my $part;
81 20 for (@ps) { #fix up "." and "..", including interior, in relatives
82 40 ▶ next if $_ eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." 0 40 40
83 40 ▶ $part = $_ eq ".." ? "" : $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '..' ? : 0 40 40
84 40 push(@path, $part);
85 }
86 20 ▶ if ($ps[-1] eq "..") { #if this happens, we need another :
Branch: 1 branch
BranchTrueFalseTotal
if ($ps[-1] eq "..") 0 20 20
87 0 push(@path, "");
88 }
89  
90 }
91 else {
92 11 $pre = ":";
93 11 @ps = @path;
94 11 @path = ();
95 11 my $part;
96 11 for (@ps) { #fix up "." and "..", including interior, in relatives
97 17 ▶ next if $_ eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." 2 15 17
98 15 ▶ $part = $_ eq ".." ? "" : $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '..' ? : 4 11 15
99 15 push(@path, $part);
100 }
101 11 ▶ if ($ps[-1] eq "..") { #if this happens, we need another :
Branch: 1 branch
BranchTrueFalseTotal
if ($ps[-1] eq "..") 2 9 11
102 2 push(@path, "");
103 }
104  
105 }
106 31 ▶ return unless $pre || @path;
Branch: 1 branch
BranchTrueFalseTotal
unless $pre or @path 0 31 31
Condition66%2/3
$pre or @path
l!l&&r!l&&!r
11200
MC/DC0%0/2
$pre or @path
$pre @path
Truth table66%2/3
A or B
A= $preB= @path
ABresult
1X1
011
000
107 31 for (@path) {
108 52 s/;.*//; # get rid of parameters
109 #return unless length; # XXX
110 52 $_ = uri_unescape($_);
111 52 ▶ return if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 0 52 52
112 52 ▶ return if /:/; # Should we?
Branch: 1 branch
BranchTrueFalseTotal
if /:/ 5 47 52
113 }
114 26 $pre . join(":", @path);
115 }
116  
117 0 ▶sub dir {
Subroutine dir: not called CC=3 SCAR=24.8
Pod undocumented
118 0 my $class = shift;
119 0 my $path = $class->file(@_);
120 0 ▶ return unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
121 0 ▶ $path .= ":" unless $path =~ /:$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /:$/ 0 0 0
122 0 $path;
123 }
124  
125 3 1;
« URI/Heuristic.pm ↑ Summary URI/file.pm »