URI/file/Mac.pm

filter: Statementstmt 89.0% 73 / 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 81.4% 127 / 156 CC 33 SCAR 28.7
CC
33
Cov
83%
file
24.5
dir
12.0
_file_extract_path
9.1
CRAP 17.6
« 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.37';
11  
12 12 ▶sub _file_extract_path {
Subroutine _file_extract_path: called CC=9 SCAR=22.0
13 12 shift; # $class
14 12 my $path = shift;
15  
16 12 my @pre;
17 12 ▶ if ($path =~ s/^(:+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s/^(:+)//) { } 10 2 12
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 2 $pre[0] = "";
27 }
28  
29 12 my $isdir = ($path =~ s/:$//);
30 12 $path =~ s,([%/;]), URI::Escape::escape_char($1),eg;
31  
32 12 my @path = split(/:/, $path, -1);
33 12 for (@path) {
34 12 ▶ if ($_ eq "." || $_ eq "..") {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "." or $_ eq "..") 4 8 12
Condition100%3/3
$_ eq "." or $_ eq ".."
l!l&&r!l&&!r
228
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 12 ▶ $_ = ".." unless length($_);
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 12 12
38 }
39 12 ▶ push(@path, "") if $isdir;
Branch: 1 branch
BranchTrueFalseTotal
if $isdir 0 12 12
40 12 (join("/", @pre, @path), 1);
41 }
42  
43  
44 27 ▶sub file {
Subroutine file: called CC=23 SCAR=32.0
Pod undocumented
45 27 my $class = shift;
46 27 my $uri = shift;
47 27 my @path;
48  
49 27 my $auth = $uri->authority;
50 27 ▶ if (defined $auth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auth) 11 16 27
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 27 my @ps = split("/", $uri->path, -1);
63 27 ▶ shift @ps if @path;
Branch: 1 branch
BranchTrueFalseTotal
if @path 5 22 27
64 27 push(@path, @ps);
65  
66 27 my $pre = "";
67 27 ▶ if (!@path) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @path) { } 0 27 27
elsif ($path[0] eq '') { } 16 11 27
68 0 return; # empty path; XXX return ":" instead?
69 }
70 elsif ($path[0] eq "") {
71  
72 # absolute
73 16 shift(@path);
74 16 ▶ if (@path == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path == 1) 2 14 16
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 14 @ps = @path;
79 14 @path = ();
80 14 my $part;
81 14 for (@ps) { #fix up "." and "..", including interior, in relatives
82 28 ▶ next if $_ eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." 0 28 28
83 28 ▶ $part = $_ eq ".." ? "" : $_;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '..' ? : 0 28 28
84 28 push(@path, $part);
85 }
86 14 ▶ if ($ps[-1] eq "..") { #if this happens, we need another :
Branch: 1 branch
BranchTrueFalseTotal
if ($ps[-1] eq "..") 0 14 14
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 25 ▶ return unless $pre || @path;
Branch: 1 branch
BranchTrueFalseTotal
unless $pre or @path 0 25 25
Condition66%2/3
$pre or @path
l!l&&r!l&&!r
11140
MC/DC0%0/2
$pre or @path
$pre @path
Truth table66%2/3
A or B
A= $preB= @path
ABresult
1X1
011
000
107 25 for (@path) {
108 40 s/;.*//; # get rid of parameters
109 #return unless length; # XXX
110 40 $_ = uri_unescape($_);
111 40 ▶ return if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 0 40 40
112 40 ▶ return if /:/; # Should we?
Branch: 1 branch
BranchTrueFalseTotal
if /:/ 5 35 40
113 }
114 20 $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 »