File Coverage

inc/Path/Class/Entity.pm
Criterion Covered Total %
statement 19 47 40.4
branch 2 12 16.6
condition n/a
subroutine 7 19 36.8
pod 0 12 0.0
total 28 90 31.1


line stmt bran cond sub pod time code
1             #line 1
2             package Path::Class::Entity;
3              
4             $VERSION = '0.17';
5 1     1   5  
  1         2  
  1         25  
6 1     1   5 use strict;
  1         1  
  1         15  
7 1     1   891 use File::Spec;
  1         17790  
  1         78  
8 1     1   11 use File::stat ();
  1         1  
  1         92  
9             use Cwd;
10              
11             use overload
12 1         15 (
13             q[""] => 'stringify',
14             'bool' => 'boolify',
15 1     1   6 fallback => 1,
  1         2  
16             );
17              
18 2     2 0 6 sub new {
19 2 50       11 my $from = shift;
20             my ($class, $fs_class) = (ref($from)
21             ? (ref $from, $from->{file_spec_class})
22 2         16 : ($from, $Path::Class::Foreign));
23             return bless {file_spec_class => $fs_class}, $class;
24             }
25 0     0 0 0  
26             sub is_dir { 0 }
27              
28 0     0   0 sub _spec_class {
29             my ($class, $type) = @_;
30 0 0       0  
31 0         0 die "Invalid system type '$type'" unless ($type) = $type =~ /^(\w+)$/; # Untaint
32 0 0       0 my $spec = "File::Spec::$type";
33 0         0 eval "require $spec; 1" or die $@;
34             return $spec;
35             }
36              
37 0     0 0 0 sub new_foreign {
38 0         0 my ($class, $type) = (shift, shift);
39 0         0 local $Path::Class::Foreign = $class->_spec_class($type);
40             return $class->new(@_);
41             }
42 4 50   4   128  
43             sub _spec { $_[0]->{file_spec_class} || 'File::Spec' }
44 0     0 0    
45             sub boolify { 1 }
46            
47             sub is_absolute {
48             # 5.6.0 has a bug with regexes and stringification that's ticked by
49 0     0 0   # file_name_is_absolute(). Help it along with an explicit stringify().
50             $_[0]->_spec->file_name_is_absolute($_[0]->stringify)
51             }
52 0     0 0    
53             sub is_relative { ! $_[0]->is_absolute }
54              
55 0     0 0   sub cleanup {
56 0           my $self = shift;
57 0           my $cleaned = $self->new( $self->_spec->canonpath($self) );
58 0           %$self = %$cleaned;
59             return $self;
60             }
61              
62 0     0 0   sub resolve {
63 0           my $self = shift;
64             my $cleaned = $self->new( Cwd::realpath($self->stringify) );
65              
66 0 0         # realpath() always returns absolute path, kind of annoying
67             $cleaned = $cleaned->relative if $self->is_relative;
68 0            
69 0           %$self = %$cleaned;
70             return $self;
71             }
72              
73 0     0 0   sub absolute {
74 0 0         my $self = shift;
75 0           return $self if $self->is_absolute;
76             return $self->new($self->_spec->rel2abs($self->stringify, @_));
77             }
78              
79 0     0 0   sub relative {
80 0           my $self = shift;
81             return $self->new($self->_spec->abs2rel($self->stringify, @_));
82             }
83 0     0 0    
84 0     0 0   sub stat { File::stat::stat("$_[0]") }
85             sub lstat { File::stat::lstat("$_[0]") }
86              
87             1;