File Coverage

blib/lib/Path/Class/URI.pm
Criterion Covered Total %
statement 38 38 100.0
branch 6 8 75.0
condition n/a
subroutine 12 12 100.0
pod 2 4 50.0
total 58 62 93.5


line stmt bran cond sub pod time code
1             package Path::Class::URI;
2              
3 4     4   430767 use strict;
  4         8  
  4         401  
4 4     4   120 use 5.008_001;
  4         13  
  4         244  
5             our $VERSION = '0.07';
6              
7 4     4   4837 use URI;
  4         23720  
  4         157  
8 4     4   3995 use URI::file;
  4         24667  
  4         159  
9 4     4   2880 use Exporter::Lite;
  4         2932  
  4         33  
10 4     4   820 use Path::Class;
  4         38704  
  4         261  
11 4     4   26 use Scalar::Util qw(blessed);
  4         7  
  4         231  
12 4     4   22 use URI::Escape;
  4         5  
  4         1995  
13              
14             our @EXPORT = qw( file_from_uri dir_from_uri );
15              
16             sub file_from_uri {
17 7     7 1 2880 Path::Class::File->from_uri(shift);
18             }
19              
20             sub dir_from_uri {
21 3     3 1 220 Path::Class::Dir->from_uri(shift);
22             }
23              
24             sub Path::Class::Entity::uri {
25 12     12 0 80668 my $self = shift;
26 12         110 my $escaped_self = $self->new( map { uri_escape($_) } $self->components );
  45         810  
27             # escape the components so that URI can see them as path segments
28 12         1121 my $path = $escaped_self->stringify;
29 12 50       458 $path =~ tr!\\!/! if $^O eq "MSWin32";
30 12 100       120 $path .= '/' if $self->isa('Path::Class::Dir'); # preserve directory if used as base URI
31 12 100       65 if ($self->is_absolute) {
32 10         406 return URI->new("file://$path");
33             } else {
34 2         88 return URI->new("file:$path");
35             }
36             }
37              
38             sub Path::Class::Entity::from_uri {
39 10     10 0 27 my($class, $uri) = @_;
40 10 50       94 $uri = URI->new($uri) unless blessed $uri;;
41 10         53 $class->new( $uri->file('unix') );
42             }
43              
44             1;
45             __END__