| 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
| |||||||||||||||||||||||||||||
| 18 | 10 | ▶ | if (length($1) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | @pre = (".") unless length($path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$_ eq "." or $_ eq ".."
MC/DC100%2/2
$_ eq "." or $_ eq ".."
$_ eq "."
$_ eq ".."
Truth table100%3/3
A or B
A= $_ eq "."B= $_ eq ".."
| |||||||||||||||||||||||||||||
| 35 | 4 | $_ = "%2E" x length($_); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 24 | ▶ | $_ = ".." unless length($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 18 | ▶ | push(@path, "") if $isdir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | 11 | ▶ | if (lc($auth) ne "localhost" && $auth ne "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
lc $auth ne "localhost" and $auth ne ""
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 ""
| |||||||||||||||||||||||||||||
| 52 | 5 | my $u_auth = uri_unescape($auth); | |||||||||||||||||||||||||||
| 53 | 5 | ▶ | if (!$class->_file_is_localhost($u_auth)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 64 | 33 | push(@path, @ps); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 33 | my $pre = ""; | |||||||||||||||||||||||||||
| 67 | 33 | ▶ | if (!@path) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | return if $path[0] eq ""; # not root directory | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | 40 | ▶ | $part = $_ eq ".." ? "" : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 40 | push(@path, $part); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 20 | ▶ | if ($ps[-1] eq "..") { #if this happens, we need another : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 98 | 15 | ▶ | $part = $_ eq ".." ? "" : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 15 | push(@path, $part); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 11 | ▶ | if ($ps[-1] eq "..") { #if this happens, we need another : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 2 | push(@path, ""); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 31 | ▶ | return unless $pre || @path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pre or @path
MC/DC0%0/2
$pre or @path
$pre
@path
Truth table66%2/3
A or B
A= $preB= @path
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 112 | 52 | ▶ | return if /:/; # Should we? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | $path .= ":" unless $path =~ /:$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | $path; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 3 | 1; | |||||||||||||||||||||||||||