Class/Entity.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 78.5% 11 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 13 totaltotal 83.3% 90 / 108 CC 9 SCAR 5.9
CC
9
Cov
94%
_spec_class
3.1
resolve
3.0
_spec
3.0
CRAP 1.8
« Class/Dir.pm ↑ Summary Class.pm »
1 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Path::Class::Entity;
4 {
5 7 $Path::Class::Entity::VERSION = '0.37';
6 }
7  
8 7 ▶use File::Spec 3.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use File::stat ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 use overload
14 7 ▶ (
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 q[""] => 'stringify',
16 'bool' => 'boolify',
17 fallback => 1,
18 7 );
19  
20 715 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
21 715 my $from = shift;
22 my ($class, $fs_class) = (ref($from)
23 ? (ref $from, $from->{file_spec_class})
24 715 ▶ : ($from, $Path::Class::Foreign));
Branch: 1 branch
BranchTrueFalseTotal
ref $from ? : 335 380 715
25 715 return bless {file_spec_class => $fs_class}, $class;
26 }
27  
28 27 ▶sub is_dir { 0 }
Subroutine is_dir: called CC=1 SCAR=0.0
Pod undocumented
29  
30 73 ▶sub _spec_class {
Subroutine _spec_class: called CC=3 SCAR=11.3
31 73 my ($class, $type) = @_;
32  
33 73 ▶ die "Invalid system type '$type'" unless ($type) = $type =~ /^(\w+)$/; # Untaint
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) = $type =~ /^(\w+)$/ 0 73 73
34 73 my $spec = "File::Spec::$type";
35 ## no critic
36 73 ▶ eval "require $spec; 1" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $spec; 1" or die $@ 73 0 73
37 73 return $spec;
38 }
39  
40 14 ▶sub new_foreign {
Subroutine new_foreign: called CC=1 SCAR=0.0
Pod undocumented
41 14 my ($class, $type) = (shift, shift);
42 14 local $Path::Class::Foreign = $class->_spec_class($type);
43 14 return $class->new(@_);
44 }
45  
46 2252 ▶sub _spec { (ref($_[0]) && $_[0]->{file_spec_class}) || 'File::Spec' }
Subroutine _spec: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] and $_[0]{"file_spec_class"} or "File::Spec" 189 2063 2252
Condition100%3/3
ref $_[0] and $_[0]{"file_spec_class"}
!ll&&!rl&&r
142049189
MC/DC100%2/2
ref $_[0] and $_[0]{"file_spec_class"}
ref $_[0] $_[0]{"file_spec_class"}
Truth table100%3/3
A and B
A= ref $_[0]B= $_[0]{"file_spec_class"}
ABresult
0X0
100
111
47  
48 14 ▶sub boolify { 1 }
Subroutine boolify: called CC=1 SCAR=0.0
Pod undocumented
49
50 120 ▶sub is_absolute {
Subroutine is_absolute: called CC=1 SCAR=0.0
Pod undocumented
51 # 5.6.0 has a bug with regexes and stringification that's ticked by
52 # file_name_is_absolute(). Help it along with an explicit stringify().
53 120 $_[0]->_spec->file_name_is_absolute($_[0]->stringify)
54 }
55  
56 24 ▶sub is_relative { ! $_[0]->is_absolute }
Subroutine is_relative: called CC=1 SCAR=0.0
Pod undocumented
57  
58 53 ▶sub cleanup {
Subroutine cleanup: called CC=1 SCAR=0.0
Pod undocumented
59 53 my $self = shift;
60 53 my $cleaned = $self->new( $self->_spec->canonpath("$self") );
61 53 %$self = %$cleaned;
62 53 return $self;
63 }
64  
65 23 ▶sub resolve {
Subroutine resolve: called CC=3 SCAR=11.0
Pod undocumented
66 23 my $self = shift;
67 23 ▶ Carp::croak($! . " $self") unless -e $self; # No such file or directory
Branch: 1 branch
BranchTrueFalseTotal
unless -e $self 0 23 23
68 23 my $cleaned = $self->new( scalar Cwd::realpath($self->stringify) );
69  
70 # realpath() always returns absolute path, kind of annoying
71 23 ▶ $cleaned = $cleaned->relative if $self->is_relative;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_relative 21 2 23
72  
73 23 %$self = %$cleaned;
74 23 return $self;
75 }
76  
77 14 ▶sub absolute {
Subroutine absolute: called CC=2 SCAR=6.9
Pod undocumented
78 14 my $self = shift;
79 14 ▶ return $self if $self->is_absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_absolute 7 7 14
80 7 return $self->new($self->_spec->rel2abs($self->stringify, @_));
81 }
82  
83 13 ▶sub relative {
Subroutine relative: called CC=1 SCAR=0.0
Pod undocumented
84 13 my $self = shift;
85 13 return $self->new($self->_spec->abs2rel($self->stringify, @_));
86 }
87  
88 2 ▶sub stat { File::stat::stat("$_[0]") }
Subroutine stat: called CC=1 SCAR=0.0
Pod undocumented
89 0 ▶sub lstat { File::stat::lstat("$_[0]") }
Subroutine lstat: not called CC=1 SCAR=6.9
Pod undocumented
90  
91 29 ▶sub PRUNE { return \&PRUNE; }
Subroutine PRUNE: called CC=1 SCAR=0.0
Pod undocumented
92  
93 7 1;
94 __END__
« Class/Dir.pm ↑ Summary Class.pm »