File Coverage

blib/lib/URI/file/Unix.pm
Criterion Covered Total %
statement 35 35 100.0
branch 10 14 71.4
condition 3 3 100.0
subroutine 7 7 100.0
pod 0 1 0.0
total 55 60 91.6


line stmt bran cond sub pod time code
1             package URI::file::Unix;
2              
3 4     4   45 use strict;
  4         18  
  4         214  
4 4     4   83 use warnings;
  4         8  
  4         244  
5              
6 4     4   31 use parent 'URI::file::Base';
  4         24  
  4         46  
7              
8 4     4   268 use URI::Escape qw(uri_unescape);
  4         10  
  4         1951  
9              
10             our $VERSION = '5.19';
11              
12             sub _file_extract_path
13             {
14 26     26   172 my($class, $path) = @_;
15              
16             # tidy path
17 26         98 $path =~ s,//+,/,g;
18 26         69 $path =~ s,(/\.)+/,/,g;
19 26 50       91 $path = "./$path" if $path =~ m,^[^:/]+:,,; # look like "scheme:"
20              
21 26         85 return $path;
22             }
23              
24             sub _file_is_absolute {
25 26     26   118 my($class, $path) = @_;
26 26         337 return $path =~ m,^/,;
27             }
28              
29             sub file
30             {
31 36     36 0 49 my $class = shift;
32 36         50 my $uri = shift;
33 36         53 my @path;
34              
35 36         89 my $auth = $uri->authority;
36 36 100       82 if (defined($auth)) {
37 13 100 100     67 if (lc($auth) ne "localhost" && $auth ne "") {
38 5         15 $auth = uri_unescape($auth);
39 5 50       23 unless ($class->_file_is_localhost($auth)) {
40 5         14954 push(@path, "", "", $auth);
41             }
42             }
43             }
44              
45 36         133 my @ps = $uri->path_segments;
46 36 100       99 shift @ps if @path;
47 36         86 push(@path, @ps);
48              
49 36         68 for (@path) {
50             # Unix file/directory names are not allowed to contain '\0' or '/'
51 98 50       198 return undef if /\0/;
52 98 50       187 return undef if /\//; # should we really?
53             }
54              
55 36         321 return join("/", @path);
56             }
57              
58             1;