URI/file/Base.pm

filter: Statementstmt 87.2% 41 / 47 Branchbran 77.2% 17 / 22 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 76.1% 67 / 88 CC 14 SCAR 16.9
CC
14
Cov
82%
new
9.2
_file_is_localhost
5.6
_file_extract_authority
2.0
CRAP 5.4
« URI/Escape.pm ↑ Summary URI/_emailauth.pm »
1 package URI::file::Base;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use URI::Escape ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '5.40';
9  
10 69 ▶sub new {
Subroutine new: called CC=9 SCAR=22.2
Pod undocumented
11 69 my $class = shift;
12 69 my $path = shift;
13 69 ▶ $path = "" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 2 67 69
14  
15 69 my ($auth, $escaped_auth, $escaped_path);
16  
17 69 ($auth, $escaped_auth) = $class->_file_extract_authority($path);
18 69 ($path, $escaped_path) = $class->_file_extract_path($path);
19  
20 69 ▶ if (defined $auth) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auth) { } 18 51 69
21 18 ▶ $auth =~ s,%,%25,g unless $escaped_auth;
Branch: 1 branch
BranchTrueFalseTotal
unless $escaped_auth 18 0 18
22 0 $auth =~ s,([/?\#\t\n\f\r\x0b ]), URI::Escape::escape_char($1),eg;
23 18 $auth = "//$auth";
24 18 ▶ if (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) { } 18 0 18
25 18 ▶ $path = "/$path" unless substr($path, 0, 1) eq "/";
Branch: 1 branch
BranchTrueFalseTotal
unless substr($path, 0, 1) eq "/" 1 17 18
26 }
27 else {
28 0 $path = "";
29 }
30 }
31 else {
32 51 ▶ return undef unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 51 51
33 51 $auth = "";
34 }
35  
36 69 ▶ $path =~ s,([%;?\t\n\f\r\x0b ]), URI::Escape::escape_char($1),eg
Branch: 1 branch
BranchTrueFalseTotal
unless $escaped_path 51 18 69
37 unless $escaped_path;
38 69 $path =~ s/\#/%23/g;
39  
40 69 my $uri = $auth . $path;
41 69 ▶ $uri = "file:$uri" if substr($uri, 0, 1) eq "/";
Branch: 1 branch
BranchTrueFalseTotal
if substr($uri, 0, 1) eq "/" 36 33 69
42  
43 69 URI->new($uri, "file");
44 }
45  
46 62 ▶sub _file_extract_authority {
Subroutine _file_extract_authority: called CC=2 SCAR=6.9
47 62 my ($class, $path) = @_;
48 62 ▶ return undef unless $class->_file_is_absolute($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_file_is_absolute($path) 38 24 62
49 24 return $URI::file::DEFAULT_AUTHORITY;
50 }
51  
52 0 ▶sub _file_extract_path {
Subroutine _file_extract_path: not called CC=1 SCAR=6.9
53 0 return undef;
54 }
55  
56 18 ▶sub _file_is_absolute {
Subroutine _file_is_absolute: called CC=1 SCAR=0.0
57 18 return 0;
58 }
59  
60 10 ▶sub _file_is_localhost {
Subroutine _file_is_localhost: called CC=5 SCAR=17.2
61 10 shift; # class
62 10 my $host = lc(shift);
63 10 ▶ return 1 if $host eq "localhost";
Branch: 1 branch
BranchTrueFalseTotal
if $host eq "localhost" 0 10 10
64 10 eval {
65 10 require Net::Domain;
66 10 ▶ lc(Net::Domain::hostfqdn() || '') eq $host
Branch: 1 branch
BranchTrueFalseTotal
lc(Net::Domain::hostfqdn() || "") eq $host or lc(Net::Domain::hostname() || "") eq $host 0 10 10
Condition50%2/4
Net::Domain::hostfqdn() || ''
l!l
100
Net::Domain::hostname() || ''
l!l
100
MC/DC0%0/1
Net::Domain::hostfqdn() || ''
Net::Domain::hostfqdn()
MC/DC0%0/1
Net::Domain::hostname() || ''
Net::Domain::hostname()
Truth table50%1/2
A
A= Net::Domain::hostfqdn()
Aresult
11
00
Truth table50%1/2
A
A= Net::Domain::hostname()
Aresult
11
00
67 || lc(Net::Domain::hostname() || '') eq $host;
68 };
69 }
70  
71 0 ▶sub file {
Subroutine file: not called CC=1 SCAR=6.9
Pod undocumented
72 0 undef;
73 }
74  
75 0 ▶sub dir {
Subroutine dir: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my $self = shift;
77 0 $self->file(@_);
78 }
79  
80 4 1;
« URI/Escape.pm ↑ Summary URI/_emailauth.pm »