Local.pm

filter: Statementstmt 88.5% 85 / 96 Branchbran 57.1% 32 / 56 Conditioncond 70.3% 19 / 27 MC/DCmcdc 46.6% 7 / 15 Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 7 totaltotal 72.8% 158 / 217 CC 40 SCAR 22.2
CC
40
Cov
76%
print_path
20.0
get_path
13.2
add_to_path
11.1
CRAP 9.2
↑ Summary Local/PATH.pm »
1 2 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Devel::Local;
3 2 our $VERSION = '0.22';
4  
5 2 ▶use Cwd 'abs_path';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 my $path_sep = $Config::Config{'path_sep'};
11  
12 3 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
13 3 my ($package, @args) = @_;
14 3 unshift @INC, get_path('PERL5LIB', @args);
15 3 $ENV{PATH} = join $path_sep, get_path('PATH', @args);
16 }
17  
18 0 ▶sub print_path {
Subroutine print_path: not called CC=4 SCAR=30.0
Pod undocumented
19 0 my ($name, @args) = @_;
20 0 my @path = get_path($name, @args);
21 0 ▶ if (@path) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 0 0 0
22 0 ▶ if (not $ENV{PERL_DEVEL_LOCAL_QUIET}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PERL_DEVEL_LOCAL_QUIET"}) 0 0 0
23 0 warn "${name}:\n";
24 0 for (@path) {
25 0 warn " $_\n";
26 }
27 0 warn "\n";
28 }
29 0 print join $path_sep, @path;
30 }
31 }
32  
33 6 ▶sub get_path {
Subroutine get_path: called CC=12 SCAR=25.8
Pod undocumented
34 6 my ($name, @args) = @_;
35 6 my $cmd = '';
36 6 ▶ if (not @args) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @args) { } 4 2 6
elsif (@args == 1 and $args[0] =~ /^[\!\?]$/) { } 2 0 2
37 4 @args = get_config_file();
38 }
39 ▶ elsif (@args == 1 and $args[0] =~ /^[\!\?]$/) {
Condition33%1/3
@args == 1 and $args[0] =~ /^[\!\?]$/
!ll&&!rl&&r
002
MC/DC0%0/2
@args == 1 and $args[0] =~ /^[\!\?]$/
@args == 1 $args[0] =~ /^[\!\?]$/
Truth table33%1/3
A and B
A= @args == 1B= $args[0] =~ /^[\!\?]$/
ABresult
0X0
100
111
40 2 $cmd = shift @args;
41 }
42 6 my (@left, @right, $found);
43 map {
44 21 ▶ if ($_ eq '|') {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '|') { } 4 17 21
elsif ($found) { } 8 9 17
45 4 $found = 1;
46 }
47 elsif ($found) {
48 8 unshift @left, $_;
49 }
50 else {
51 9 ▶ unshift @right, $_;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{$name} ? : 5 1 6
52 }
53 } reverse(($ENV{$name})
54 6 ? grep($_, split($path_sep, $ENV{$name}, -1))
55 : ()
56 );
57 6 ▶ if ($cmd eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "!") 2 4 6
58 2 return @right;
59 }
60 4 ▶ if ($cmd eq '?') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "?") 0 4 4
61 0 ▶ return scalar(@left) ? (@left, '|', @right) : (@right);
Branch: 1 branch
BranchTrueFalseTotal
scalar @left ? : 0 0 0
62 }
63  
64 4 my @locals = get_locals(@args);
65 4 for my $dir (reverse @locals) {
66 12 add_to_path($name, $dir, \@left);
67 }
68 4 ▶ return scalar(@left) ? (@left, '|', @right) : (@right);
Branch: 1 branch
BranchTrueFalseTotal
scalar @left ? : 4 0 4
69 }
70  
71 4 ▶sub get_config_file {
Subroutine get_config_file: called CC=5 SCAR=23.0
Pod undocumented
72 4 my $home_file = File::Spec->catfile($ENV{HOME}, '.perl-devel-local');
73 4 my $dot_file = File::Spec->catfile(File::Spec->curdir, 'devel-local');
74 return
75 $ENV{PERL_DEVEL_LOCAL} ? $ENV{PERL_DEVEL_LOCAL} :
76 (-f $dot_file) ? $dot_file :
77 4 ▶ ($ENV{HOME} && -f $home_file) ? $home_file :
Branch: 3 branches
BranchTrueFalseTotal
$ENV{'PERL_DEVEL_LOCAL'} ? : 0 4 4
-f $dot_file ? : 4 0 4
$ENV{'HOME'} && -f $home_file ? : 0 0 0
Condition0%0/3
$ENV{"HOME"} and -f $home_file
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"HOME"} and -f $home_file
$ENV{"HOME"} -f $home_file
Truth table0%0/3
A and B
A= $ENV{"HOME"}B= -f $home_file
ABresult
0X0
100
111
78 ();
79 }
80  
81 4 ▶sub get_locals {
Subroutine get_locals: called CC=5 SCAR=17.0
Pod undocumented
82 return map {
83 12 s!([\\/])/+!$1!g;
84 12 s!(.)/$!$1!;
85 12 abs_path($_);
86 } grep {
87 12 ▶ s!^~/!$ENV{HOME}/! if defined $ENV{HOME};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"HOME"} 12 0 12
88 12 -d $_;
89 } map {
90 2 ▶ -f($_) ? map { /\*/ ? glob($_) : $_ } read_config($_) :
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 3 branches
BranchTrueFalseTotal
-f $_ ? : 4 0 4
/\*/ ? : 0 12 12
/\*/ ? : 0 0 0
91 /\*/ ? glob($_) :
92 ($_);
93 } @_;
94 }
95  
96 12 ▶sub add_to_path {
Subroutine add_to_path: called CC=11 SCAR=24.0
Pod undocumented
97 12 my ($name, $dir, $path) = @_;
98 12 my $bin = File::Spec->catfile($dir, 'bin');
99 12 my $lib = File::Spec->catfile($dir, 'lib');
100 12 my $blib = File::Spec->catfile($dir, 'blib');
101 12 my @add;
102 12 ▶ if ($name eq 'PERL5LIB' and -d $lib) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'PERL5LIB' and -d $lib) { } 4 8 12
elsif ($name eq 'PATH' and -d $bin) { } 4 6 10
Condition100%3/3
$name eq "PERL5LIB" and -d $lib
!ll&&!rl&&r
624
MC/DC100%2/2
$name eq "PERL5LIB" and -d $lib
$name eq "PERL5LIB" -d $lib
Truth table100%3/3
A and B
A= $name eq "PERL5LIB"B= -d $lib
ABresult
0X0
100
111
103 4 push @add, $lib;
104 4 ▶ if (has_xs($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_xs($dir)) 0 4 4
105 0 push @add, $blib;
106 }
107 }
108 ▶ elsif ($name eq 'PATH' and -d $bin) {
Condition100%3/3
$name eq "PATH" and -d $bin
!ll&&!rl&&r
224
MC/DC100%2/2
$name eq "PATH" and -d $bin
$name eq "PATH" -d $bin
Truth table100%3/3
A and B
A= $name eq "PATH"B= -d $bin
ABresult
0X0
100
111
109 4 push @add, $bin;
110 }
111 12 ▶ return unless @add;
Branch: 1 branch
BranchTrueFalseTotal
unless @add 4 8 12
112 @$path = (
113 @add,
114 grep {
115 8 not(
116 10 ▶ ($name eq 'PERL5LIB' and ($_ eq $lib or $_ eq $blib)) or
Condition91%11/12
$name eq 'PERL5LIB' && ($_ eq $lib || $_ eq $blib) || $name eq 'PATH' && $_ eq $bin
l!l&&r!l&&!r
226
$name eq "PERL5LIB" and $_ eq $lib || $_ eq $blib
!ll&&!rl&&r
532
$_ eq $lib or $_ eq $blib
l!l&&r!l&&!r
203
$name eq "PATH" and $_ eq $bin
!ll&&!rl&&r
332
MC/DC60%3/5
$name eq 'PERL5LIB' && ($_ eq $lib || $_ eq $blib) || $name eq 'PATH' && $_ eq $bin
$name eq "PERL5LIB" $_ eq $lib $_ eq $blib $name eq "PATH" $_ eq $bin
Truth table50%4/8
A and B or C || D and E
A= $name eq "PERL5LIB"B= $_ eq $libC= $_ eq $blibD= $name eq "PATH"E= $_ eq $bin
ABCDEresult
11XXX1
101XX1
0XX111
100111
0XX0X0
0XX100
1000X0
100100
117 ($name eq 'PATH' and ($_ eq $bin))
118 )
119 } @$path
120 );
121 8 return;
122 }
123  
124 4 ▶sub has_xs {
Subroutine has_xs: called CC=1 SCAR=0.0
Pod undocumented
125 4 my $dir = shift;
126 4 my @xs;
127 16 ▶ File::Find::find sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
128 16 ▶ push @xs, $_ if /\.xs$/;
Branch: 1 branch
BranchTrueFalseTotal
if /\.xs$/ 0 16 16
129 4 }, $dir;
130 4 return scalar @xs;
131 }
132  
133 4 ▶sub read_config {
Subroutine read_config: called CC=7 SCAR=20.5
Pod undocumented
134 4 my ($file) = @_;
135 4 ▶ return () unless $file and -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -f $file 0 4 4
Condition33%1/3
$file and -f $file
!ll&&!rl&&r
004
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table33%1/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
136 4 ▶ open my $f, $file or die "Can't open $file for input";
Branch: 1 branch
BranchTrueFalseTotal
open my $f, $file or die "Can't open $file for input" 4 0 4
137 4 my @lines;
138 4 ▶ while (my $line = <$f>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $f)) 12 4 16
139 12 chomp $line;
140 12 ▶ last unless $line =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\S/ 0 12 12
141 12 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 0 12 12
142 12 $line =~ s/^\s*(.*?)\s*/$1/;
143 12 push @lines, $line;
144 }
145 4 return @lines;
146 }
147  
148 2 1;
↑ Summary Local/PATH.pm »