| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::PTP; |
|
2
|
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
204601
|
use 5.022; |
|
|
15
|
|
|
|
|
145
|
|
|
4
|
15
|
|
|
15
|
|
74
|
use strict; |
|
|
15
|
|
|
|
|
28
|
|
|
|
15
|
|
|
|
|
265
|
|
|
5
|
15
|
|
|
15
|
|
69
|
use warnings; |
|
|
15
|
|
|
|
|
31
|
|
|
|
15
|
|
|
|
|
348
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
6784
|
use App::PTP::Args; |
|
|
15
|
|
|
|
|
56
|
|
|
|
15
|
|
|
|
|
668
|
|
|
8
|
15
|
|
|
15
|
|
112
|
use App::PTP::Commands 'warn_or_die_if_needed'; |
|
|
15
|
|
|
|
|
34
|
|
|
|
15
|
|
|
|
|
813
|
|
|
9
|
15
|
|
|
15
|
|
98
|
use App::PTP::Files; |
|
|
15
|
|
|
|
|
41
|
|
|
|
15
|
|
|
|
|
839
|
|
|
10
|
15
|
|
|
15
|
|
97
|
use Data::Dumper; |
|
|
15
|
|
|
|
|
32
|
|
|
|
15
|
|
|
|
|
622
|
|
|
11
|
15
|
|
|
15
|
|
101
|
use File::Find; |
|
|
15
|
|
|
|
|
79
|
|
|
|
15
|
|
|
|
|
676
|
|
|
12
|
15
|
|
|
15
|
|
91
|
use Safe; |
|
|
15
|
|
|
|
|
33
|
|
|
|
15
|
|
|
|
|
11888
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$Data::Dumper::Terse = 1; # Don't output variable names. |
|
17
|
|
|
|
|
|
|
$Data::Dumper::Sortkeys = 1; # Sort the content of the hash variables. |
|
18
|
|
|
|
|
|
|
$Data::Dumper::Useqq = 1; # Use double quote for string (better escaping). |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $safe = Safe->new(); |
|
21
|
|
|
|
|
|
|
$safe->deny_only(':subprocess', ':ownprocess', ':others', ':dangerous'); |
|
22
|
|
|
|
|
|
|
$safe->reval('use App::PTP::PerlEnv;'); |
|
23
|
|
|
|
|
|
|
$safe->reval('use File::Spec::Functions qw(:ALL);'); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# maybe_expand_dirs(filepath) |
|
26
|
|
|
|
|
|
|
# If filepath is a normal file, then returns it as, is. |
|
27
|
|
|
|
|
|
|
# If filepath does not exist, then terminates the program with an error. |
|
28
|
|
|
|
|
|
|
# If filepath is a directory and the $recursive option is not set then |
|
29
|
|
|
|
|
|
|
# terminates the program with an error, otherwise returns the list of all files |
|
30
|
|
|
|
|
|
|
# that it contains. |
|
31
|
|
|
|
|
|
|
sub maybe_expand_dirs { |
|
32
|
144
|
|
|
144
|
0
|
312
|
my ($f, $options) = @_; |
|
33
|
144
|
100
|
|
|
|
798
|
if (ref $f) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# This will be the $stdin_marker reference. |
|
35
|
121
|
50
|
|
|
|
399
|
if ($options->{in_place}) { |
|
36
|
0
|
|
|
|
|
0
|
die "Reading from STDIN is incompatible with the --in-place option.\n"; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
121
|
|
|
|
|
490
|
return $f; |
|
39
|
|
|
|
|
|
|
} elsif (not -e $f) { |
|
40
|
0
|
|
|
|
|
0
|
die "File does not exist: ${f}\n"; |
|
41
|
|
|
|
|
|
|
} elsif (-d _) { |
|
42
|
1
|
50
|
|
|
|
5
|
if (not $options->{recursive}) { |
|
43
|
0
|
|
|
|
|
0
|
die "Input is a directory (did you forget the -R option?): ${f}\n"; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
1
|
|
|
|
|
3
|
my @files; |
|
46
|
|
|
|
|
|
|
my $filter; |
|
47
|
1
|
50
|
|
|
|
4
|
if (defined $options->{input_filter}) { |
|
48
|
1
|
|
|
|
|
12
|
$filter = $safe->reval("sub { $options->{input_filter} }"); |
|
49
|
1
|
50
|
|
|
|
882
|
die "FATAL: Cannot wrap code for --input_filter: ${@}" if $@; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
find({ |
|
52
|
|
|
|
|
|
|
# Because of the follow option, a stat has already been done on the file, |
|
53
|
|
|
|
|
|
|
# so the '_' magic is guaranteed to work. |
|
54
|
|
|
|
|
|
|
wanted => sub { |
|
55
|
11
|
100
|
|
11
|
|
286
|
if (-f _) { |
|
56
|
9
|
|
|
|
|
16
|
my $f = $_; |
|
57
|
9
|
50
|
|
|
|
19
|
if (defined $filter) { |
|
58
|
9
|
|
|
|
|
32
|
my $r = $filter->(); |
|
59
|
9
|
100
|
66
|
|
|
4943
|
return if warn_or_die_if_needed( |
|
60
|
|
|
|
|
|
|
'Perl code failed while filtering input') || !$r; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
2
|
|
|
|
|
59
|
push @files, $f; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
} , |
|
65
|
1
|
|
|
|
|
175
|
follow => 1, |
|
66
|
|
|
|
|
|
|
no_chdir => 1, |
|
67
|
|
|
|
|
|
|
}, $f); |
|
68
|
1
|
|
|
|
|
30
|
return sort @files; |
|
69
|
|
|
|
|
|
|
} else { |
|
70
|
|
|
|
|
|
|
# We assume that everything else is a file. |
|
71
|
22
|
|
|
|
|
110
|
return $f; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub process_all { |
|
76
|
129
|
|
|
129
|
0
|
303
|
my ($inputs, $pipeline, $options, $stdin) = @_; |
|
77
|
129
|
|
|
|
|
512
|
$App::PTP::Commands::I_setter->set(1); |
|
78
|
129
|
100
|
|
|
|
334
|
if ($options->{merge}) { |
|
79
|
2
|
50
|
|
|
|
9
|
print "Merging all the inputs.\n" if $options->{debug_mode}; |
|
80
|
2
|
|
|
|
|
3
|
my $missing_final_separator = 0; |
|
81
|
2
|
|
|
|
|
4
|
my @content; |
|
82
|
2
|
|
|
|
|
6
|
for my $input (@$inputs) { |
|
83
|
4
|
|
|
|
|
11
|
my ($content, $missing_separator) = |
|
84
|
|
|
|
|
|
|
read_input($input, $options); |
|
85
|
4
|
|
|
|
|
15
|
push @content, @$content; |
|
86
|
4
|
|
|
|
|
10
|
$missing_final_separator = $missing_separator; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
App::PTP::Commands::process( |
|
89
|
2
|
|
|
|
|
11
|
\$App::PTP::Files::merged_marker, $pipeline, $options, \@content, |
|
90
|
|
|
|
|
|
|
$missing_final_separator); |
|
91
|
2
|
|
|
|
|
13
|
write_output(\$App::PTP::Files::merged_marker, \@content, |
|
92
|
|
|
|
|
|
|
$missing_final_separator, $options); |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
127
|
|
|
|
|
309
|
for my $file_name (@$inputs) { |
|
95
|
141
|
|
|
|
|
387
|
my ($content, $missing_final_separator) = |
|
96
|
|
|
|
|
|
|
read_input($file_name, $options, $stdin); |
|
97
|
|
|
|
|
|
|
# Note that process can modify the input $file_name variable. |
|
98
|
141
|
|
|
|
|
611
|
App::PTP::Commands::process($file_name, $pipeline, $options, $content, |
|
99
|
|
|
|
|
|
|
$missing_final_separator); |
|
100
|
139
|
|
|
|
|
2012
|
write_output($file_name, $content, $missing_final_separator, $options); |
|
101
|
139
|
|
|
|
|
556
|
$App::PTP::Commands::I_setter->inc(); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub Run { |
|
107
|
129
|
|
|
129
|
0
|
998
|
my ($stdin, $stdout, $stderr, $argv) = @_; |
|
108
|
129
|
|
|
|
|
330
|
select($stderr); # All debug output, this applies inside the safe too. |
|
109
|
129
|
|
|
|
|
575
|
my ($inputs, $pipeline, $options) = |
|
110
|
|
|
|
|
|
|
App::PTP::Args::parse_command_line($argv); |
|
111
|
|
|
|
|
|
|
|
|
112
|
129
|
50
|
|
|
|
412
|
if ($options->{debug_mode}) { |
|
113
|
129
|
|
|
|
|
855
|
print 'options = '.Dumper($options)."\n"; |
|
114
|
129
|
|
|
|
|
16747
|
print 'inputs = '.Dumper($inputs)."\n"; |
|
115
|
129
|
|
|
|
|
6320
|
print 'pipeline = '.Dumper($pipeline)."\n"; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
129
|
|
|
|
|
13157
|
@$inputs = map { maybe_expand_dirs($_, $options) } @$inputs; |
|
|
144
|
|
|
|
|
389
|
|
|
119
|
129
|
50
|
|
|
|
493
|
print 'expanded @inputs = '.Dumper($inputs)."\n" if $options->{debug_mode}; |
|
120
|
|
|
|
|
|
|
|
|
121
|
129
|
50
|
|
|
|
5939
|
return if $options->{abort}; |
|
122
|
|
|
|
|
|
|
|
|
123
|
129
|
|
|
|
|
542
|
init_global_output($options, $stdout); |
|
124
|
129
|
|
|
|
|
19722
|
process_all($inputs, $pipeline, $options, $stdin); |
|
125
|
127
|
|
|
|
|
438
|
close_global_output($options); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |