Find/Unix.pm

filter: Statementstmt 48.0% 50 / 104 Branchbran 23.0% 18 / 78 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 8 / 14 Podpod 40.0% 2 / 5 totaltotal 36.2% 78 / 215 CC 46 SCAR 41.2
CC
46
Cov
36%
look_for_dir_file
210.0
look_for_helper
30.0
_var_dir
20.0
CRAP 61.7
↑ Summary Find.pm »
1 package Config::Find::Unix;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Config::Find::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our @ISA=qw(Config::Find::Any);
11  
12 14 ▶sub app_dir {
Subroutine app_dir: called CC=3 SCAR=11.3
Pod undocumented
13 14 my ($class, $name)=@_;
14 14 ▶ $name=$class->guess_script_name
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 14 14
15 unless defined $name;
16  
17 14 my $ename = uc($name).'_HOME';
18 14 ▶ return $ENV{$ename} if (exists $ENV{$ename});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ENV{$ename} 0 14 14
19  
20 14 $class->parent_dir($class->guess_script_dir);
21 }
22  
23 7 ▶sub _my_home {
Subroutine _my_home: called CC=4 SCAR=23.7
24 7 my $home = File::HomeDir->my_home;
25 7 ▶ return $home if defined $home;
Branch: 1 branch
BranchTrueFalseTotal
if defined $home 7 0 7
26  
27 0 my ($user, $dir) = (getpwuid $>)[0, 7];
28  
29 0 ▶ return $dir if defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dir 0 0 0
30 0 ▶ return "/home/$user" if defined $user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $user 0 0 0
31 0 return "/"
32 };
33  
34 0 ▶sub system_temp { '/tmp' }
Subroutine system_temp: not called CC=1 SCAR=6.9
Pod undocumented
35  
36 0 ▶sub _var_dir {
Subroutine _var_dir: not called CC=4 SCAR=30.0
37 0 my ($class, $name, $more_name, $scope) = @_;
38  
39 0 ▶ if ($scope eq 'global') {
Branch: 3 branches
BranchTrueFalseTotal
if ($scope eq 'global') { } 0 0 0
elsif ($scope eq 'user') { } 0 0 0
elsif ($scope eq 'app') { } 0 0 0
40 0 $class->my_catfile('/var', $name, $more_name);
41 } elsif ($scope eq 'user') {
42 0 File::Spec->catfile(_my_home(), '.'.$name, 'var', $more_name);
43 } elsif ($scope eq 'app') {
44 0 $class->my_catfile($class->app_dir($name), 'var', $more_name);
45 } else {
46 0 croak "scope '$scope' is not valid for var_dir method";
47 }
48 }
49  
50 0 ▶sub _bin_dir {
Subroutine _bin_dir: not called CC=4 SCAR=30.0
51 0 my ($class, $name, $more_name, $scope) = @_;
52
53 0 ▶ if ($scope eq 'global') {
Branch: 3 branches
BranchTrueFalseTotal
if ($scope eq 'global') { } 0 0 0
elsif ($scope eq 'user') { } 0 0 0
elsif ($scope eq 'app') { } 0 0 0
54 0 '/usr/bin';
55 } elsif ($scope eq 'user') {
56 0 File::Spec->catfile(_my_home(), 'bin');
57 } elsif ($scope eq 'app') {
58 0 File::Spec->catfile($class->app_dir($name), 'bin');
59 } else {
60 0 croak "scope '$scope' is not valid for bin_dir method";
61 }
62 }
63  
64 0 ▶sub _lib_dir {
Subroutine _lib_dir: not called CC=4 SCAR=30.0
65 0 my ($class, $name, $more_name, $scope) = @_;
66
67 0 ▶ if ($scope eq 'global') {
Branch: 3 branches
BranchTrueFalseTotal
if ($scope eq 'global') { } 0 0 0
elsif ($scope eq 'user') { } 0 0 0
elsif ($scope eq 'app') { } 0 0 0
68 0 '/usr/lib';
69 } elsif ($scope eq 'user') {
70 0 File::Spec->catfile(_my_home(), 'lib');
71 } elsif ($scope eq 'app') {
72 0 File::Spec->catfile($class->app_dir($name), 'lib');
73 } else {
74 0 croak "scope '$scope' is not valid for lib_dir method";
75 }
76 }
77  
78 8 ▶sub look_for_file {
Subroutine look_for_file: called CC=15 SCAR=28.2
Pod documented
79 8 my ($class, $name, $write, $global)=@_;
80 8 my $fn;
81
82 8 ▶ if ($write) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write) { } 2 6 8
83 2 ▶ if ($global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global) 1 1 2
84 1 my $fnwe=$class->add_extension($name, 'conf');
85  
86 1 ▶ unless ($class->is_one_liner) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->is_one_liner) 1 0 1
87 1 my $etc=File::Spec->catfile($class->app_dir($name), 'etc');
88 1 ▶ return File::Spec->catfile($etc, $fnwe) if -e $etc;
Branch: 1 branch
BranchTrueFalseTotal
if -e $etc 0 1 1
89  
90 1 $etc=File::Spec->catfile($class->app_dir($name), 'conf');
91 1 ▶ return File::Spec->catfile($etc, $fnwe) if -e $etc;
Branch: 1 branch
BranchTrueFalseTotal
if -e $etc 1 0 1
92 }
93  
94 0 return File::Spec->catfile('/etc', $fnwe);
95 }
96  
97 1 return File::Spec->catfile(_my_home(), ".$name");
98  
99 } else {
100  
101 # looks in ~/.whatever
102 6 ▶ unless ($global) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($global) 6 0 6
103 6 $fn=File::Spec->catfile(_my_home(), ".$name");
104 6 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 3 3 6
105 3 for my $ext (qw(conf cfg)) {
106 6 ▶ return "$fn.$ext" if -f "$fn.$ext";
Branch: 1 branch
BranchTrueFalseTotal
if -f "$fn.$ext" 0 6 6
107 }
108 }
109  
110 3 for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) {
111 6 ▶ unless ($class->is_one_liner) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->is_one_liner) 6 0 6
112 # looks in ./../etc/whatever.conf relative to the running script
113 6 $fn=File::Spec->catfile($class->app_dir($name), 'etc', $fnwe);
114 6 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 6 6
115
116 # looks in ./../conf/whatever.conf relative to the running script
117 6 $fn=File::Spec->catfile($class->app_dir($name), 'conf', $fnwe);
118 6 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 6 6
119 }
120  
121 # looks in /etc/whatever.conf
122 6 $fn=File::Spec->catfile('/etc', $fnwe);
123 6 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 6 6
124 }
125 }
126
127 3 return;
128 }
129  
130 0 ▶sub look_for_helper {
Subroutine look_for_helper: not called CC=5 SCAR=34.0
Pod undocumented
131 0 my ($class, $dir, $helper)=@_;
132 0 my $path=File::Spec->catfile($dir, $helper);
133 0 ▶ -e $path
Branch: 1 branch
BranchTrueFalseTotal
-e $path or croak("helper '${helper}' not found") 0 0 0
134 or croak "helper '$helper' not found";
135 0 ▶ ((-f $path or -l $path) and -x $path)
Branch: 1 branch
BranchTrueFalseTotal
-f $path || -l $path and -x $path or croak("helper '${helper}' found at '${path}' but it is not executable") 0 0 0
Condition0%0/6
-f $path || -l $path and -x $path
!ll&&!rl&&r
000
-f $path or -l $path
l!l&&r!l&&!r
000
MC/DC0%0/3
-f $path || -l $path and -x $path
-f $path -l $path -x $path
Truth table0%0/5
A or B and C
A= -f $pathB= -l $pathC= -x $path
ABCresult
00X0
1X00
0100
1X11
0111
136 or croak "helper '$helper' found at '$path' but it is not executable";
137 0 return $path
138 }
139  
140 0 ▶sub look_for_dir_file {
Subroutine look_for_dir_file: not called CC=14 SCAR=53.5
Pod documented
141 0 my ($class, $dir, $name, $write, $global)=@_;
142 0 my $fn;
143  
144 0 ▶ if ($write) {
Branch: 1 branch
BranchTrueFalseTotal
if ($write) { } 0 0 0
145 0 my $fnwe=$class->add_extension($name, 'conf');
146 0 ▶ if ($global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($global) 0 0 0
147 0 ▶ unless ($class->is_one_liner) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->is_one_liner) 0 0 0
148 0 my $etc=File::Spec->catfile($class->app_dir($dir), 'etc');
149 0 ▶ return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc;
Branch: 1 branch
BranchTrueFalseTotal
if -e $etc 0 0 0
150  
151 0 $etc=File::Spec->catfile($class->app_dir($dir), 'conf');
152 0 ▶ return File::Spec->catfile($etc, $dir, $fnwe) if -e $etc;
Branch: 1 branch
BranchTrueFalseTotal
if -e $etc 0 0 0
153 }
154  
155 0 return File::Spec->catfile('/etc', $dir, $fnwe);
156 }
157  
158 0 return File::Spec->catfile(_my_home(), ".$dir", $fnwe);
159  
160 } else {
161 # looks in ~/.whatever
162 0 for my $fnwe (map {$class->add_extension($name, $_)} qw(conf cfg)) {
163  
164 0 ▶ unless ($global) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($global) 0 0 0
165 0 my $fn=File::Spec->catfile(_my_home(), ".$dir", $fnwe);
166 0 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 0 0
167 }
168  
169 0 ▶ unless ($class->is_one_liner and not defined $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->is_one_liner and not defined $dir) 0 0 0
Condition0%0/3
$class->is_one_liner and not defined $dir
!ll&&!rl&&r
000
MC/DC0%0/2
$class->is_one_liner and not defined $dir
$class->is_one_liner not defined $dir
Truth table0%0/3
A and not(B)
A= $class->is_one_linerB= not defined $dir
ABresult
0X0
100
111
170 # looks in ./../etc/whatever.conf relative to the running script
171 0 $fn=File::Spec->catfile($class->app_dir($dir), 'etc', $dir, $fnwe);
172 0 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 0 0
173  
174 # looks in ./../conf/whatever.conf relative to the running script
175 0 $fn=File::Spec->catfile($class->app_dir($dir), 'conf', $dir, $fnwe);
176 0 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 0 0
177 }
178
179 # looks in system /etc/whatever.conf
180 0 $fn=File::Spec->catfile('/etc', $dir, $fnwe);
181 0 ▶ return $fn if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 0 0
182 }
183 }
184  
185 0 return;
186 }
187  
188 6 1;
189  
190 __END__
↑ Summary Find.pm »