File Coverage

blib/lib/URI/file/Base.pm
Criterion Covered Total %
statement 38 45 84.4
branch 17 22 77.2
condition 2 4 50.0
subroutine 7 10 70.0
pod 0 3 0.0
total 64 84 76.1


line stmt bran cond sub pod time code
1             package URI::file::Base;
2              
3 4     4   1751 use strict;
  4         10  
  4         121  
4 4     4   17 use warnings;
  4         6  
  4         213  
5              
6 4     4   18 use URI::Escape ();
  4         5  
  4         2289  
7              
8             our $VERSION = '5.35';
9              
10             sub new
11             {
12 51     51 0 67 my $class = shift;
13 51         126 my $path = shift;
14 51 100       105 $path = "" unless defined $path;
15              
16 51         146 my($auth, $escaped_auth, $escaped_path);
17              
18 51         198 ($auth, $escaped_auth) = $class->_file_extract_authority($path);
19 51         155 ($path, $escaped_path) = $class->_file_extract_path($path);
20              
21 51 100       119 if (defined $auth) {
22 12 50       32 $auth =~ s,%,%25,g unless $escaped_auth;
23 12         16 $auth =~ s,([/?\#]), URI::Escape::escape_char($1),eg;
  0         0  
24 12         22 $auth = "//$auth";
25 12 50       22 if (defined $path) {
26 12 100       44 $path = "/$path" unless substr($path, 0, 1) eq "/";
27             } else {
28 0         0 $path = "";
29             }
30             } else {
31 39 50       105 return undef unless defined $path;
32 39         77 $auth = "";
33             }
34              
35 51 100       151 $path =~ s,([%;?]), URI::Escape::escape_char($1),eg unless $escaped_path;
  0         0  
36 51         101 $path =~ s/\#/%23/g;
37              
38 51         73 my $uri = $auth . $path;
39 51 100       150 $uri = "file:$uri" if substr($uri, 0, 1) eq "/";
40              
41 51         230 URI->new($uri, "file");
42             }
43              
44             sub _file_extract_authority
45             {
46 44     44   82 my($class, $path) = @_;
47 44 100       147 return undef unless $class->_file_is_absolute($path);
48 18         57 return $URI::file::DEFAULT_AUTHORITY;
49             }
50              
51             sub _file_extract_path
52             {
53 0     0   0 return undef;
54             }
55              
56             sub _file_is_absolute
57             {
58 12     12   36 return 0;
59             }
60              
61             sub _file_is_localhost
62             {
63 10     10   12 shift; # class
64 10         15 my $host = lc(shift);
65 10 50       20 return 1 if $host eq "localhost";
66 10         11 eval {
67 10         1172 require Net::Domain;
68 10 50 50     15875 lc(Net::Domain::hostfqdn() || '') eq $host ||
      50        
69             lc(Net::Domain::hostname() || '') eq $host;
70             };
71             }
72              
73             sub file
74             {
75 0     0 0   undef;
76             }
77              
78             sub dir
79             {
80 0     0 0   my $self = shift;
81 0           $self->file(@_);
82             }
83              
84             1;