File Coverage

blib/lib/URI/file/Win32.pm
Criterion Covered Total %
statement 52 52 100.0
branch 25 30 83.3
condition 3 3 100.0
subroutine 9 9 100.0
pod 0 2 0.0
total 89 96 92.7


line stmt bran cond sub pod time code
1             package URI::file::Win32;
2              
3 3     3   515 use strict;
  3         7  
  3         108  
4 3     3   18 use warnings;
  3         6  
  3         83  
5              
6 3     3   16 use parent 'URI::file::Base';
  3         6  
  3         34  
7              
8 3     3   214 use URI::Escape qw(uri_unescape);
  3         6  
  3         2568  
9              
10             our $VERSION = '5.20';
11              
12             sub _file_extract_authority
13             {
14 13     13   19 my $class = shift;
15              
16 13 100       35 return $class->SUPER::_file_extract_authority($_[0])
17             if defined $URI::file::DEFAULT_AUTHORITY;
18              
19 7 100       22 return $1 if $_[0] =~ s,^\\\\([^\\]+),,; # UNC
20 6 50       11 return $1 if $_[0] =~ s,^//([^/]+),,; # UNC too?
21              
22 6 100       15 if ($_[0] =~ s,^([a-zA-Z]:),,) {
23 1         3 my $auth = $1;
24 1 50       4 $auth .= "relative" if $_[0] !~ m,^[\\/],;
25 1         3 return $auth;
26             }
27 5         11 return undef;
28             }
29              
30             sub _file_extract_path
31             {
32 13     13   25 my($class, $path) = @_;
33 13         35 $path =~ s,\\,/,g;
34             #$path =~ s,//+,/,g;
35 13         20 $path =~ s,(/\.)+/,/,g;
36              
37 13 100       25 if (defined $URI::file::DEFAULT_AUTHORITY) {
38 6         13 $path =~ s,^([a-zA-Z]:),/$1,;
39             }
40              
41 13         33 return $path;
42             }
43              
44             sub _file_is_absolute {
45 6     6   11 my($class, $path) = @_;
46 6   100     51 return $path =~ m,^[a-zA-Z]:, || $path =~ m,^[/\\],;
47             }
48              
49             sub file
50             {
51 26     26 0 65 my $class = shift;
52 26         36 my $uri = shift;
53 26         62 my $auth = $uri->authority;
54 26         38 my $rel; # is filename relative to drive specified in authority
55 26 100       61 if (defined $auth) {
56 11         27 $auth = uri_unescape($auth);
57 11 100       48 if ($auth =~ /^([a-zA-Z])[:|](relative)?/) {
    100          
    100          
58 3         9 $auth = uc($1) . ":";
59 3 100       11 $rel++ if $2;
60             } elsif (lc($auth) eq "localhost") {
61 2         4 $auth = "";
62             } elsif (length $auth) {
63 2         7 $auth = "\\\\" . $auth; # UNC
64             }
65             } else {
66 15         27 $auth = "";
67             }
68              
69 26         72 my @path = $uri->path_segments;
70 26         71 for (@path) {
71 55 50       129 return undef if /\0/;
72 55 50       117 return undef if /\//;
73             #return undef if /\\/; # URLs with "\" is not uncommon
74             }
75 26 50       58 return undef unless $class->fix_path(@path);
76              
77 26         61 my $path = join("\\", @path);
78 26 100       53 $path =~ s/^\\// if $rel;
79 26         44 $path = $auth . $path;
80 26         68 $path =~ s,^\\([a-zA-Z])[:|],\u$1:,;
81              
82 26         86 return $path;
83             }
84              
85 24     24 0 51 sub fix_path { 1; }
86              
87             1;