blib/script/find2perl

filter: Statementstmt 40.4% 97 / 240 Branchbran 37.9% 60 / 158 Conditioncond 17.6% 9 / 51 MC/DCmcdc 6.9% 2 / 29 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 36.2% 176 / 486 CC 7 SCAR 10.6
CC
7
Cov
37%
tab
5.1
n
3.0
BEGIN
1.0
CRAP 2.9
↑ Summary blib/lib/App/find2perl.pm »
1 #!/usr/local/bin/perl
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use vars qw/$statdone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use File::Spec::Functions 'curdir';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 my ($perlpath) = $Config{perlpath};
8 11 my $startperl = "#! $perlpath -w";
9  
10 sub tab ();
11 sub n ($$);
12 sub fileglob_to_re ($);
13 sub quote ($);
14  
15 11 my @roots = ();
16 11 ▶while ($ARGV[0] =~ /^[^-!(]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0] =~ /^[^-!(]/) 11 11 22
17 11 push(@roots, shift);
18 }
19 11 ▶@roots = (curdir()) unless @roots;
Branch: 1 branch
BranchTrueFalseTotal
unless @roots 0 11 11
20 11 for (@roots) { $_ = quote($_) }
21 11 my $roots = join(', ', @roots);
22  
23 11 my $find = "find";
24 11 my $indent_depth = 1;
25 11 my $stat = 'lstat';
26 11 my $decl = '';
27 11 my $flushall = '';
28 11 my $initfile = '';
29 11 my $initnewer = '';
30 11 my $out = '';
31 11 my $declaresubs = "sub wanted;\n";
32 11 my %init = ();
33 11 my ($follow_in_effect,$Skip_And) = (0,0);
34 11 my $print_needed = 1;
35  
36 11 ▶while (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 10 11 21
37 10 $_ = shift;
38 10 ▶ s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
Branch: 1 branch
BranchTrueFalseTotal
s/^-// or /^[()!]/ or die "Unrecognized switch: $_\n" 10 0 10
Condition33%1/3
s/^-// or /^[()!]/
l!l&&r!l&&!r
1000
MC/DC0%0/2
s/^-// or /^[()!]/
s/^-// /^[()!]/
Truth table33%1/3
A or B
A= s/^-//B= /^[()!]/
ABresult
1X1
011
000
39 10 ▶ if ($_ eq '(') {
Branch: 34 branches
BranchTrueFalseTotal
if ($_ eq '(') { } 0 10 10
elsif ($_ eq ')') { } 0 10 10
elsif ($_ eq 'follow') { } 0 10 10
elsif ($_ eq '!') { } 0 10 10
elsif (/^(i)?name$/) { } 2 8 10
elsif (/^(i)?path$/) { } 0 8 8
elsif ($_ eq 'perm') { } 0 8 8
elsif ($_ eq 'type') { } 2 6 8
elsif ($_ eq 'print') { } 0 6 6
elsif ($_ eq 'print0') { } 0 6 6
elsif ($_ eq 'fstype') { } 0 6 6
elsif ($_ eq 'user') { } 0 6 6
elsif ($_ eq 'group') { } 0 6 6
elsif ($_ eq 'nouser') { } 0 6 6
elsif ($_ eq 'nogroup') { } 0 6 6
elsif ($_ eq 'links') { } 1 5 6
elsif ($_ eq 'inum') { } 0 5 5
elsif ($_ eq 'size') { } 1 4 5
elsif ($_ eq 'atime') { } 0 4 4
elsif ($_ eq 'mtime') { } 2 2 4
elsif ($_ eq 'ctime') { } 0 2 2
elsif ($_ eq 'amin') { } 2 0 2
elsif ($_ eq 'mmin') { } 0 0 0
elsif ($_ eq 'cmin') { } 0 0 0
elsif ($_ eq 'exec') { } 0 0 0
elsif ($_ eq 'ok') { } 0 0 0
elsif ($_ eq 'prune') { } 0 0 0
elsif ($_ eq 'xdev') { } 0 0 0
elsif ($_ eq 'newer') { } 0 0 0
elsif ($_ eq 'eval') { } 0 0 0
elsif ($_ eq 'depth') { } 0 0 0
elsif ($_ eq 'ls') { } 0 0 0
elsif ($_ eq 'tar') { } 0 0 0
elsif (/^(n?)cpio\z/) { } 0 0 0
40 0 $out .= tab . "(\n";
41 0 $indent_depth++;
42 0 next;
43 } elsif ($_ eq ')') {
44 0 --$indent_depth;
45 0 $out .= tab . ")";
46 } elsif ($_ eq 'follow') {
47 0 $follow_in_effect= 1;
48 0 $stat = 'stat';
49 0 $Skip_And= 1;
50 } elsif ($_ eq '!') {
51 0 $out .= tab . "!";
52 0 next;
53 } elsif (/^(i)?name$/) {
54 2 $out .= tab . '/' . fileglob_to_re(shift) . "/s$1";
55 } elsif (/^(i)?path$/) {
56 0 $out .= tab . '$File::Find::name =~ /' . fileglob_to_re(shift) . "/s$1";
57 } elsif ($_ eq 'perm') {
58 0 my $onum = shift;
59 0 ▶ $onum =~ /^-?[0-7]+$/
Branch: 1 branch
BranchTrueFalseTotal
$onum =~ /^-?[0-7]+$/ or die "Malformed -perm argument: $onum\n" 0 0 0
60 || die "Malformed -perm argument: $onum\n";
61 0 $out .= tab;
62 0 ▶ if ($onum =~ s/^-//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onum =~ s/^-//) { } 0 0 0
63 0 $onum = sprintf("0%o", oct($onum) & 07777);
64 0 $out .= "((\$mode & $onum) == $onum)";
65 } else {
66 0 $onum =~ s/^0*/0/;
67 0 $out .= "((\$mode & 0777) == $onum)";
68 }
69 } elsif ($_ eq 'type') {
70 2 (my $filetest = shift) =~ tr/s/S/;
71 2 $out .= tab . "-$filetest _";
72 } elsif ($_ eq 'print') {
73 0 $out .= tab . 'print("$name\n")';
74 0 $print_needed = 0;
75 } elsif ($_ eq 'print0') {
76 0 $out .= tab . 'print("$name\0")';
77 0 $print_needed = 0;
78 } elsif ($_ eq 'fstype') {
79 0 my $type = shift;
80 0 $out .= tab;
81 0 ▶ if ($type eq 'nfs') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'nfs') { } 0 0 0
82 0 $out .= '($dev < 0)';
83 } else {
84 0 $out .= '($dev >= 0)'; #XXX
85 }
86 } elsif ($_ eq 'user') {
87 0 my $uname = shift;
88 0 $out .= tab . "(\$uid == \$uid{'$uname'})";
89 0 $init{user} = 1;
90 } elsif ($_ eq 'group') {
91 0 my $gname = shift;
92 0 $out .= tab . "(\$gid == \$gid{'$gname'})";
93 0 $init{group} = 1;
94 } elsif ($_ eq 'nouser') {
95 0 $out .= tab . '!exists $uid{$uid}';
96 0 $init{user} = 1;
97 } elsif ($_ eq 'nogroup') {
98 0 $out .= tab . '!exists $gid{$gid}';
99 0 $init{group} = 1;
100 } elsif ($_ eq 'links') {
101 1 $out .= tab . n('$nlink', shift);
102 } elsif ($_ eq 'inum') {
103 0 $out .= tab . n('$ino', shift);
104 } elsif ($_ eq 'size') {
105 1 $_ = shift;
106 1 my $n = 'int(((-s _) + 511) / 512)';
107 1 ▶ if (s/c\z//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/c\z//) { } 1 0 1
elsif (s/k\z//) { } 0 0 0
108 1 $n = 'int(-s _)';
109 } elsif (s/k\z//) {
110 0 $n = 'int(((-s _) + 1023) / 1024)';
111 }
112 1 $out .= tab . n($n, $_);
113 } elsif ($_ eq 'atime') {
114 0 $out .= tab . n('int(-A _)', shift);
115 } elsif ($_ eq 'mtime') {
116 2 $out .= tab . n('int(-M _)', shift);
117 } elsif ($_ eq 'ctime') {
118 0 $out .= tab . n('int(-C _)', shift);
119 } elsif ($_ eq 'amin') {
120 2 $out .= tab . n('int(1440 * -A _)', shift);
121 } elsif ($_ eq 'mmin') {
122 0 $out .= tab . n('int(1440 * -M _)', shift);
123 } elsif ($_ eq 'cmin') {
124 0 $out .= tab . n('int(1440 * -C _)', shift);
125 } elsif ($_ eq 'exec') {
126 0 my @cmd = ();
127 0 ▶ while (@ARGV && $ARGV[0] ne ';')
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] ne ";") 0 0 0
Condition0%0/3
@ARGV and $ARGV[0] ne ";"
!ll&&!rl&&r
000
MC/DC0%0/2
@ARGV and $ARGV[0] ne ";"
@ARGV $ARGV[0] ne ";"
Truth table0%0/3
A and B
A= @ARGVB= $ARGV[0] ne ";"
ABresult
0X0
100
111
128 0 { push(@cmd, shift) }
129 0 shift;
130 0 $out .= tab;
131 0 ▶ if ($cmd[0] =~m#^(?:(?:/usr)?/bin/)?rm$#
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$] and $cmd[$#cmd] eq '{}' and @cmd == 2 || @cmd == 3 && $cmd[1] eq '-f') { } 0 0 0
Condition0%0/12
$cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$] and $cmd[$#cmd] eq "{}" and @cmd == 2 || @cmd == 3 && $cmd[1] eq "-f"
!ll&&!rl&&r
000
$cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$] and $cmd[$#cmd] eq "{}"
!ll&&!rl&&r
000
@cmd == 2 or @cmd == 3 and $cmd[1] eq "-f"
l!l&&r!l&&!r
000
@cmd == 3 and $cmd[1] eq "-f"
!ll&&!rl&&r
000
MC/DC0%0/5
$cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$] and $cmd[$#cmd] eq "{}" and @cmd == 2 || @cmd == 3 && $cmd[1] eq "-f"
$cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$] $cmd[$#cmd] eq "{}" @cmd == 2 @cmd == 3 $cmd[1] eq "-f"
Truth table0%0/6
A and B and C or D and E
A= $cmd[0] =~ m[^(?:(?:/usr)?/bin/)?rm$]B= $cmd[$#cmd] eq "{}"C= @cmd == 2D= @cmd == 3E= $cmd[1] eq "-f"
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
132 && $cmd[$#cmd] eq '{}'
133 && (@cmd == 2 || (@cmd == 3 && $cmd[1] eq '-f'))) {
134 0 ▶ if (@cmd == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@cmd == 2) { } 0 0 0
elsif (not @ARGV) { } 0 0 0
135 0 $out .= '(unlink($_) || warn "$name: $!\n")';
136 } elsif (!@ARGV) {
137 0 $out .= 'unlink($_)';
138 } else {
139 0 $out .= '(unlink($_) || 1)';
140 }
141 } else {
142 0 for (@cmd)
143 0 { s/'/\\'/g }
144 0 { local $" = "','"; $out .= "doexec(0, '@cmd')"; }
145 0 $declaresubs .= "sub doexec (\$\@);\n";
146 0 $init{doexec} = 1;
147 }
148 0 $print_needed = 0;
149 } elsif ($_ eq 'ok') {
150 0 my @cmd = ();
151 0 ▶ while (@ARGV && $ARGV[0] ne ';')
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV and $ARGV[0] ne ";") 0 0 0
Condition0%0/3
@ARGV and $ARGV[0] ne ";"
!ll&&!rl&&r
000
MC/DC0%0/2
@ARGV and $ARGV[0] ne ";"
@ARGV $ARGV[0] ne ";"
Truth table0%0/3
A and B
A= @ARGVB= $ARGV[0] ne ";"
ABresult
0X0
100
111
152 0 { push(@cmd, shift) }
153 0 shift;
154 0 $out .= tab;
155 0 for (@cmd)
156 0 { s/'/\\'/g }
157 0 { local $" = "','"; $out .= "doexec(1, '@cmd')"; }
158 0 $declaresubs .= "sub doexec (\$\@);\n";
159 0 $init{doexec} = 1;
160 0 $print_needed = 0;
161 } elsif ($_ eq 'prune') {
162 0 $out .= tab . '($File::Find::prune = 1)';
163 } elsif ($_ eq 'xdev') {
164 0 $out .= tab . '!($File::Find::prune |= ($dev != $File::Find::topdev))'
165 ;
166 } elsif ($_ eq 'newer') {
167 0 my $file = shift;
168 0 my $newername = 'AGE_OF' . $file;
169 0 $newername =~ s/\W/_/g;
170 0 $newername = '$' . $newername;
171 0 $out .= tab . "(-M _ < $newername)";
172 0 $initnewer .= "my $newername = -M " . quote($file) . ";\n";
173 } elsif ($_ eq 'eval') {
174 0 my $prog = shift;
175 0 $prog =~ s/'/\\'/g;
176 0 $out .= tab . "eval {$prog}";
177 0 $print_needed = 0;
178 } elsif ($_ eq 'depth') {
179 0 $find = 'finddepth';
180 0 next;
181 } elsif ($_ eq 'ls') {
182 0 $out .= tab . "ls";
183 0 $declaresubs .= "sub ls ();\n";
184 0 $init{ls} = 1;
185 0 $print_needed = 0;
186 } elsif ($_ eq 'tar') {
187 0 ▶ die "-tar must have a filename argument\n" unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 0 0
188 0 my $file = shift;
189 0 my $fh = 'FH' . $file;
190 0 $fh =~ s/\W/_/g;
191 0 $out .= tab . "tar(*$fh, \$name)";
192 0 $flushall .= "tflushall;\n";
193 0 $declaresubs .= "sub tar;\nsub tflushall ();\n";
194 0 $initfile .= "open($fh, " . quote('> ' . $file) .
195 qq{) || die "Can't open $fh: \$!\\n";\n};
196 0 $init{tar} = 1;
197 } elsif (/^(n?)cpio\z/) {
198 0 ▶ die "-$_ must have a filename argument\n" unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 0 0
199 0 my $file = shift;
200 0 my $fh = 'FH' . $file;
201 0 $fh =~ s/\W/_/g;
202 0 $out .= tab . "cpio(*$fh, \$name, '$1')";
203 0 $find = 'finddepth';
204 0 $flushall .= "cflushall;\n";
205 0 $declaresubs .= "sub cpio;\nsub cflushall ();\n";
206 0 $initfile .= "open($fh, " . quote('> ' . $file) .
207 qq{) || die "Can't open $fh: \$!\\n";\n};
208 0 $init{cpio} = 1;
209 } else {
210 0 die "Unrecognized switch: -$_\n";
211 }
212  
213 10 ▶ if (@ARGV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ARGV) 0 10 10
214 0 ▶ if ($ARGV[0] eq '-o') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0] eq '-o') { } 0 0 0
215 0 { local($statdone) = 1; $out .= "\n" . tab . "||\n"; }
216 0 ▶ $statdone = 0 if $indent_depth == 1 && exists $init{delayedstat};
Branch: 1 branch
BranchTrueFalseTotal
if $indent_depth == 1 and exists $init{"delayedstat"} 0 0 0
Condition0%0/3
$indent_depth == 1 and exists $init{"delayedstat"}
!ll&&!rl&&r
000
MC/DC0%0/2
$indent_depth == 1 and exists $init{"delayedstat"}
$indent_depth == 1 exists $init{"delayedstat"}
Truth table0%0/3
A and B
A= $indent_depth == 1B= exists $init{"delayedstat"}
ABresult
0X0
100
111
217 0 $init{saw_or} = 1;
218 0 shift;
219 } else {
220 0 ▶ $out .= " &&" unless $Skip_And || $ARGV[0] eq ')';
Branch: 1 branch
BranchTrueFalseTotal
unless $Skip_And or $ARGV[0] eq ")" 0 0 0
Condition0%0/3
$Skip_And or $ARGV[0] eq ")"
l!l&&r!l&&!r
000
MC/DC0%0/2
$Skip_And or $ARGV[0] eq ")"
$Skip_And $ARGV[0] eq ")"
Truth table0%0/3
A or B
A= $Skip_AndB= $ARGV[0] eq ")"
ABresult
1X1
011
000
221 0 $out .= "\n";
222 0 ▶ shift if $ARGV[0] eq '-a';
Branch: 1 branch
BranchTrueFalseTotal
if $ARGV[0] eq "-a" 0 0 0
223 }
224 }
225 }
226  
227 11 ▶if ($print_needed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print_needed) 11 0 11
228 11 my $t = tab;
229 11 ▶ if ($t !~ /&&\s*$/) { $t .= '&& ' }
Branch: 1 branch
BranchTrueFalseTotal
unless ($t =~ /&&\s*$/) 10 1 11
230 11 $out .= "\n" . $t . 'print("$name\n")';
231 }
232  
233  
234 11 print <<"END";
235 $startperl
236 eval 'exec $perlpath -S \$0 \${1+"\$@"}'
237 if 0; #\$running_under_some_shell
238  
239 use strict;
240 use File::Find ();
241  
242 # Set the variable \$File::Find::dont_use_nlink if you're using AFS,
243 # since AFS cheats.
244  
245 # for the convenience of &wanted calls, including -eval statements:
246 use vars qw/*name *dir *prune/;
247 *name = *File::Find::name;
248 *dir = *File::Find::dir;
249 *prune = *File::Find::prune;
250  
251 $declaresubs
252  
253 END
254  
255 11 ▶if (exists $init{doexec}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"doexec"}) 0 11 11
256 0 print <<'END';
257 use Cwd ();
258 my $cwd = Cwd::cwd();
259  
260 END
261 }
262  
263 11 ▶if (exists $init{ls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"ls"}) 0 11 11
264 0 print <<'END';
265 my @rwx = qw(--- --x -w- -wx r-- r-x rw- rwx);
266 my @moname = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
267  
268 END
269 }
270  
271 11 ▶if (exists $init{user} || exists $init{ls} || exists $init{tar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"user"} or exists $init{"ls"} or exists $init{"tar"}) 0 11 11
Condition33%2/6
exists $init{"user"} or exists $init{"ls"} or exists $init{"tar"}
l!l&&r!l&&!r
0011
exists $init{"user"} or exists $init{"ls"}
l!l&&r!l&&!r
0011
MC/DC0%0/3
exists $init{"user"} or exists $init{"ls"} or exists $init{"tar"}
exists $init{"user"} exists $init{"ls"} exists $init{"tar"}
Truth table25%1/4
A or B or C
A= exists $init{"user"}B= exists $init{"ls"}C= exists $init{"tar"}
ABCresult
1XX1
01X1
0011
0000
272 0 print "my (%uid, %user);\n";
273 0 print "while (my (\$name, \$pw, \$uid) = getpwent) {\n";
274 print ' $uid{$name} = $uid{$uid} = $uid;', "\n"
275 0 ▶ if exists $init{user};
Branch: 1 branch
BranchTrueFalseTotal
if exists $init{"user"} 0 0 0
276 print ' $user{$uid} = $name unless exists $user{$uid};', "\n"
277 0 ▶ if exists $init{ls} || exists $init{tar};
Branch: 1 branch
BranchTrueFalseTotal
if exists $init{"ls"} or exists $init{"tar"} 0 0 0
Condition0%0/3
exists $init{"ls"} or exists $init{"tar"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $init{"ls"} or exists $init{"tar"}
exists $init{"ls"} exists $init{"tar"}
Truth table0%0/3
A or B
A= exists $init{"ls"}B= exists $init{"tar"}
ABresult
1X1
011
000
278 0 print "}\n\n";
279 }
280  
281 11 ▶if (exists $init{group} || exists $init{ls} || exists $init{tar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"group"} or exists $init{"ls"} or exists $init{"tar"}) 0 11 11
Condition33%2/6
exists $init{"group"} or exists $init{"ls"} or exists $init{"tar"}
l!l&&r!l&&!r
0011
exists $init{"group"} or exists $init{"ls"}
l!l&&r!l&&!r
0011
MC/DC0%0/3
exists $init{"group"} or exists $init{"ls"} or exists $init{"tar"}
exists $init{"group"} exists $init{"ls"} exists $init{"tar"}
Truth table25%1/4
A or B or C
A= exists $init{"group"}B= exists $init{"ls"}C= exists $init{"tar"}
ABCresult
1XX1
01X1
0011
0000
282 0 print "my (%gid, %group);\n";
283 0 print "while (my (\$name, \$pw, \$gid) = getgrent) {\n";
284 print ' $gid{$name} = $gid{$gid} = $gid;', "\n"
285 0 ▶ if exists $init{group};
Branch: 1 branch
BranchTrueFalseTotal
if exists $init{"group"} 0 0 0
286 print ' $group{$gid} = $name unless exists $group{$gid};', "\n"
287 0 ▶ if exists $init{ls} || exists $init{tar};
Branch: 1 branch
BranchTrueFalseTotal
if exists $init{"ls"} or exists $init{"tar"} 0 0 0
Condition0%0/3
exists $init{"ls"} or exists $init{"tar"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $init{"ls"} or exists $init{"tar"}
exists $init{"ls"} exists $init{"tar"}
Truth table0%0/3
A or B
A= exists $init{"ls"}B= exists $init{"tar"}
ABresult
1X1
011
000
288 0 print "}\n\n";
289 }
290  
291 11 ▶print $initnewer, "\n" if $initnewer ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $initnewer ne "" 0 11 11
292 11 ▶print $initfile, "\n" if $initfile ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $initfile ne "" 0 11 11
293 11 $flushall .= "exit;\n";
294 11 ▶if (exists $init{declarestat}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"declarestat"}) 9 2 11
295 9 $out = <<'END' . $out;
296 my ($dev,$ino,$mode,$nlink,$uid,$gid);
297  
298 END
299 }
300  
301 11 ▶if ( $follow_in_effect ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($follow_in_effect) { } 0 11 11
302 0 $out =~ s/lstat\(\$_\)/lstat(_)/;
303 0 print <<"END";
304 $decl
305 # Traverse desired filesystems
306 File::Find::$find( {wanted => \\&wanted, follow => 1}, $roots);
307 $flushall
308  
309 sub wanted {
310 $out;
311 }
312  
313 END
314 } else {
315 11 print <<"END";
316 $decl
317 # Traverse desired filesystems
318 File::Find::$find({wanted => \\&wanted}, $roots);
319 $flushall
320  
321 sub wanted {
322 $out;
323 }
324  
325 END
326 }
327  
328 11 ▶if (exists $init{doexec}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"doexec"}) 0 11 11
329 0 print <<'END';
330  
331 sub doexec ($@) {
332 my $ok = shift;
333 my @command = @_; # copy so we don't try to s/// aliases to constants
334 for my $word (@command)
335 { $word =~ s#{}#$name#g }
336 if ($ok) {
337 my $old = select(STDOUT);
338 $| = 1;
339 print "@command";
340 select($old);
341 return 0 unless <STDIN> =~ /^y/;
342 }
343 chdir $cwd; #sigh
344 system @command;
345 chdir $File::Find::dir;
346 return !$?;
347 }
348  
349 END
350 }
351  
352 11 ▶if (exists $init{ls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"ls"}) 0 11 11
353 0 print <<'INTRO', <<"SUB", <<'END';
354  
355 sub sizemm {
356 my $rdev = shift;
357 sprintf("%3d, %3d", ($rdev >> 8) & 0xff, $rdev & 0xff);
358 }
359  
360 sub ls () {
361 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
362 INTRO
363 \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
364 SUB
365 my $pname = $name;
366  
367 $blocks
368 or $blocks = int(($size + 1023) / 1024);
369  
370 my $perms = $rwx[$mode & 7];
371 $mode >>= 3;
372 $perms = $rwx[$mode & 7] . $perms;
373 $mode >>= 3;
374 $perms = $rwx[$mode & 7] . $perms;
375 substr($perms, 2, 1) =~ tr/-x/Ss/ if -u _;
376 substr($perms, 5, 1) =~ tr/-x/Ss/ if -g _;
377 substr($perms, 8, 1) =~ tr/-x/Tt/ if -k _;
378 if (-f _) { $perms = '-' . $perms; }
379 elsif (-d _) { $perms = 'd' . $perms; }
380 elsif (-l _) { $perms = 'l' . $perms; $pname .= ' -> ' . readlink($_); }
381 elsif (-c _) { $perms = 'c' . $perms; $size = sizemm($rdev); }
382 elsif (-b _) { $perms = 'b' . $perms; $size = sizemm($rdev); }
383 elsif (-p _) { $perms = 'p' . $perms; }
384 elsif (-S _) { $perms = 's' . $perms; }
385 else { $perms = '?' . $perms; }
386  
387 my $user = $user{$uid} || $uid;
388 my $group = $group{$gid} || $gid;
389  
390 my ($sec,$min,$hour,$mday,$mon,$timeyear) = localtime($mtime);
391 if (-M _ > 365.25 / 2) {
392 $timeyear += 1900;
393 } else {
394 $timeyear = sprintf("%02d:%02d", $hour, $min);
395 }
396  
397 printf "%5lu %4ld %-10s %3d %-8s %-8s %8s %s %2d %5s %s\n",
398 $ino,
399 $blocks,
400 $perms,
401 $nlink,
402 $user,
403 $group,
404 $size,
405 $moname[$mon],
406 $mday,
407 $timeyear,
408 $pname;
409 1;
410 }
411  
412 END
413 }
414  
415  
416 11 ▶if (exists $init{cpio} || exists $init{tar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"cpio"} or exists $init{"tar"}) 0 11 11
Condition33%1/3
exists $init{"cpio"} or exists $init{"tar"}
l!l&&r!l&&!r
0011
MC/DC0%0/2
exists $init{"cpio"} or exists $init{"tar"}
exists $init{"cpio"} exists $init{"tar"}
Truth table33%1/3
A or B
A= exists $init{"cpio"}B= exists $init{"tar"}
ABresult
1X1
011
000
417 0 print <<'END';
418  
419 my %blocks = ();
420  
421 sub flush {
422 my ($fh, $varref, $blksz) = @_;
423  
424 while (length($$varref) >= $blksz) {
425 no strict qw/refs/;
426 syswrite($fh, $$varref, $blksz);
427 substr($$varref, 0, $blksz) = '';
428 ++$blocks{$fh};
429 }
430 }
431  
432 END
433 }
434  
435  
436 11 ▶if (exists $init{cpio}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"cpio"}) 0 11 11
437 0 print <<'INTRO', <<"SUB", <<'END';
438  
439 my %cpout = ();
440 my %nc = ();
441  
442 sub cpio {
443 my ($fh, $fname, $nc) = @_;
444 my $text = '';
445 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
446 $atime,$mtime,$ctime,$blksize,$blocks);
447 local (*IN);
448  
449 if ( ! defined $fname ) {
450 $fname = 'TRAILER!!!';
451 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
452 $atime,$mtime,$ctime,$blksize,$blocks) = (0) x 13;
453 } else {
454 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
455 INTRO
456 \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
457 SUB
458 if (-f _) {
459 open(IN, "./$_\0") || do {
460 warn "Couldn't open $fname: $!\n";
461 return;
462 }
463 } else {
464 $text = readlink($_);
465 $size = 0 unless defined $text;
466 }
467 }
468  
469 $fname =~ s#^\./##;
470 $nc{$fh} = $nc;
471 if ($nc eq 'n') {
472 $cpout{$fh} .=
473 sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
474 070707,
475 $dev & 0777777,
476 $ino & 0777777,
477 $mode & 0777777,
478 $uid & 0777777,
479 $gid & 0777777,
480 $nlink & 0777777,
481 $rdev & 0177777,
482 $mtime,
483 length($fname)+1,
484 $size,
485 $fname);
486 } else {
487 $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
488 $cpout{$fh} .= pack("SSSSSSSSLSLa*",
489 070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
490 length($fname)+1, $size,
491 $fname . (length($fname) & 1 ? "\0" : "\0\0"));
492 }
493  
494 if ($text ne '') {
495 $cpout{$fh} .= $text;
496 } elsif ($size) {
497 my $l;
498 flush($fh, \$cpout{$fh}, 5120)
499 while ($l = length($cpout{$fh})) >= 5120;
500 while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
501 flush($fh, \$cpout{$fh}, 5120);
502 $l = length($cpout{$fh});
503 }
504 close IN;
505 }
506 }
507  
508 sub cflushall () {
509 for my $fh (keys %cpout) {
510 cpio($fh, undef, $nc{$fh});
511 $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
512 flush($fh, \$cpout{$fh}, 5120);
513 print $blocks{$fh} * 10, " blocks\n";
514 }
515 }
516  
517 END
518 }
519  
520 11 ▶if (exists $init{tar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{"tar"}) 0 11 11
521 0 print <<'INTRO', <<"SUB", <<'END';
522  
523 my %tarout = ();
524 my %linkseen = ();
525  
526 sub tar {
527 my ($fh, $fname) = @_;
528 my $prefix = '';
529 my $typeflag = '0';
530 my $linkname;
531 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
532 INTRO
533 \$atime,\$mtime,\$ctime,\$blksize,\$blocks) = $stat(_);
534 SUB
535 local (*IN);
536  
537 if ($nlink > 1) {
538 if ($linkname = $linkseen{$fh, $dev, $ino}) {
539 if (length($linkname) > 100) {
540 warn "$0: omitting file with linkname ",
541 "too long for tar output: $linkname\n";
542 return;
543 }
544 $typeflag = '1';
545 $size = 0;
546 } else {
547 $linkseen{$fh, $dev, $ino} = $fname;
548 }
549 }
550 if ($typeflag eq '0') {
551 if (-f _) {
552 open(IN, "./$_\0") || do {
553 warn "Couldn't open $fname: $!\n";
554 return;
555 }
556 } else {
557 $linkname = readlink($_);
558 if (defined $linkname) { $typeflag = '2' }
559 elsif (-c _) { $typeflag = '3' }
560 elsif (-b _) { $typeflag = '4' }
561 elsif (-d _) { $typeflag = '5' }
562 elsif (-p _) { $typeflag = '6' }
563 }
564 }
565  
566 if (length($fname) > 100) {
567 ($prefix, $fname) = ($fname =~ m#\A(.*?)/(.{,100})\Z(?!\n)#);
568 if (!defined($fname) || length($prefix) > 155) {
569 warn "$0: omitting file with name too long for tar output: ",
570 $fname, "\n";
571 return;
572 }
573 }
574  
575 $size = 0 if $typeflag ne '0';
576 my $header = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155",
577 $fname,
578 sprintf("%7o ", $mode & 0777),
579 sprintf("%7o ", $uid & 0777777),
580 sprintf("%7o ", $gid & 0777777),
581 sprintf("%11o ", $size),
582 sprintf("%11o ", $mtime),
583 ' 'x8,
584 $typeflag,
585 defined $linkname ? $linkname : '',
586 "ustar\0",
587 "00",
588 $user{$uid},
589 $group{$gid},
590 ($rdev >> 8) & 0xff,
591 $rdev & 0xff,
592 $prefix,
593 );
594 substr($header, 148, 8) = sprintf("%7o ", unpack("%16C*", $header));
595 my $l = length($header) % 512;
596 $tarout{$fh} .= $header;
597 $tarout{$fh} .= "\0" x (512 - $l) if $l;
598  
599 if ($size) {
600 flush($fh, \$tarout{$fh}, 10240)
601 while ($l = length($tarout{$fh})) >= 10240;
602 while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
603 my $slop = length($tarout{$fh}) % 512;
604 $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
605 flush($fh, \$tarout{$fh}, 10240);
606 $l = length($tarout{$fh});
607 }
608 close IN;
609 }
610 }
611  
612 sub tflushall () {
613 my $len;
614 for my $fh (keys %tarout) {
615 $len = 10240 - length($tarout{$fh});
616 $len += 10240 if $len < 1024;
617 $tarout{$fh} .= "\0" x $len;
618 flush($fh, \$tarout{$fh}, 10240);
619 }
620 }
621  
622 END
623 }
624  
625 11 exit;
626  
627 ############################################################################
628  
629 21 ▶sub tab () {
Subroutine tab: called CC=5 SCAR=16.2
630 21 my $tabstring;
631  
632 21 $tabstring = "\t" x ($indent_depth/2) . ' ' x ($indent_depth%2 * 4);
633 21 ▶ if (!$statdone) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($main::statdone) 13 8 21
634 13 ▶ if ($_ =~ /^(?:name|print|prune|exec|ok|\(|\))/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^(?:name|print|prune|exec|ok|\(|\))/) { } 4 9 13
635 4 $init{delayedstat} = 1;
636 } else {
637 9 my $statcall = '(($dev,$ino,$mode,$nlink,$uid,$gid) = '
638 . $stat . '($_))';
639 9 ▶ if (exists $init{saw_or}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $init{'saw_or'}) { } 0 9 9
640 0 $tabstring .= "(\$nlink || $statcall) &&\n" . $tabstring;
641 } else {
642 9 $tabstring .= "$statcall &&\n" . $tabstring;
643 }
644 9 $statdone = 1;
645 9 $init{declarestat} = 1;
646 }
647 }
648 21 ▶ $tabstring =~ s/^\s+/ / if $out =~ /!$/;
Branch: 1 branch
BranchTrueFalseTotal
if $out =~ /!$/ 0 21 21
649 21 $tabstring;
650 }
651  
652 2 ▶sub fileglob_to_re ($) {
Subroutine fileglob_to_re: called CC=1 SCAR=0.0
653 2 my $x = shift;
654 2 $x =~ s#([./^\$()+])#\\$1#g;
655 2 $x =~ s#\*#.*#g;
656 2 $x =~ s#\?#.#g;
657 2 "^$x\\z";
658 }
659  
660 6 ▶sub n ($$) {
Subroutine n: called CC=3 SCAR=11.0
661 6 my ($pre, $n) = @_;
662 6 ▶ $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
Branch: 1 branch
BranchTrueFalseTotal
$n =~ s/^-/< / or $n =~ s/^\+/> / or $n =~ s/^/== / 4 2 6
Condition100%3/3
$n =~ s/^-/< / or $n =~ s/^\+/> /
l!l&&r!l&&!r
222
MC/DC100%2/2
$n =~ s/^-/< / or $n =~ s/^\+/> /
$n =~ s/^-/< / $n =~ s/^\+/> /
Truth table100%3/3
A or B
A= $n =~ s/^-/< /B= $n =~ s/^\+/> /
ABresult
1X1
011
000
663 6 $n =~ s/ 0*(\d)/ $1/;
664 6 "($pre $n)";
665 }
666  
667 11 ▶sub quote ($) {
Subroutine quote: called CC=1 SCAR=0.0
668 11 my $string = shift;
669 11 $string =~ s/\\/\\\\/g;
670 11 $string =~ s/'/\\'/g;
671 11 "'$string'";
672 }
673  
674 __END__
↑ Summary blib/lib/App/find2perl.pm »