File/ShareDir/Dist.pm

filter: Statementstmt 100% 62 / 62 Branchbran 83.3% 20 / 24 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 89.1% 99 / 111 CC 18 SCAR 19.4
CC
18
Cov
92%
dist_share
11.2
dist_config
6.1
import
3.0
CRAP 6.9
↑ Summary File/ShareDir/Dist/Install.pm »
1 package File::ShareDir::Dist;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our @EXPORT_OK = qw( dist_share dist_config );
10  
11 # ABSTRACT: Locate per-dist shared files
12 2 our $VERSION = '0.07'; # VERSION
13  
14  
15 # TODO: Works with PAR
16  
17 2 our %over;
18  
19 sub dist_share ($)
20 14 ▶{
Subroutine dist_share: called CC=11 SCAR=24.2
Pod documented
21 14 my($dist_name) = @_;
22
23 14 $dist_name =~ s/::/-/g;
24  
25 local $over{$1} = $2
26 14 ▶ if defined $ENV{PERL_FILE_SHAREDIR_DIST} && $ENV{PERL_FILE_SHAREDIR_DIST} =~ /^(.*?)=(.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"PERL_FILE_SHAREDIR_DIST"} and $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/ 1 13 14
Condition66%2/3
defined $ENV{"PERL_FILE_SHAREDIR_DIST"} and $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/
!ll&&!rl&&r
1301
MC/DC50%1/2
defined $ENV{"PERL_FILE_SHAREDIR_DIST"} and $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/
defined $ENV{"PERL_FILE_SHAREDIR_DIST"} $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/
Truth table66%2/3
A and B
A= defined $ENV{"PERL_FILE_SHAREDIR_DIST"}B= $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/
ABresult
0X0
100
111
27  
28 14 ▶ return File::Spec->rel2abs($over{$dist_name}) if $over{$dist_name};
Branch: 1 branch
BranchTrueFalseTotal
if $File::ShareDir::Dist::over{$dist_name} 3 11 14
29  
30 11 my @pm = split /-/, $dist_name;
31 11 $pm[-1] .= ".pm";
32  
33 11 foreach my $inc (@INC)
34 {
35 12 my $pm = File::Spec->catfile( $inc, @pm );
36 12 ▶ if(-f $pm)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $pm) 7 5 12
37 {
38 7 my $share = File::Spec->catdir( $inc, qw( auto share dist ), $dist_name );
39 7 ▶ if(-d $share)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $share) 5 2 7
40 {
41 5 return File::Spec->rel2abs($share);
42 }
43
44 2 ▶ if(!File::Spec->file_name_is_absolute($inc))
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($inc)) 2 0 2
45 {
46 2 my($v,$dir) = File::Spec->splitpath( File::Spec->rel2abs($inc), 1 );
47 2 my @dirs = File::Spec->splitdir($dir);
48 2 ▶ if(defined $dirs[-1] && $dirs[-1] eq 'lib')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dirs[-1] and $dirs[-1] eq "lib") 2 0 2
Condition33%1/3
defined $dirs[-1] and $dirs[-1] eq "lib"
!ll&&!rl&&r
002
MC/DC0%0/2
defined $dirs[-1] and $dirs[-1] eq "lib"
defined $dirs[-1] $dirs[-1] eq "lib"
Truth table33%1/3
A and B
A= defined $dirs[-1]B= $dirs[-1] eq "lib"
ABresult
0X0
100
111
49 {
50 2 pop @dirs; # pop off the 'lib';
51 # put humpty dumpty back together again
52 2 my $share = File::Spec->catdir(
53 File::Spec->catpath($v,
54 File::Spec->catdir(@dirs),
55 '',
56 ),
57 'share',
58 );
59
60 2 ▶ if(-d $share)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $share) 1 1 2
61 {
62 1 return $share;
63 }
64 }
65 }
66  
67 1 last;
68 }
69 }
70
71 5 return;
72 }
73  
74  
75 sub dist_config
76 4 ▶{
Subroutine dist_config: called CC=6 SCAR=18.0
Pod documented
77 4 my($dist_name) = @_;
78 4 my $dir = dist_share $dist_name;
79 4 ▶ return {} unless defined $dir && -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and -d $dir 2 2 4
Condition66%2/3
defined $dir and -d $dir
!ll&&!rl&&r
202
MC/DC50%1/2
defined $dir and -d $dir
defined $dir -d $dir
Truth table66%2/3
A and B
A= defined $dirB= -d $dir
ABresult
0X0
100
111
80 2 my $fn = File::Spec->catfile($dir, 'config.pl');
81 2 ▶ return {} unless -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $fn 1 1 2
82 1 my $fh;
83 1 ▶ open($fh, '<', $fn) || die "unable to read $fn $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $fn or die "unable to read $fn $!" 1 0 1
84 1 my $pl = do { local $/; <$fh> };
85 1 close $fh;
86 1 my $config = eval $pl;
87 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
88 1 $config;
89 }
90  
91 sub import
92 2 ▶{
Subroutine import: called CC=3 SCAR=11.0
93 2 my($class, @args) = @_;
94  
95 2 my @modify;
96
97 2 foreach my $arg (@args)
98 {
99 3 ▶ if($arg =~ /^-(.*?)=(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^-(.*?)=(.*)$/) { } 1 2 3
100 {
101 1 $over{$1} = $2;
102 }
103 else
104 {
105 2 push @modify, $arg;
106 }
107 }
108
109 2 @_ = ($class, @modify);
110
111 2 goto \&Exporter::import;
112 }
113  
114 2 1;
115  
116 __END__
↑ Summary File/ShareDir/Dist/Install.pm »