line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Compile::Internal; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
956341
|
use warnings; |
|
24
|
|
|
|
|
189
|
|
|
24
|
|
|
|
|
846
|
|
4
|
24
|
|
|
24
|
|
140
|
use strict; |
|
24
|
|
|
|
|
44
|
|
|
24
|
|
|
|
|
483
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
7156
|
use version; our $VERSION = version->declare("v3.2.2"); |
|
24
|
|
|
|
|
31744
|
|
|
24
|
|
|
|
|
160
|
|
7
|
24
|
|
|
24
|
|
2304
|
use File::Find; |
|
24
|
|
|
|
|
57
|
|
|
24
|
|
|
|
|
1991
|
|
8
|
24
|
|
|
24
|
|
163
|
use File::Spec; |
|
24
|
|
|
|
|
49
|
|
|
24
|
|
|
|
|
810
|
|
9
|
24
|
|
|
24
|
|
2780
|
use Test::Builder; |
|
24
|
|
|
|
|
243742
|
|
|
24
|
|
|
|
|
502
|
|
10
|
24
|
|
|
24
|
|
12324
|
use IPC::Open3 (); |
|
24
|
|
|
|
|
97315
|
|
|
24
|
|
|
|
|
25094
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Test::Compile::Internal - Assert that your Perl files compile OK. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Test::Compile::Internal; |
19
|
|
|
|
|
|
|
my $test = Test::Compile::Internal->new(); |
20
|
|
|
|
|
|
|
$test->all_files_ok(); |
21
|
|
|
|
|
|
|
$test->done_testing(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
C is an object oriented tool for testing whether your |
26
|
|
|
|
|
|
|
perl files compile. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
It is primarily to provide the inner workings of C, but it can |
29
|
|
|
|
|
|
|
also be used directly to test a CPAN distribution. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 METHODS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item C |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
A basic constructor, nothing special. |
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub new { |
41
|
25
|
|
|
25
|
1
|
2867
|
my ($class, %self) = @_; |
42
|
25
|
|
|
|
|
69
|
my $self = \%self; |
43
|
|
|
|
|
|
|
|
44
|
25
|
|
|
|
|
182
|
$self->{test} = Test::Builder->new(); |
45
|
|
|
|
|
|
|
|
46
|
25
|
|
|
|
|
305
|
bless ($self, $class); |
47
|
25
|
|
|
|
|
82
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item C |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Looks for perl files and tests them all for compilation errors. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
If C<@dirs> is defined then it is taken as an array of files or directories to be |
55
|
|
|
|
|
|
|
searched for perl files, otherwise it searches the default locations you'd expect to find |
56
|
|
|
|
|
|
|
perl files in a perl module - see L and L |
57
|
|
|
|
|
|
|
for details. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
sub all_files_ok { |
61
|
4
|
|
|
4
|
1
|
623
|
my ($self, @dirs) = @_; |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
18
|
my $pm_ok = $self->all_pm_files_ok(@dirs); |
64
|
4
|
|
|
|
|
75
|
my $pl_ok = $self->all_pl_files_ok(@dirs); |
65
|
|
|
|
|
|
|
|
66
|
4
|
100
|
66
|
|
|
116
|
if ( $pm_ok && $pl_ok ) { |
67
|
3
|
|
|
|
|
341
|
return 1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item C |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Checks all the perl module files it can find for compilation errors. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
If C<@dirs> is defined then it is taken as an array of files or directories to |
77
|
|
|
|
|
|
|
be searched for perl files, otherwise it searches some default locations |
78
|
|
|
|
|
|
|
- see L. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
sub all_pm_files_ok { |
82
|
6
|
|
|
6
|
1
|
291
|
my ($self, @dirs) = @_; |
83
|
|
|
|
|
|
|
|
84
|
6
|
|
|
|
|
23
|
my $test = $self->{test}; |
85
|
|
|
|
|
|
|
|
86
|
6
|
|
|
|
|
14
|
my $ok = 1; |
87
|
6
|
|
|
|
|
44
|
for my $file ( $self->all_pm_files(@dirs) ) { |
88
|
10
|
|
|
|
|
6980
|
my $testok = $self->pm_file_compiles($file); |
89
|
10
|
50
|
|
|
|
115
|
$ok = $testok ? $ok : 0; |
90
|
10
|
|
|
|
|
364
|
$test->ok($testok, "$file compiles"); |
91
|
|
|
|
|
|
|
} |
92
|
6
|
|
|
|
|
6594
|
return $ok; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item C |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Checks all the perl program files it can find for compilation errors. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If C<@dirs> is defined then it is taken as an array of directories to |
101
|
|
|
|
|
|
|
be searched for perl files, otherwise it searches some default locations |
102
|
|
|
|
|
|
|
- see L. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
sub all_pl_files_ok { |
106
|
6
|
|
|
6
|
1
|
382
|
my ($self, @dirs) = @_; |
107
|
|
|
|
|
|
|
|
108
|
6
|
|
|
|
|
33
|
my $test = $self->{test}; |
109
|
|
|
|
|
|
|
|
110
|
6
|
|
|
|
|
28
|
my $ok = 1; |
111
|
6
|
|
|
|
|
40
|
for my $file ( $self->all_pl_files(@dirs) ) { |
112
|
3
|
|
|
|
|
26
|
my $testok = $self->pl_file_compiles($file); |
113
|
3
|
100
|
|
|
|
17
|
$ok = $testok ? $ok : 0; |
114
|
3
|
|
|
|
|
84
|
$test->ok($testok, "$file compiles"); |
115
|
|
|
|
|
|
|
} |
116
|
6
|
|
|
|
|
4585
|
return $ok; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item C |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
An accessor to get/set the verbosity. The default value (undef) will suppress output |
123
|
|
|
|
|
|
|
unless the compilation fails. This is probably what you want. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
If C is set to true, you'll get the output from 'perl -c'. If it's set to |
126
|
|
|
|
|
|
|
false, all diagnostic output is suppressed. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub verbose { |
131
|
82
|
|
|
82
|
1
|
381
|
my ($self, $verbose) = @_; |
132
|
|
|
|
|
|
|
|
133
|
82
|
100
|
|
|
|
381
|
if ( @_ eq 2 ) { |
134
|
5
|
|
|
|
|
23
|
$self->{verbose} = $verbose; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
82
|
|
|
|
|
530
|
return $self->{verbose}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item C |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Searches for and returns a list of perl module files - that is, files with a F<.pm> |
143
|
|
|
|
|
|
|
extension. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
If you provide a list of C<@dirs>, it'll use that as a list of files to process, or |
146
|
|
|
|
|
|
|
directories to search for perl modules. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
If you don't provide C, it'll search for perl modules in the F directory, |
149
|
|
|
|
|
|
|
if that directory exists, otherwise it'll search the F directory. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Skips any files in F, F<.svn>, or F<.git> directories. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub all_pm_files { |
156
|
12
|
|
|
12
|
1
|
5139
|
my ($self, @dirs) = @_; |
157
|
|
|
|
|
|
|
|
158
|
12
|
100
|
|
|
|
63
|
@dirs = @dirs ? @dirs : $self->_default_locations('lib'); |
159
|
|
|
|
|
|
|
|
160
|
12
|
|
|
|
|
30
|
my @pm; |
161
|
12
|
|
|
|
|
47
|
for my $file ( $self->_find_files(@dirs) ) { |
162
|
31
|
100
|
|
|
|
79
|
if ( $self->_perl_module($file) ) { |
163
|
19
|
|
|
|
|
45
|
push @pm, $file; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
12
|
|
|
|
|
49
|
return @pm; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item C |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Searches for and returns a list of perl script files - that is, any files that either |
172
|
|
|
|
|
|
|
have a case insensitive F<.pl>, F<.psgi> extension, or have no extension but have a perl shebang line. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
If you provide a list of C<@dirs>, it'll use that as a list of files to process, or |
175
|
|
|
|
|
|
|
directories to search for perl scripts. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
If you don't provide C, it'll search for perl scripts in the F |
178
|
|
|
|
|
|
|
and F directories if F exists, otherwise it'll search the F |
179
|
|
|
|
|
|
|
and F directories |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Skips any files in F, F<.svn>, or F<.git> directories. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub all_pl_files { |
186
|
12
|
|
|
12
|
1
|
5643
|
my ($self, @dirs) = @_; |
187
|
|
|
|
|
|
|
|
188
|
12
|
100
|
|
|
|
132
|
@dirs = @dirs ? @dirs : $self->_default_locations('script', 'bin'); |
189
|
|
|
|
|
|
|
|
190
|
12
|
|
|
|
|
36
|
my @pl; |
191
|
12
|
|
|
|
|
65
|
for my $file ( $self->_find_files(@dirs) ) { |
192
|
20
|
100
|
|
|
|
53
|
if ( $self->_perl_script($file) ) { |
193
|
12
|
|
|
|
|
36
|
push @pl, $file; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
12
|
|
|
|
|
107
|
return @pl; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item C |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns true if C<$file> compiles as a perl script. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub pl_file_compiles { |
206
|
11
|
|
|
11
|
1
|
8962
|
my ($self, $file) = @_; |
207
|
|
|
|
|
|
|
|
208
|
11
|
|
|
|
|
45
|
return $self->_perl_file_compiles($file); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item C |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Returns true if C<$file> compiles as a perl module. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=cut |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub pm_file_compiles { |
220
|
15
|
|
|
15
|
1
|
5793
|
my ($self, $file) = @_; |
221
|
|
|
|
|
|
|
|
222
|
15
|
|
|
|
|
90
|
return $self->_perl_file_compiles($file); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 TEST METHODS |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
C encapsulates a C object, and provides |
228
|
|
|
|
|
|
|
access to some of its methods. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over 4 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item C |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Your basic test. Pass if C<$test> is true, fail if C<$test> is false. Just |
235
|
|
|
|
|
|
|
like C's C. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
sub ok { |
239
|
8
|
|
|
8
|
1
|
915
|
my ($self, @args) = @_; |
240
|
8
|
|
|
|
|
142
|
$self->{test}->ok(@args); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item C |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Declares that you got to the end of your test plan, no more tests will be run after |
246
|
|
|
|
|
|
|
this point. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=cut |
249
|
|
|
|
|
|
|
sub done_testing { |
250
|
9
|
|
|
9
|
1
|
6626
|
my ($self, @args) = @_; |
251
|
9
|
|
|
|
|
131
|
$self->{test}->done_testing(@args); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item C $count)> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Defines how many tests you plan to run. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
sub plan { |
260
|
3
|
|
|
3
|
1
|
16
|
my ($self, @args) = @_; |
261
|
3
|
|
|
|
|
39
|
$self->{test}->plan(@args); |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item C |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Prints out the given C<@msgs>. Like print, arguments are simply appended |
267
|
|
|
|
|
|
|
together. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Output will be indented and marked with a # so as not to interfere with |
270
|
|
|
|
|
|
|
test output. A newline will be put on the end if there isn't one already. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
We encourage using this rather than calling print directly. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=cut |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub diag { |
277
|
1
|
|
|
1
|
1
|
513
|
my ($self, @args) = @_; |
278
|
1
|
|
|
|
|
6
|
$self->{test}->diag(@args); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item C |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Skips the current test, reporting the C<$reason>. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub skip { |
288
|
1
|
|
|
1
|
1
|
288
|
my ($self, @args) = @_; |
289
|
1
|
|
|
|
|
5
|
$self->{test}->skip(@args); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item C |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Skips all the tests, using the given C<$reason>. Exits immediately with 0. |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=back |
297
|
|
|
|
|
|
|
=cut |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub skip_all { |
300
|
1
|
|
|
1
|
1
|
6
|
my ($self, @args) = @_; |
301
|
1
|
|
|
|
|
6
|
$self->{test}->skip_all(@args); |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
# Run a subcommand, catching STDOUT, STDERR and return code |
305
|
|
|
|
|
|
|
sub _run_command { |
306
|
24
|
|
|
24
|
|
86
|
my ($self, $cmd) = @_; |
307
|
|
|
|
|
|
|
|
308
|
24
|
|
|
|
|
47
|
my ($stdout, $stderr); |
309
|
24
|
50
|
|
|
|
159
|
my $pid = IPC::Open3::open3(0, $stdout, $stderr, $cmd) |
310
|
|
|
|
|
|
|
or die "open3() failed $!"; |
311
|
|
|
|
|
|
|
|
312
|
24
|
|
|
|
|
100471
|
my $output; |
313
|
24
|
|
|
|
|
233
|
for my $handle ( $stdout, $stderr ) { |
314
|
48
|
100
|
|
|
|
355
|
if ( $handle ) { |
315
|
24
|
|
|
|
|
1172891
|
while ( my $line = <$handle> ) { |
316
|
66
|
|
|
|
|
28943
|
push @$output, $line; |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
24
|
|
|
|
|
773
|
waitpid($pid, 0); |
322
|
24
|
100
|
|
|
|
544
|
my $success = ($? == 0 ? 1 : 0); |
323
|
|
|
|
|
|
|
|
324
|
24
|
|
|
|
|
1308
|
return ($success, $output); |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# Works it's way through the input array (files and/or directories), recursively |
328
|
|
|
|
|
|
|
# finding files |
329
|
|
|
|
|
|
|
sub _find_files { |
330
|
31
|
|
|
31
|
|
2690
|
my ($self, @searchlist) = @_; |
331
|
|
|
|
|
|
|
|
332
|
31
|
|
|
|
|
57
|
my @filelist; |
333
|
|
|
|
|
|
|
my $addFile = sub { |
334
|
154
|
|
|
154
|
|
300
|
my ($fname) = @_; |
335
|
|
|
|
|
|
|
|
336
|
154
|
100
|
|
|
|
5333
|
if ( -f $fname ) { |
337
|
103
|
100
|
|
|
|
912
|
if ( !($fname =~ m/CVS|\.svn|\.git/) ) { |
338
|
88
|
|
|
|
|
1727
|
push @filelist, $fname; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
} |
341
|
31
|
|
|
|
|
234
|
}; |
342
|
|
|
|
|
|
|
|
343
|
31
|
|
|
|
|
108
|
for my $item ( @searchlist ) { |
344
|
29
|
|
|
|
|
93
|
$addFile->($item); |
345
|
29
|
100
|
|
|
|
338
|
if ( -d $item ) { |
346
|
24
|
|
|
24
|
|
234
|
no warnings 'File::Find'; |
|
24
|
|
|
|
|
58
|
|
|
24
|
|
|
|
|
20975
|
|
347
|
11
|
|
|
125
|
|
1517
|
find({wanted => sub{$addFile->($File::Find::name)}, no_chdir => 1}, $item); |
|
125
|
|
|
|
|
339
|
|
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
} |
350
|
31
|
|
|
|
|
307
|
return (sort @filelist); |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# Check the syntax of a perl file |
354
|
|
|
|
|
|
|
sub _perl_file_compiles { |
355
|
26
|
|
|
26
|
|
153
|
my ($self, $file) = @_; |
356
|
|
|
|
|
|
|
|
357
|
26
|
100
|
|
|
|
821
|
if ( ! -f $file ) { |
358
|
2
|
50
|
|
|
|
66
|
$self->{test}->diag("$file could not be found") if $self->verbose(); |
359
|
2
|
|
|
|
|
29
|
return 0; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
24
|
|
|
|
|
723
|
my @inc = (File::Spec->catdir("blib", "lib"), @INC); |
363
|
24
|
|
|
|
|
208
|
my $taint = $self->_taint_mode($file); |
364
|
24
|
|
|
|
|
164
|
my $command = join(" ", (qq{"$^X"}, (map { qq{"-I$_"} } @inc), "-c$taint", $file)); |
|
312
|
|
|
|
|
931
|
|
365
|
24
|
50
|
|
|
|
129
|
if ( $self->verbose() ) { |
366
|
0
|
|
|
|
|
0
|
$self->{test}->diag("Executing: " . $command); |
367
|
|
|
|
|
|
|
} |
368
|
24
|
|
|
|
|
114
|
my ($compiles, $output) = $self->_run_command($command); |
369
|
24
|
100
|
66
|
|
|
733
|
if ( $output && (!defined($self->verbose()) || $self->verbose() != 0) ) { |
|
|
|
33
|
|
|
|
|
370
|
17
|
100
|
66
|
|
|
239
|
if ( !$compiles || $self->verbose() ) { |
371
|
1
|
|
|
|
|
15
|
for my $line ( @$output ) { |
372
|
21
|
|
|
|
|
6945
|
$self->{test}->diag($line); |
373
|
|
|
|
|
|
|
} |
374
|
|
|
|
|
|
|
} |
375
|
|
|
|
|
|
|
} |
376
|
|
|
|
|
|
|
|
377
|
24
|
|
|
|
|
1999
|
return $compiles; |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
# Where do we expect to find perl files? |
381
|
|
|
|
|
|
|
sub _default_locations { |
382
|
9
|
|
|
9
|
|
91
|
my ($self, @dirs) = @_; |
383
|
|
|
|
|
|
|
|
384
|
9
|
|
|
|
|
88
|
my @locations = (); |
385
|
9
|
50
|
|
|
|
232
|
my $prefix = -e 'blib' ? "blib" : "."; |
386
|
9
|
|
|
|
|
56
|
for my $dir ( @dirs ) { |
387
|
13
|
|
|
|
|
348
|
my $location = File::Spec->catfile($prefix, $dir); |
388
|
13
|
100
|
|
|
|
203
|
if ( -e $location ) { |
389
|
5
|
|
|
|
|
24
|
push @locations, $location; |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
} |
392
|
9
|
|
|
|
|
52
|
return @locations; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
# Extract the shebang line from a perl program |
396
|
|
|
|
|
|
|
sub _read_shebang { |
397
|
35
|
|
|
35
|
|
660
|
my ($self, $file) = @_; |
398
|
|
|
|
|
|
|
|
399
|
35
|
50
|
|
|
|
1912
|
open(my $f, "<", $file) or die "could not open $file"; |
400
|
35
|
|
|
|
|
1441
|
my $line = <$f>; |
401
|
35
|
100
|
100
|
|
|
1002
|
if (defined $line && $line =~ m/^#!/ ) { |
402
|
11
|
|
|
|
|
267
|
return $line; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
# Should the given file be checked with taint mode on? |
407
|
|
|
|
|
|
|
sub _taint_mode { |
408
|
27
|
|
|
27
|
|
1573
|
my ($self, $file) = @_; |
409
|
|
|
|
|
|
|
|
410
|
27
|
|
|
|
|
113
|
my $shebang = $self->_read_shebang($file); |
411
|
27
|
|
|
|
|
118
|
my $taint = ""; |
412
|
27
|
100
|
|
|
|
180
|
if ($shebang =~ /^#!\s*[\/\w]+\s+-\w*([tT])/) { |
413
|
5
|
|
|
|
|
29
|
$taint = $1; |
414
|
|
|
|
|
|
|
} |
415
|
27
|
|
|
|
|
98
|
return $taint; |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
# Does this file look like a perl script? |
419
|
|
|
|
|
|
|
sub _perl_script { |
420
|
24
|
|
|
24
|
|
1220
|
my ($self, $file) = @_; |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
# Files with .pl or .psgi extensions are perl scripts |
423
|
24
|
100
|
|
|
|
122
|
if ( $file =~ /\.p(?:l|sgi)$/i ) { |
424
|
12
|
|
|
|
|
36
|
return 1; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
# Files with no extension, but a perl shebang are perl scripts |
428
|
12
|
100
|
|
|
|
67
|
if ( $file =~ /(?:^[^.]+$)/ ) { |
429
|
6
|
|
|
|
|
15
|
my $shebang = $self->_read_shebang($file); |
430
|
6
|
100
|
|
|
|
44
|
if ( $shebang =~ m/perl/ ) { |
431
|
2
|
|
|
|
|
8
|
return 1; |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
} |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
# Does this file look like a perl module? |
437
|
|
|
|
|
|
|
sub _perl_module { |
438
|
35
|
|
|
35
|
|
1198
|
my ($self, $file) = @_; |
439
|
|
|
|
|
|
|
|
440
|
35
|
100
|
|
|
|
169
|
if ( $file =~ /\.pm$/ ) { |
441
|
20
|
|
|
|
|
59
|
return 1; |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
1; |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
=head1 AUTHORS |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
Sagar R. Shah C<< >>, |
450
|
|
|
|
|
|
|
Marcel GrEnauer, C<< >>, |
451
|
|
|
|
|
|
|
Evan Giles, C<< >> |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
Copyright 2007-2023 by the authors. |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
458
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
=head1 SEE ALSO |
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
L provides functions to ensure your perl files compile, with |
463
|
|
|
|
|
|
|
the added bonus that it will check you have used strict in all your files. |
464
|
|
|
|
|
|
|
|
465
|
|
|
|
|
|
|
L just handles modules, not script files, but has more |
466
|
|
|
|
|
|
|
fine-grained control. |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
=cut |