| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package URI::file; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 221947 | use strict; | 
|  | 4 |  |  |  |  | 37 |  | 
|  | 4 |  |  |  |  | 113 |  | 
| 4 | 4 |  |  | 4 |  | 22 | use warnings; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 120 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 4 |  |  | 4 |  | 1352 | use parent 'URI::_generic'; | 
|  | 4 |  |  |  |  | 932 |  | 
|  | 4 |  |  |  |  | 20 |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '5.19'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 4 |  |  | 4 |  | 264 | use URI::Escape qw(uri_unescape); | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 416 |  | 
| 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 | 713 | my($OS) = shift || $^O; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 140 |  | 100 |  |  | 648 | my $class = "URI::file::" . ($OS_CLASS{$OS} || "Unix"); | 
| 31 | 4 |  |  | 4 |  | 27 | no strict 'refs'; | 
|  | 4 |  |  |  |  | 9 |  | 
|  | 4 |  |  |  |  | 2318 |  | 
| 32 | 140 | 100 |  |  |  | 210 | unless (%{"$class\::"}) { | 
|  | 140 |  |  |  |  | 789 |  | 
| 33 | 10 |  |  |  |  | 833 | eval "require $class"; | 
| 34 | 10 | 50 |  |  |  | 86 | die $@ if $@; | 
| 35 |  |  |  |  |  |  | } | 
| 36 | 140 |  |  |  |  | 749 | $class; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 2 |  |  | 2 | 1 | 16 | sub host { uri_unescape(shift->authority(@_)) } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub new | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 51 |  |  | 51 | 1 | 12772 | my($class, $path, $os) = @_; | 
| 44 | 51 |  |  |  |  | 242 | os_class($os)->new($path); | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub new_abs | 
| 48 |  |  |  |  |  |  | { | 
| 49 | 9 |  |  | 9 | 1 | 3188 | my $class = shift; | 
| 50 | 9 |  |  |  |  | 83 | my $file = $class->new(@_); | 
| 51 | 9 | 100 |  |  |  | 102 | return $file->abs($class->cwd) unless $$file =~ /^file:/; | 
| 52 | 4 |  |  |  |  | 31 | $file; | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub cwd | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 6 |  |  | 6 | 1 | 943 | my $class = shift; | 
| 58 | 6 |  |  |  |  | 44 | require Cwd; | 
| 59 | 6 |  |  |  |  | 22140 | my $cwd = Cwd::cwd(); | 
| 60 | 6 | 50 |  |  |  | 413 | $cwd = VMS::Filespec::unixpath($cwd) if $^O eq 'VMS'; | 
| 61 | 6 |  |  |  |  | 153 | $cwd = $class->new($cwd); | 
| 62 | 6 | 100 |  |  |  | 168 | $cwd .= "/" unless substr($cwd, -1, 1) eq "/"; | 
| 63 | 6 |  |  |  |  | 172 | $cwd; | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | sub canonical { | 
| 67 | 46 |  |  | 46 | 1 | 69 | my $self = shift; | 
| 68 | 46 |  |  |  |  | 125 | my $other = $self->SUPER::canonical; | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 46 |  |  |  |  | 124 | my $scheme = $other->scheme; | 
| 71 | 46 |  |  |  |  | 128 | my $auth = $other->authority; | 
| 72 | 46 | 50 | 66 |  |  | 128 | return $other if !defined($scheme) && !defined($auth);  # relative | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 40 | 50 | 66 |  |  | 157 | 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 |  |  | 130 | 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 |  |  |  |  | 96 | $other; | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub file | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 89 |  |  | 89 | 1 | 9774 | my($self, $os) = @_; | 
| 96 | 89 |  |  |  |  | 171 | 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__ |