line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Compile::Internal; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
969588
|
use warnings; |
|
24
|
|
|
|
|
217
|
|
|
24
|
|
|
|
|
800
|
|
4
|
24
|
|
|
24
|
|
129
|
use strict; |
|
24
|
|
|
|
|
43
|
|
|
24
|
|
|
|
|
463
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
7215
|
use version; our $VERSION = version->declare("v3.3.1"); |
|
24
|
|
|
|
|
31964
|
|
|
24
|
|
|
|
|
148
|
|
7
|
24
|
|
|
24
|
|
2373
|
use File::Find; |
|
24
|
|
|
|
|
51
|
|
|
24
|
|
|
|
|
2061
|
|
8
|
24
|
|
|
24
|
|
163
|
use File::Spec; |
|
24
|
|
|
|
|
47
|
|
|
24
|
|
|
|
|
710
|
|
9
|
24
|
|
|
24
|
|
2925
|
use Test::Builder; |
|
24
|
|
|
|
|
248404
|
|
|
24
|
|
|
|
|
503
|
|
10
|
24
|
|
|
24
|
|
12302
|
use IPC::Open3 (); |
|
24
|
|
|
|
|
98893
|
|
|
24
|
|
|
|
|
25714
|
|
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
|
2991
|
my ($class, %self) = @_; |
42
|
25
|
|
|
|
|
100
|
my $self = \%self; |
43
|
|
|
|
|
|
|
|
44
|
25
|
|
|
|
|
163
|
$self->{test} = Test::Builder->new(); |
45
|
|
|
|
|
|
|
|
46
|
25
|
|
|
|
|
298
|
bless ($self, $class); |
47
|
25
|
|
|
|
|
93
|
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
|
1865
|
my ($self, @search) = @_; |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
30
|
my $pm_ok = $self->all_pm_files_ok(@search); |
64
|
5
|
|
|
|
|
73
|
my $pl_ok = $self->all_pl_files_ok(@search); |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
100
|
|
|
350
|
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
|
624
|
my ($self, @search) = @_; |
82
|
|
|
|
|
|
|
|
83
|
7
|
|
|
|
|
24
|
my $test = $self->{test}; |
84
|
|
|
|
|
|
|
|
85
|
7
|
|
|
|
|
29
|
my $ok = 1; |
86
|
7
|
|
|
|
|
48
|
for my $file ( $self->all_pm_files(@search) ) { |
87
|
11
|
|
|
|
|
7452
|
my $testok = $self->pm_file_compiles($file); |
88
|
11
|
100
|
|
|
|
115
|
$ok = $testok ? $ok : 0; |
89
|
11
|
|
|
|
|
504
|
$test->ok($testok, "$file compiles"); |
90
|
|
|
|
|
|
|
} |
91
|
7
|
|
|
|
|
7248
|
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
|
432
|
my ($self, @search) = @_; |
106
|
|
|
|
|
|
|
|
107
|
7
|
|
|
|
|
34
|
my $test = $self->{test}; |
108
|
|
|
|
|
|
|
|
109
|
7
|
|
|
|
|
28
|
my $ok = 1; |
110
|
7
|
|
|
|
|
65
|
for my $file ( $self->all_pl_files(@search) ) { |
111
|
3
|
|
|
|
|
27
|
my $testok = $self->pl_file_compiles($file); |
112
|
3
|
100
|
|
|
|
43
|
$ok = $testok ? $ok : 0; |
113
|
3
|
|
|
|
|
91
|
$test->ok($testok, "$file compiles"); |
114
|
|
|
|
|
|
|
} |
115
|
7
|
|
|
|
|
5143
|
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
|
380
|
my ($self, $verbose) = @_; |
131
|
|
|
|
|
|
|
|
132
|
90
|
100
|
|
|
|
429
|
if ( @_ eq 2 ) { |
133
|
5
|
|
|
|
|
16
|
$self->{_verbose} = $verbose; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
90
|
|
|
|
|
707
|
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
|
7886
|
my ($self, @search) = @_; |
156
|
|
|
|
|
|
|
|
157
|
13
|
100
|
|
|
|
51
|
if ( ! @search ) { |
158
|
5
|
|
|
|
|
29
|
@search = $self->_default_locations('lib'); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
13
|
|
|
|
|
30
|
my @pm; |
162
|
13
|
|
|
|
|
44
|
for my $file ( $self->_find_files(@search) ) { |
163
|
33
|
100
|
|
|
|
105
|
if ( $self->_perl_module($file) ) { |
164
|
21
|
|
|
|
|
62
|
push @pm, $file; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
13
|
|
|
|
|
98
|
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
|
7300
|
my ($self, @search) = @_; |
189
|
|
|
|
|
|
|
|
190
|
13
|
100
|
|
|
|
56
|
if ( ! @search ) { |
191
|
4
|
|
|
|
|
79
|
@search = $self->_default_locations('script', 'bin'); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
13
|
|
|
|
|
38
|
my @pl; |
195
|
13
|
|
|
|
|
52
|
for my $file ( $self->_find_files(@search) ) { |
196
|
22
|
100
|
|
|
|
58
|
if ( $self->_perl_script($file) ) { |
197
|
12
|
|
|
|
|
35
|
push @pl, $file; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
13
|
|
|
|
|
79
|
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
|
6201
|
my ($self, $file) = @_; |
211
|
|
|
|
|
|
|
|
212
|
12
|
|
|
|
|
82
|
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
|
3795
|
my ($self, $file) = @_; |
225
|
|
|
|
|
|
|
|
226
|
17
|
|
|
|
|
75
|
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
|
1345
|
my ($self, @args) = @_; |
244
|
11
|
|
|
|
|
169
|
$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
|
6723
|
my ($self, @args) = @_; |
255
|
9
|
|
|
|
|
134
|
$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
|
13
|
my ($self, @args) = @_; |
265
|
3
|
|
|
|
|
38
|
$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
|
711
|
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
|
527
|
my ($self, @args) = @_; |
293
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
48
|
$self->{test}->skip_all(@args); |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# Run a subcommand, catching STDOUT, STDERR and return code |
309
|
|
|
|
|
|
|
sub _run_command { |
310
|
27
|
|
|
27
|
|
85
|
my ($self, $cmd) = @_; |
311
|
|
|
|
|
|
|
|
312
|
27
|
|
|
|
|
83
|
my ($stdout, $stderr); |
313
|
27
|
50
|
|
|
|
158
|
my $pid = IPC::Open3::open3(0, $stdout, $stderr, $cmd) |
314
|
|
|
|
|
|
|
or die "open3() failed $!"; |
315
|
|
|
|
|
|
|
|
316
|
27
|
|
|
|
|
108620
|
my $output = []; |
317
|
27
|
|
|
|
|
257
|
for my $handle ( $stdout, $stderr ) { |
318
|
54
|
100
|
|
|
|
443
|
if ( $handle ) { |
319
|
27
|
|
|
|
|
1215402
|
while ( my $line = <$handle> ) { |
320
|
71
|
|
|
|
|
33359
|
push @$output, $line; |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
27
|
|
|
|
|
851
|
waitpid($pid, 0); |
326
|
27
|
100
|
|
|
|
544
|
my $success = ($? == 0 ? 1 : 0); |
327
|
|
|
|
|
|
|
|
328
|
27
|
|
|
|
|
1421
|
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
|
|
2614
|
my ($self, @search) = @_; |
335
|
|
|
|
|
|
|
|
336
|
33
|
|
|
|
|
56
|
my @filelist; |
337
|
|
|
|
|
|
|
my $addFile = sub { |
338
|
161
|
|
|
161
|
|
321
|
my ($fname) = @_; |
339
|
|
|
|
|
|
|
|
340
|
161
|
100
|
|
|
|
6116
|
if ( -f $fname ) { |
341
|
110
|
100
|
|
|
|
910
|
if ( !($fname =~ m/CVS|\.svn|\.git/) ) { |
342
|
95
|
|
|
|
|
2004
|
push @filelist, $fname; |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
33
|
|
|
|
|
295
|
}; |
346
|
|
|
|
|
|
|
|
347
|
33
|
|
|
|
|
154
|
for my $item ( @search ) { |
348
|
31
|
|
|
|
|
124
|
$addFile->($item); |
349
|
31
|
100
|
|
|
|
393
|
if ( -d $item ) { |
350
|
24
|
|
|
24
|
|
202
|
no warnings 'File::Find'; |
|
24
|
|
|
|
|
52
|
|
|
24
|
|
|
|
|
21311
|
|
351
|
11
|
|
|
130
|
|
1903
|
find({wanted => sub{$addFile->($File::Find::name)}, no_chdir => 1}, $item); |
|
130
|
|
|
|
|
403
|
|
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
} |
354
|
33
|
|
|
|
|
371
|
return (sort @filelist); |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
# Check the syntax of a perl file |
358
|
|
|
|
|
|
|
sub _perl_file_compiles { |
359
|
29
|
|
|
29
|
|
151
|
my ($self, $file) = @_; |
360
|
|
|
|
|
|
|
|
361
|
29
|
100
|
|
|
|
832
|
if ( ! -f $file ) { |
362
|
2
|
50
|
|
|
|
51
|
if ( $self->verbose() ) { |
363
|
0
|
|
|
|
|
0
|
$self->{test}->diag("$file could not be found"); |
364
|
|
|
|
|
|
|
} |
365
|
2
|
|
|
|
|
23
|
return 0; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
27
|
|
|
|
|
766
|
my @inc = (File::Spec->catdir("blib", "lib"), @INC); |
369
|
27
|
|
|
|
|
278
|
my $taint = $self->_taint_mode($file); |
370
|
27
|
|
|
|
|
198
|
my $command = join(" ", (qq{"$^X"}, (map { qq{"-I$_"} } @inc), "-c$taint", $file)); |
|
351
|
|
|
|
|
1102
|
|
371
|
27
|
50
|
|
|
|
139
|
if ( $self->verbose() ) { |
372
|
0
|
|
|
|
|
0
|
$self->{test}->diag("Executing: " . $command); |
373
|
|
|
|
|
|
|
} |
374
|
27
|
|
|
|
|
126
|
my ($compiles, $output) = $self->_run_command($command); |
375
|
27
|
100
|
66
|
|
|
511
|
if ( !defined($self->verbose()) || $self->verbose() != 0 ) { |
376
|
20
|
100
|
66
|
|
|
316
|
if ( !$compiles || $self->verbose() ) { |
377
|
2
|
|
|
|
|
31
|
for my $line ( @$output ) { |
378
|
24
|
|
|
|
|
8107
|
$self->{test}->diag($line); |
379
|
|
|
|
|
|
|
} |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
27
|
|
|
|
|
2428
|
return $compiles; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# Where do we expect to find perl files? |
387
|
|
|
|
|
|
|
sub _default_locations { |
388
|
9
|
|
|
9
|
|
74
|
my ($self, @dirs) = @_; |
389
|
|
|
|
|
|
|
|
390
|
9
|
|
|
|
|
33
|
my @locations = (); |
391
|
9
|
50
|
|
|
|
260
|
my $prefix = -e 'blib' ? "blib" : "."; |
392
|
9
|
|
|
|
|
90
|
for my $dir ( @dirs ) { |
393
|
13
|
|
|
|
|
310
|
my $location = File::Spec->catfile($prefix, $dir); |
394
|
13
|
100
|
|
|
|
220
|
if ( -e $location ) { |
395
|
5
|
|
|
|
|
27
|
push @locations, $location; |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
} |
398
|
9
|
|
|
|
|
49
|
return @locations; |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
# Extract the shebang line from a perl program |
402
|
|
|
|
|
|
|
sub _read_shebang { |
403
|
39
|
|
|
39
|
|
980
|
my ($self, $file) = @_; |
404
|
|
|
|
|
|
|
|
405
|
39
|
100
|
|
|
|
2325
|
if ( open(my $f, "<", $file) ) { |
406
|
38
|
|
|
|
|
1257
|
my $line = <$f>; |
407
|
38
|
100
|
100
|
|
|
1213
|
if (defined $line && $line =~ m/^#!/ ) { |
408
|
11
|
|
|
|
|
264
|
return $line; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
} |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
# Should the given file be checked with taint mode on? |
414
|
|
|
|
|
|
|
sub _taint_mode { |
415
|
30
|
|
|
30
|
|
2407
|
my ($self, $file) = @_; |
416
|
|
|
|
|
|
|
|
417
|
30
|
|
|
|
|
145
|
my $shebang = $self->_read_shebang($file); |
418
|
30
|
|
|
|
|
143
|
my $taint = ""; |
419
|
30
|
100
|
|
|
|
250
|
if ($shebang =~ /^#!\s*[\/\w]+\s+-\w*([tT])/) { |
420
|
5
|
|
|
|
|
27
|
$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
|
|
1142
|
my ($self, $file) = @_; |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# Files with .pl or .psgi extensions are perl scripts |
430
|
26
|
100
|
|
|
|
476
|
if ( $file =~ /\.p(?:l|sgi)$/i ) { |
431
|
12
|
|
|
|
|
42
|
return 1; |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
# Files with no extension, but a perl shebang are perl scripts |
435
|
14
|
100
|
|
|
|
102
|
if ( $file =~ /(?:^[^.]+$)/ ) { |
436
|
6
|
|
|
|
|
16
|
my $shebang = $self->_read_shebang($file); |
437
|
6
|
100
|
|
|
|
43
|
if ( $shebang =~ m/perl/ ) { |
438
|
2
|
|
|
|
|
8
|
return 1; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
} |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
# Does this file look like a perl module? |
444
|
|
|
|
|
|
|
sub _perl_module { |
445
|
37
|
|
|
37
|
|
1109
|
my ($self, $file) = @_; |
446
|
|
|
|
|
|
|
|
447
|
37
|
|
|
|
|
168
|
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 |