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