| 1 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Class::Scaffold::Introspect; | ||||||||||||||||||||||||||||
| 6 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | $Class::Scaffold::Introspect::VERSION = '1.102280'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Find configuration files within the framework | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use FindBin '$Bin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Spec::Functions qw/curdir updir rootdir rel2abs/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Sys::Hostname; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | our %EXPORT_TAGS = (conf => [qw/find_conf_file/],); | |||||||||||||||||||||||||||
| 16 | 1 | our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] }; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub find_file_upwards { | ||||||||||||||||||||||||||
|
Subroutine
find_file_upwards: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $wanted_file = shift; | |||||||||||||||||||||||||||
| 20 | 0 | my $previous_cwd = getcwd; | |||||||||||||||||||||||||||
| 21 | 0 | my $result; # left undef as we'll return undef if we didn't find it | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | while (rel2abs(curdir()) ne rootdir()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (-f $wanted_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | $result = rel2abs(curdir()); | |||||||||||||||||||||||||||
| 25 | 0 | last; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | chdir(updir()); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | chdir($previous_cwd); | |||||||||||||||||||||||||||
| 30 | 0 | $result; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub find_conf_file { | ||||||||||||||||||||||||||
|
Subroutine
find_conf_file: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my $file = 'SMOKEconf.yaml'; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # the distribution root is where Build.PL is; start the search from where | ||||||||||||||||||||||||||||
| 37 | # the bin file was (presumably within the distro). This way we can say any | ||||||||||||||||||||||||||||
| 38 | # of: | ||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||
| 40 | # perl t/sometest.t | ||||||||||||||||||||||||||||
| 41 | # cd t; perl sometest.t | ||||||||||||||||||||||||||||
| 42 | # perl /abs/path/to/distro/t/sometest.t | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | chdir($Bin) or die "can't chdir to [$Bin]: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $distro_root = find_file_upwards('Makefile.PL') | ||||||||||||||||||||||||||
|
Condition0%0/3
find_file_upwards('Makefile.PL') || find_file_upwards('dist.ini')
MC/DC0%0/2
find_file_upwards('Makefile.PL') || find_file_upwards('dist.ini')
find_file_upwards('Makefile.PL')
find_file_upwards('dist.ini')
Truth table0%0/3
A || B
A= find_file_upwards('Makefile.PL')B= find_file_upwards('dist.ini')
| |||||||||||||||||||||||||||||
| 45 | || find_file_upwards('dist.ini'); | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | unless (defined $distro_root && length $distro_root) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $distro_root and length $distro_root
MC/DC0%0/2
defined $distro_root and length $distro_root
defined $distro_root
length $distro_root
Truth table0%0/3
A and B
A= defined $distro_rootB= length $distro_root
| |||||||||||||||||||||||||||||
| 47 | 0 | warn "can't find distro root from [$Bin]\n"; | |||||||||||||||||||||||||||
| 48 | warn "might not be able to find conf file using [$ENV{CF_CONF}]\n" | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if $ENV{CF_CONF} eq 'local'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 0 | my $etc = "$distro_root/etc"; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | return "$etc/$file" if -e "$etc/$file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # warn "find_conf_file: not in [$etc/$file]"; | ||||||||||||||||||||||||||||
| 56 | 0 | (my $hostname = hostname) =~ s/\W.*//; | |||||||||||||||||||||||||||
| 57 | 0 | my $dir = "$etc/$hostname"; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | return "$dir/$file" if -d $dir && -e "$dir/$file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-d $dir and -e "$dir/$file"
MC/DC0%0/2
-d $dir and -e "$dir/$file"
-d $dir
-e "$dir/$file"
Truth table0%0/3
A and B
A= -d $dirB= -e "$dir/$file"
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # warn "find_conf_file: not in [$dir/$file]"; | ||||||||||||||||||||||||||||
| 61 | 0 | undef; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||