File Coverage

blib/lib/URI/file.pm
Criterion Covered Total %
statement 46 50 92.0
branch 10 18 55.5
condition 14 29 48.2
subroutine 12 13 92.3
pod 7 8 87.5
total 89 118 75.4


line stmt bran cond sub pod time code
1             package URI::file;
2              
3 4     4   228290 use strict;
  4         37  
  4         126  
4 4     4   19 use warnings;
  4         9  
  4         127  
5              
6 4     4   1360 use parent 'URI::_generic';
  4         1009  
  4         20  
7             our $VERSION = '5.20';
8              
9 4     4   260 use URI::Escape qw(uri_unescape);
  4         8  
  4         435  
10              
11             our $DEFAULT_AUTHORITY = "";
12              
13             # Map from $^O values to implementation classes. The Unix
14             # class is the default.
15             our %OS_CLASS = (
16             os2 => "OS2",
17             mac => "Mac",
18             MacOS => "Mac",
19             MSWin32 => "Win32",
20             win32 => "Win32",
21             msdos => "FAT",
22             dos => "FAT",
23             qnx => "QNX",
24             );
25              
26             sub os_class
27             {
28 140   66 140 0 563 my($OS) = shift || $^O;
29              
30 140   100     634 my $class = "URI::file::" . ($OS_CLASS{$OS} || "Unix");
31 4     4   27 no strict 'refs';
  4         8  
  4         2350  
32 140 100       229 unless (%{"$class\::"}) {
  140         738  
33 10         864 eval "require $class";
34 10 50       61 die $@ if $@;
35             }
36 140         667 $class;
37             }
38              
39 2     2 1 7 sub host { uri_unescape(shift->authority(@_)) }
40              
41             sub new
42             {
43 51     51 1 10841 my($class, $path, $os) = @_;
44 51         215 os_class($os)->new($path);
45             }
46              
47             sub new_abs
48             {
49 9     9 1 2624 my $class = shift;
50 9         64 my $file = $class->new(@_);
51 9 100       70 return $file->abs($class->cwd) unless $$file =~ /^file:/;
52 4         31 $file;
53             }
54              
55             sub cwd
56             {
57 6     6 1 1262 my $class = shift;
58 6         39 require Cwd;
59 6         18578 my $cwd = Cwd::cwd();
60 6 50       347 $cwd = VMS::Filespec::unixpath($cwd) if $^O eq 'VMS';
61 6         146 $cwd = $class->new($cwd);
62 6 100       156 $cwd .= "/" unless substr($cwd, -1, 1) eq "/";
63 6         156 $cwd;
64             }
65              
66             sub canonical {
67 46     46 1 70 my $self = shift;
68 46         132 my $other = $self->SUPER::canonical;
69              
70 46         112 my $scheme = $other->scheme;
71 46         137 my $auth = $other->authority;
72 46 50 66     132 return $other if !defined($scheme) && !defined($auth); # relative
73              
74 40 50 66     151 if (!defined($auth) ||
      66        
      33        
      33        
75             $auth eq "" ||
76             lc($auth) eq "localhost" ||
77             (defined($DEFAULT_AUTHORITY) && lc($auth) eq lc($DEFAULT_AUTHORITY))
78             )
79             {
80             # avoid cloning if $auth already match
81 36 0 33     172 if ((defined($auth) || defined($DEFAULT_AUTHORITY)) &&
      0        
      33        
82             (!defined($auth) || !defined($DEFAULT_AUTHORITY) || $auth ne $DEFAULT_AUTHORITY)
83             )
84             {
85 0 0       0 $other = $other->clone if $self == $other;
86 0         0 $other->authority($DEFAULT_AUTHORITY);
87             }
88             }
89              
90 40         103 $other;
91             }
92              
93             sub file
94             {
95 89     89 1 7688 my($self, $os) = @_;
96 89         169 os_class($os)->file($self);
97             }
98              
99             sub dir
100             {
101 0     0 1   my($self, $os) = @_;
102 0           os_class($os)->dir($self);
103             }
104              
105             1;
106              
107             __END__