URI/file/Win32.pm

filter: Statementstmt 100% 54 / 54 Branchbran 83.3% 25 / 30 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 93.0% 93 / 100 CC 18 SCAR 18.8
CC
18
Cov
94%
file
11.1
_file_extract_authority
6.0
_file_extract_path
2.0
CRAP 6.6
« URI/data.pm ↑ Summary URI/_userpass.pm »
1 package URI::file::Win32;
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 13 ▶sub _file_extract_authority {
Subroutine _file_extract_authority: called CC=6 SCAR=18.0
13 13 my $class = shift;
14  
15 13 ▶ return $class->SUPER::_file_extract_authority($_[0])
Branch: 1 branch
BranchTrueFalseTotal
if defined $URI::file::DEFAULT_AUTHORITY 6 7 13
16 if defined $URI::file::DEFAULT_AUTHORITY;
17  
18 7 ▶ return $1 if $_[0] =~ s,^\\\\([^\\]+),,; # UNC
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ s/^\\\\([^\\]+)// 1 6 7
19 6 ▶ return $1 if $_[0] =~ s,^//([^/]+),,; # UNC too?
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ s[^//([^/]+)][] 0 6 6
20  
21 6 ▶ if ($_[0] =~ s,^([a-zA-Z]:),,) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ s/^([a-zA-Z]:)//) 1 5 6
22 1 my $auth = $1;
23 1 ▶ $auth .= "relative" if $_[0] !~ m,^[\\/],;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ m[^[\\/]] 1 0 1
24 1 return $auth;
25 }
26 5 return undef;
27 }
28  
29 13 ▶sub _file_extract_path {
Subroutine _file_extract_path: called CC=2 SCAR=6.9
30 13 my ($class, $path) = @_;
31 13 $path =~ s,\\,/,g;
32  
33 #$path =~ s,//+,/,g;
34 13 $path =~ s,(/\.)+/,/,g;
35  
36 13 ▶ if (defined $URI::file::DEFAULT_AUTHORITY) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $URI::file::DEFAULT_AUTHORITY) 6 7 13
37 6 $path =~ s,^([a-zA-Z]:),/$1,;
38 }
39  
40 13 return $path;
41 }
42  
43 6 ▶sub _file_is_absolute {
Subroutine _file_is_absolute: called CC=2 SCAR=6.9
44 6 my ($class, $path) = @_;
45 6 ▶ return $path =~ m,^[a-zA-Z]:, || $path =~ m,^[/\\],;
Condition100%3/3
$path =~ /^[a-zA-Z]:/ || $path =~ m(^[/\\])
l!l&&r!l&&!r
123
MC/DC100%2/2
$path =~ /^[a-zA-Z]:/ || $path =~ m(^[/\\])
$path =~ /^[a-zA-Z]:/ $path =~ m(^[/\\])
Truth table100%3/3
A || B
A= $path =~ /^[a-zA-Z]:/B= $path =~ m(^[/\\])
ABresult
1X1
011
000
46 }
47  
48 26 ▶sub file {
Subroutine file: called CC=11 SCAR=24.0
Pod undocumented
49 26 my $class = shift;
50 26 my $uri = shift;
51 26 my $auth = $uri->authority;
52 26 my $rel; # is filename relative to drive specified in authority
53 26 ▶ if (defined $auth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auth) { } 11 15 26
54 11 $auth = uri_unescape($auth);
55 11 ▶ if ($auth =~ /^([a-zA-Z])[:|](relative)?/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($auth =~ /^([a-zA-Z])[:|](relative)?/) { } 3 8 11
elsif (lc $auth eq 'localhost') { } 2 6 8
elsif (length $auth) { } 2 4 6
56 3 $auth = uc($1) . ":";
57 3 ▶ $rel++ if $2;
Branch: 1 branch
BranchTrueFalseTotal
if $2 1 2 3
58 }
59 elsif (lc($auth) eq "localhost") {
60 2 $auth = "";
61 }
62 elsif (length $auth) {
63 2 $auth = "\\\\" . $auth; # UNC
64 }
65 }
66 else {
67 15 $auth = "";
68 }
69  
70 26 my @path = $uri->path_segments;
71 26 for (@path) {
72 55 ▶ return undef if /\0/;
Branch: 1 branch
BranchTrueFalseTotal
if /\0/ 0 55 55
73 55 ▶ return undef if /\//;
Branch: 1 branch
BranchTrueFalseTotal
if m[/] 0 55 55
74  
75 #return undef if /\\/; # URLs with "\" is not uncommon
76 }
77 26 ▶ return undef unless $class->fix_path(@path);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->fix_path(@path) 0 26 26
78  
79 26 my $path = join("\\", @path);
80 26 ▶ $path =~ s/^\\// if $rel;
Branch: 1 branch
BranchTrueFalseTotal
if $rel 1 25 26
81 26 $path = $auth . $path;
82 26 $path =~ s,^\\([a-zA-Z])[:|],\u$1:,;
83  
84 26 return $path;
85 }
86  
87 24 ▶sub fix_path { 1; }
Subroutine fix_path: called CC=1 SCAR=0.0
Pod undocumented
88  
89 3 1;
« URI/data.pm ↑ Summary URI/_userpass.pm »