blib/script/find

filter: Statementstmt 86.7% 72 / 83 Branchbran 45.4% 20 / 44 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 73.3% 110 / 150 CC 7 SCAR 8.4
CC
7
Cov
72%
find_find2perl
4.2
wanted
4.0
BEGIN
1.0
CRAP 2.3
« bin/echo ↑ Summary blib/lib/ppt.pm »
1 #!/usr/local/bin/perl
2  
3 =begin metadata
4  
5 Name: find
6 Description: search directory tree for files matching a pattern
7 Author: Greg Snow, snow@biostat.washington.edu
8 Author: Tom Christiansen, tchrist@perl.com
9 Author: Larry Wall, larry@wall.org
10 License: perl
11  
12 =end metadata
13  
14 =cut
15  
16  
17 # find - actually a pass through front end for find2perl
18  
19 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use File::Spec::Functions;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use File::Temp qw/ tempfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 3 ▶sub find_find2perl {
Subroutine find_find2perl: called CC=4 SCAR=14.5
28 3 ▶ return $ENV{FIND2PERL} if defined $ENV{FIND2PERL};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"FIND2PERL"} 0 3 3
29 my @candidates =
30 33 grep { -e }
31 33 map { catfile( $_, 'find2perl' ) }
32 dirname($Config{perlpath}),
33 split( /$Config{path_sep}/, $ENV{PATH} )
34 3 ;
35  
36 push @candidates, catfile( $ENV{PERL_LOCAL_LIB_ROOT}, 'bin', 'find2perl' )
37 3 ▶ if defined $ENV{PERL_LOCAL_LIB_ROOT};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"PERL_LOCAL_LIB_ROOT"} 0 3 3
38  
39 3 ▶ return defined $candidates[0] ? $candidates[0] : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $candidates[0] ? : 3 0 3
40 }
41  
42 3 my $find2perl = find_find2perl();
43 3 ▶die("This program needs the App::find2perl module.\n") unless -e $find2perl;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $find2perl 0 3 3
44  
45 # Temp files to capture find2perl output and error.
46 3 my ($out_fh, $out_file) = tempfile();
47 3 my ($err_fh, $err_file) = tempfile();
48  
49 3 ▶END {
Subroutine END: called CC=1 SCAR=0.0
50 3 unlink $out_file;
51 3 unlink $err_file;
52 }
53  
54 # Save STDOUT and STDERR. Redirect to temp files.
55  
56 3 ▶open SAVE_OUT, '>&', STDOUT or die "Can't save STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open SAVE_OUT, ">&", "STDOUT" or die "Can't save STDOUT: $!" 3 0 3
57 3 ▶die unless defined fileno SAVE_OUT;
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno SAVE_OUT 0 3 3
58  
59 3 ▶open STDOUT, '>&', $out_fh or die "Can't dup STDOUT to $out_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $out_fh or die "Can't dup STDOUT to ${out_file}: $!" 3 0 3
60 3 $|++, select $_ for select STDOUT;
61  
62 3 ▶open SAVE_ERR, '>&', STDERR or die "Can't save STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open SAVE_ERR, ">&", "STDERR" or die "Can't save STDERR: $!" 3 0 3
63 3 ▶die unless defined fileno SAVE_ERR;
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno SAVE_ERR 0 3 3
64  
65 3 ▶open STDERR, '>&', $err_fh or die "Can't dup STDERR to $err_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $err_fh or die "Can't dup STDERR to ${err_file}: $!" 3 0 3
66 3 $|++, select $_ for select STDERR;
67  
68 # Run find2perl to convert find command to Perl script.
69  
70 3 system $^X, $find2perl, @ARGV;
71  
72 # Check for errors.
73  
74 3 my $child_error = $?;
75 3 my $acm_min_error;
76  
77 3 ▶open STDERR, '>&', SAVE_ERR or die "Can't restore STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", "SAVE_ERR" or die "Can't restore STDERR: $!" 3 0 3
78  
79 3 ▶seek $err_fh, 0, 0 or die "Can't rewind $err_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $err_fh, 0, 0 or die "Can't rewind ${err_file}: $!" 3 0 3
80  
81 3 my $error = do { local $/; <$err_fh> };
82  
83 3 close $err_fh;
84  
85 3 ▶if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 3 3
86 0 ▶ if ($error =~ /^Unrecognized switch: -[acm]min\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^Unrecognized switch: -[acm]min\s*$/) { } 0 0 0
87 # Tried to use -amin, -cmin or -mmin, which find2perl doesn't
88 # support.
89 0 $acm_min_error++;
90  
91 # So change to -atime, -ctime or -mtime, and append an
92 # identifier to its argument (fortunately, find2perl does not
93 # validate the argument).
94 0 for my $i (0..$#ARGV) {
95 0 ▶ $ARGV[$i + 1] .= '-ppt-minutes'
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[$i] =~ s/^(-[acm])min$/$1time/ 0 0 0
96 if $ARGV[$i] =~ s/^(-[acm])min$/${1}time/;
97 }
98  
99 0 system $find2perl, @ARGV;
100 0 $child_error = $?;
101 } else {
102 0 warn $error;
103 }
104 }
105  
106 3 ▶die "Can't run $find2perl (wait status == $child_error)" if $child_error;
Branch: 1 branch
BranchTrueFalseTotal
if $child_error 0 3 3
107  
108 3 ▶die "Empty program" unless -s $out_fh && -s $out_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -s $out_fh and -s $out_file 0 3 3
Condition33%1/3
-s $out_fh and -s $out_file
!ll&&!rl&&r
003
MC/DC0%0/2
-s $out_fh and -s $out_file
-s $out_fh -s $out_file
Truth table33%1/3
A and B
A= -s $out_fhB= -s $out_file
ABresult
0X0
100
111
109  
110 # Get "find" Perl script from output.
111  
112 3 ▶seek $out_fh, 0, 0 or die "Can't rewind $out_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $out_fh, 0, 0 or die "Can't rewind ${out_file}: $!" 3 0 3
113  
114 3 my $program = do { local $/; <$out_fh> };
115  
116 3 close $out_fh;
117  
118 3 ▶open STDOUT, '>&', SAVE_OUT or die "Can't restore STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", "SAVE_OUT" or die "Can't restore STDOUT: $!" 3 0 3
119  
120 # Convert fake -atime, -ctime and -mtime conditionals, such as:
121 #
122 # (int(-C _) > 60-ppt-minutes) &&
123 # (int(-M _) < 15-ppt-minutes)
124 #
125 # To -amin, -cmin and -mmin conditionals, such as:
126 #
127 # (int(1440 * -C _) > 60) &&
128 # (int(1440 * -M _) < 15)
129 #
130 3 ▶if ($acm_min_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acm_min_error) 0 3 3
131 0 my $minutes_per_day = 24 * 60;
132 0 $program =~ s/(\bint\()(-[AMC] .*)-ppt-minutes/$1$minutes_per_day * $2/g;
133 }
134  
135 # Run "find" Perl script.
136  
137 3 ▶eval qq{
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine wanted: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
() = lstat $_ and -f _ and print "$main::name\n" 8 34 42
Condition100%3/3
() = lstat $_ and -f _
!ll&&!rl&&r
20148
MC/DC50%1/2
() = lstat $_ and -f _
() = lstat $_ -f _
Truth table66%2/3
A and B
A= () = lstat $_B= -f _
ABresult
0X0
100
111
138 no strict;
139 local \$^W = 0;
140 $program;
141 };
142  
143 0 ▶die "Can't compile and execute $find2perl: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
144  
145 0 exit 0;
146  
147 __END__
« bin/echo ↑ Summary blib/lib/ppt.pm »