lib/App/Perlbrew/Path.pm

filter: Statementstmt 100% 65 / 65 Branchbran 75.0% 9 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 23 / 23 Podpod 0.0% 0 / 13 totaltotal 82.7% 101 / 122 CC 10 SCAR 9.0
CC
10
Cov
93%
symlink
7.1
_joinpath
3.0
stringify_with_tilde
2.0
CRAP 2.5
« lib/App/Perlbrew/Util.pm ↑ Summary lib/App/Perlbrew/Path/Installations.pm »
1 73 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 73 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package App::Perlbrew::Path;
5  
6 73 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 73 ▶use File::Glob ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 73 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 73 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
11 73 '""' => \& stringify,
12 fallback => 1,
13 73 );
14  
15 4580 ▶sub _joinpath {
Subroutine _joinpath: called CC=3 SCAR=11.0
16 4580 for my $entry (@_) {
17 73 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8676 ▶ die 'Received an undefined entry as a parameter (all parameters are: '. join(', ', @_). ')' unless (defined($entry));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $entry 1 8675 8676
19 }
20 4579 return join "/", @_;
21 }
22  
23 3214 ▶sub _child {
Subroutine _child: called CC=1 SCAR=0.0
24 3214 my ($self, $package, @path) = @_;
25  
26 3214 $package->new($self->{path}, @path);
27 }
28  
29 659 ▶sub _children {
Subroutine _children: called CC=1 SCAR=0.0
30 659 my ($self, $package) = @_;
31  
32 659 map { $package->new($_) } File::Glob::bsd_glob($self->child("*"));
33 }
34  
35 4580 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
36 4580 my ($class, @path) = @_;
37  
38 4580 bless { path => _joinpath (@path) }, $class;
39 }
40  
41 63 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod undocumented
42 63 my ($self) = @_;
43  
44 63 -e $self->stringify;
45 }
46  
47 549 ▶sub basename {
Subroutine basename: called CC=1 SCAR=0.0
Pod undocumented
48 549 my ($self, $suffix) = @_;
49  
50 549 return scalar File::Basename::fileparse($self, ($suffix) x!! defined $suffix);
51 }
52  
53 2437 ▶sub child {
Subroutine child: called CC=1 SCAR=0.0
Pod undocumented
54 2437 my ($self, @path) = @_;
55  
56 2437 return $self->_child(__PACKAGE__, @path);
57 }
58  
59 480 ▶sub children {
Subroutine children: called CC=1 SCAR=0.0
Pod undocumented
60 480 my ($self) = @_;
61  
62 480 return $self->_children(__PACKAGE__);
63 }
64  
65 8 ▶sub dirname {
Subroutine dirname: called CC=1 SCAR=0.0
Pod undocumented
66 8 my ($self) = @_;
67  
68 8 return App::Perlbrew::Path->new( File::Basename::dirname($self) );
69 }
70  
71 234 ▶sub mkpath {
Subroutine mkpath: called CC=1 SCAR=0.0
Pod undocumented
72 234 my ($self) = @_;
73 234 File::Path::mkpath( [$self->stringify], 0, 0777 );
74 234 return $self;
75 }
76  
77 63 ▶sub readlink {
Subroutine readlink: called CC=2 SCAR=6.9
Pod undocumented
78 63 my ($self) = @_;
79  
80 63 my $link = CORE::readlink( $self->stringify );
81 63 ▶ $link = __PACKAGE__->new($link) if defined $link;
Branch: 1 branch
BranchTrueFalseTotal
if defined $link 61 2 63
82  
83 63 return $link;
84 }
85  
86 11 ▶sub rmpath {
Subroutine rmpath: called CC=1 SCAR=0.0
Pod undocumented
87 11 my ($self) = @_;
88 11 File::Path::rmtree( [$self->stringify], 0, 0 );
89 11 return $self;
90 }
91  
92 7061 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod undocumented
93 7061 my ($self) = @_;
94  
95 7061 return $self->{path};
96 }
97  
98 34 ▶sub stringify_with_tilde {
Subroutine stringify_with_tilde: called CC=2 SCAR=7.0
Pod undocumented
99 34 my ($self) = @_;
100 34 my $path = $self->stringify;
101 34 my $home = $ENV{HOME};
102 34 ▶ $path =~ s!\Q$home/\E!~/! if $home;
Branch: 1 branch
BranchTrueFalseTotal
if $home 34 0 34
103 34 return $path;
104 }
105  
106 3 ▶sub symlink {
Subroutine symlink: called CC=6 SCAR=19.6
Pod undocumented
107 3 my ($self, $destination, $force) = @_;
108 3 ▶ $destination = App::Perlbrew::Path->new($destination) unless ref $destination;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $destination 0 3 3
109  
110 3 ▶ CORE::unlink($destination) if $force && (-e $destination || -l $destination);
Branch: 1 branch
BranchTrueFalseTotal
if $force and -e $destination || -l $destination 1 2 3
Condition50%3/6
$force and -e $destination || -l $destination
!ll&&!rl&&r
201
-e $destination or -l $destination
l!l&&r!l&&!r
010
MC/DC33%1/3
$force and -e $destination || -l $destination
$force -e $destination -l $destination
Truth table50%2/4
A and B or C
A= $forceB= -e $destinationC= -l $destination
ABCresult
0XX0
1000
11X1
1011
111  
112 3 ▶ $destination if CORE::symlink($self, $destination);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::symlink $self, $destination 3 0 3
113 }
114  
115 8 ▶sub unlink {
Subroutine unlink: called CC=1 SCAR=0.0
Pod undocumented
116 8 my ($self) = @_;
117 8 CORE::unlink($self);
118 }
119  
120 73 1;
121  
« lib/App/Perlbrew/Util.pm ↑ Summary lib/App/Perlbrew/Path/Installations.pm »