| 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
Condition66%2/3
defined $ENV{"PERL_FILE_SHAREDIR_DIST"} and $ENV{"PERL_FILE_SHAREDIR_DIST"} =~ /^(.*?)=(.*)$/
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"} =~ /^(.*?)=(.*)$/
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | ▶ | return File::Spec->rel2abs($over{$dist_name}) if $over{$dist_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 7 | my $share = File::Spec->catdir( $inc, qw( auto share dist ), $dist_name ); | |||||||||||||||||||||||||||
| 39 | 7 | ▶ | if(-d $share) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 5 | return File::Spec->rel2abs($share); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | if(!File::Spec->file_name_is_absolute($inc)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $dirs[-1] and $dirs[-1] eq "lib"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $dir and -d $dir
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
| |||||||||||||||||||||||||||||
| 80 | 2 | my $fn = File::Spec->catfile($dir, 'config.pl'); | |||||||||||||||||||||||||||
| 81 | 2 | ▶ | return {} unless -f $fn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 1 | my $fh; | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | open($fh, '<', $fn) || die "unable to read $fn $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | my $pl = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 85 | 1 | close $fh; | |||||||||||||||||||||||||||
| 86 | 1 | my $config = eval $pl; | |||||||||||||||||||||||||||
| 87 | 1 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||