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   48 use strict;
  4         21  
  4         222  
4 4     4   114 use warnings;
  4         10  
  4         255  
5              
6 4     4   33 use parent 'URI::file::Base';
  4         9  
  4         67  
7              
8 4     4   322 use URI::Escape qw(uri_unescape);
  4         10  
  4         2297  
9              
10             our $VERSION = '5.21';
11              
12             sub _file_extract_path
13             {
14 26     26   149 my($class, $path) = @_;
15              
16             # tidy path
17 26         77 $path =~ s,//+,/,g;
18 26         50 $path =~ s,(/\.)+/,/,g;
19 26 50       166 $path = "./$path" if $path =~ m,^[^:/]+:,,; # look like "scheme:"
20              
21 26         104 return $path;
22             }
23              
24             sub _file_is_absolute {
25 26     26   90 my($class, $path) = @_;
26 26         300 return $path =~ m,^/,;
27             }
28              
29             sub file
30             {
31 36     36 0 57 my $class = shift;
32 36         49 my $uri = shift;
33 36         48 my @path;
34              
35 36         86 my $auth = $uri->authority;
36 36 100       83 if (defined($auth)) {
37 13 100 100     58 if (lc($auth) ne "localhost" && $auth ne "") {
38 5         16 $auth = uri_unescape($auth);
39 5 50       22 unless ($class->_file_is_localhost($auth)) {
40 5         15068 push(@path, "", "", $auth);
41             }
42             }
43             }
44              
45 36         105 my @ps = $uri->path_segments;
46 36 100       90 shift @ps if @path;
47 36         98 push(@path, @ps);
48              
49 36         70 for (@path) {
50             # Unix file/directory names are not allowed to contain '\0' or '/'
51 98 50       185 return undef if /\0/;
52 98 50       185 return undef if /\//; # should we really?
53             }
54              
55 36         311 return join("/", @path);
56             }
57              
58             1;