File Coverage

blib/lib/ASP4/ConfigFinder.pm
Criterion Covered Total %
statement 17 18 94.4
branch 5 6 83.3
condition 2 3 66.6
subroutine 4 4 100.0
pod 0 1 0.0
total 28 32 87.5


line stmt bran cond sub pod time code
1              
2             package ASP4::ConfigFinder;
3              
4 9     9   39 use strict;
  9         16  
  9         231  
5 9     9   32 use warnings 'all';
  9         10  
  9         256  
6 9     9   31 use Cwd 'cwd';
  9         11  
  9         1909  
7              
8             our $CONFIGFILE = 'asp4-config.json';
9              
10              
11             sub config_path
12             {
13 37117     37117 0 30247 my $path = $CONFIGFILE;
14            
15 37117   66     369588 my $root = $ENV{DOCUMENT_ROOT} || cwd();
16            
17             # Try test dir:
18 37117 100       410837 if( -f "$root/t/conf/$CONFIGFILE" )
19             {
20 133         1912 return "$root/t/conf/$CONFIGFILE";
21             }# end if()
22            
23             # Start moving up:
24 36984         53137 for( 1...10 )
25             {
26 73968         80007 my $path = "$root/conf/$CONFIGFILE";
27 73968 100       681327 return $path if -f $path;
28 36984 50       212300 $root =~ s/\/[^\/]+$//
29             or last;
30             }# end for()
31            
32 0           die "CANNOT FIND '$CONFIGFILE' anywhere under '$root'";
33             }# end config_path()
34              
35             1;# return true:
36