line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::logicLAB::RequireSheBang; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id$ |
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
248244
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
193
|
|
6
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
178
|
|
7
|
5
|
|
|
5
|
|
36
|
use base 'Perl::Critic::Policy'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
435626
|
|
8
|
5
|
|
|
5
|
|
1245083
|
use Perl::Critic::Utils qw{ $SEVERITY_MEDIUM :booleans }; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
479
|
|
9
|
5
|
|
|
5
|
|
565
|
use List::MoreUtils qw(none); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
494
|
|
10
|
5
|
|
|
5
|
|
6440
|
use Data::Dumper; |
|
5
|
|
|
|
|
37168
|
|
|
5
|
|
|
|
|
474
|
|
11
|
5
|
|
|
5
|
|
262
|
use 5.008; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
481
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$Data::Dumper::Useqq = 1; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{she-bang line should adhere to requirement}; |
18
|
|
|
|
|
|
|
Readonly::Scalar my $DEBUG => q{DEBUG logicLAB::RequireSheBang}; |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
30
|
use constant default_severity => $SEVERITY_MEDIUM; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
373
|
|
21
|
5
|
|
|
5
|
|
25
|
use constant default_themes => qw(logiclab); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
235
|
|
22
|
5
|
|
|
5
|
|
40
|
use constant supported_parameters => qw(formats debug); |
|
5
|
|
|
|
|
105
|
|
|
5
|
|
|
|
|
3953
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub prepare_to_scan_document { |
25
|
18
|
|
|
18
|
1
|
63672
|
my ( $self, $document ) = @_; |
26
|
18
|
50
|
33
|
|
|
135
|
if ($self->{exempt_modules} && $document->is_module()) { |
27
|
0
|
|
|
|
|
0
|
return 0; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
18
|
|
|
|
|
185
|
return $document->is_program(); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub violates { |
34
|
138
|
|
|
138
|
1
|
2155
|
my ( $self, $element, $doc ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
138
|
|
|
|
|
372
|
my $statement = $doc->find_first( 'PPI::Token::Comment' ); |
37
|
|
|
|
|
|
|
|
38
|
138
|
50
|
|
|
|
2106
|
if (not $statement->location()->[0]) { |
39
|
0
|
|
|
|
|
0
|
return $self->violation( |
40
|
|
|
|
|
|
|
q{she-bang line not located as first line}, |
41
|
|
|
|
|
|
|
$EXPL, $statement ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
138
|
50
|
|
|
|
1728
|
if ( $self->{debug} ) { |
45
|
0
|
|
|
|
|
0
|
print {*STDERR} "$DEBUG: we got statement:\n"; |
|
0
|
|
|
|
|
0
|
|
46
|
0
|
|
|
|
|
0
|
print {*STDERR} Dumper $statement; |
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
138
|
|
|
|
|
405
|
my ( $shebang, $cli ) = $element =~ m{ |
50
|
|
|
|
|
|
|
\A #beginning of string |
51
|
|
|
|
|
|
|
(\#!) #actual she-bang |
52
|
|
|
|
|
|
|
#([^\r\n]*?) #the path and possible flags |
53
|
|
|
|
|
|
|
([/\-\w ]+?) #the path and possible flags, note the space character |
54
|
|
|
|
|
|
|
\s* #possible left over whitespace (PPI?) |
55
|
|
|
|
|
|
|
\Z #indication of end of string to assist above capture |
56
|
|
|
|
|
|
|
}xsm; |
57
|
|
|
|
|
|
|
|
58
|
138
|
100
|
|
|
|
1066
|
if ($cli) { |
59
|
18
|
|
|
|
|
61
|
$cli =~ s{ |
60
|
|
|
|
|
|
|
\s+ #one or more whitespace character, PCPLRSB-9 / http://logiclab.jira.com/browse/PCPLRSB-9 |
61
|
|
|
|
|
|
|
$ #end of string |
62
|
|
|
|
|
|
|
}{}xsm; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
138
|
50
|
33
|
|
|
595
|
if ( $self->{debug} && $shebang && $cli ) { |
|
|
50
|
33
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
print {*STDERR} "$DEBUG: we got a shebang line:\n"; |
|
0
|
|
|
|
|
0
|
|
67
|
0
|
|
|
|
|
0
|
print {*STDERR} '>' . $shebang . $cli . "<\n"; |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
print {*STDERR} "$DEBUG: comparing against formats:\n"; |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
|
|
|
|
0
|
print {*STDERR} Dumper $self->{_formats}; |
|
0
|
|
|
|
|
0
|
|
71
|
0
|
|
|
|
|
0
|
print {*STDERR} "\n"; |
|
0
|
|
|
|
|
0
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} elsif ( $self->{debug} ) { |
74
|
0
|
|
|
|
|
0
|
print {*STDERR} "$DEBUG: not a shebang, ignoring...\n"; |
|
0
|
|
|
|
|
0
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
138
|
100
|
100
|
24
|
|
354
|
if ( $shebang && none { ( $shebang . $cli ) eq $_ } |
|
24
|
|
|
|
|
119
|
|
78
|
18
|
|
|
|
|
127
|
@{ $self->{_formats} } ) |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
|
81
|
9
|
50
|
|
|
|
32
|
if ( $self->{debug} ) { |
82
|
0
|
|
|
|
|
0
|
print {*STDERR} "$DEBUG: we got a violation:\n"; |
|
0
|
|
|
|
|
0
|
|
83
|
0
|
|
|
|
|
0
|
print {*STDERR} '>' . $shebang . $cli . "<\n"; |
|
0
|
|
|
|
|
0
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
9
|
|
|
|
|
64
|
return $self->violation( |
87
|
|
|
|
|
|
|
q{she-bang line not conforming with requirement}, |
88
|
|
|
|
|
|
|
$EXPL, $element ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
129
|
|
|
|
|
411
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub initialize_if_enabled { |
95
|
4
|
|
|
4
|
1
|
6618843
|
my ( $self, $config ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#Formats: |
98
|
|
|
|
|
|
|
#Setting the default |
99
|
4
|
|
|
|
|
20
|
$self->{_formats} = [ ('#!/usr/local/bin/perl') ]; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#fetching configured formats |
102
|
4
|
|
|
|
|
21
|
my $formats = $config->get('formats'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#parsing configured formats, see also _parse_formats |
105
|
4
|
100
|
|
|
|
43
|
if ($formats) { |
106
|
3
|
|
|
|
|
14
|
$self->{_formats} = $self->_parse_formats($formats); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#debug |
110
|
4
|
|
50
|
|
|
18
|
$self->{debug} = $config->get('debug') || 0; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
#exempt_modules |
113
|
4
|
|
50
|
|
|
57
|
$self->{exempt_modules} = $config->get('exempt_modules') || 1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
4
|
|
|
|
|
54
|
return $TRUE; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _parse_formats { |
120
|
3
|
|
|
3
|
|
9
|
my ( $self, $config_string ) = @_; |
121
|
|
|
|
|
|
|
|
122
|
3
|
|
|
|
|
26
|
my @formats = split m{ \s* [||]+ \s* }xsm, $config_string; |
123
|
|
|
|
|
|
|
|
124
|
3
|
|
|
|
|
12
|
return \@formats; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=pod |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Perl::Critic::Policy::logicLAB::RequireSheBang - simple policy for keeping your shebang line uniform |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AFFILIATION |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This policy is a policy in the Perl::Critic::logicLAB distribution. The policy |
140
|
|
|
|
|
|
|
is themed: logiclab. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 VERSION |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This documentation describes version 0.05. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This policy is intended in guarding your use of the shebang line. It assists |
149
|
|
|
|
|
|
|
in making sure that your shebang line adheres to certain formats. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The default format is |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You can however specify another or define your own in the configuration of the |
156
|
|
|
|
|
|
|
policy. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
B<NB> this policy does currently not warn about missing shebang lines, it only |
159
|
|
|
|
|
|
|
checks shebang lines encountered. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This policy allow you to configure the contents of the shebang lines you |
164
|
|
|
|
|
|
|
want to allow using L</formats>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 formats |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
[logicLAB::RequireSheBang] |
169
|
|
|
|
|
|
|
formats = #!/usr/local/bin/perl || #!/usr/bin/perl || #!perl || #!env perl |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Since the default shebang line enforced by the policy is: |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Please note that if you however what to extend the pattern, you also have |
176
|
|
|
|
|
|
|
to specify was is normally the default pattern since configuration |
177
|
|
|
|
|
|
|
overwrites the default even for extensions. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This mean that if you want to allow: |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#!/usr/local/bin/perl -wT |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Your format should look like the following: |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
[logicLAB::RequireSheBang] |
190
|
|
|
|
|
|
|
formats = #!/usr/local/bin/perl || #!/usr/local/bin/perl -w || #!/usr/local/bin/perl -wT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 exempt_modules |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
You can specify if you want to check modules also. The default is to exempt from checking |
195
|
|
|
|
|
|
|
shebang lines in modules. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
[logicLAB::RequireSheBang] |
198
|
|
|
|
|
|
|
exempt_modules = 0 |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 debug |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Optionally and for development purposes I have added a debug flag. This can be set in |
203
|
|
|
|
|
|
|
your L<Perl::Critic> configuration file as follows: |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
[logicLAB::RequireSheBang] |
206
|
|
|
|
|
|
|
debug = 1 |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This enables more explicit output on what is going on during the actual processing of |
209
|
|
|
|
|
|
|
the policy. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 DEPENDENCIES AND REQUIREMENTS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * L<Perl::Critic::Utils> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * L<Readonly> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * L<Test::More> |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * L<Test::Perl::Critic> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * L<List::MoreUtils> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=back |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
This distribution has no known incompatibilities. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
The distribution has now known bugs or limitations. It locates shebang lines |
236
|
|
|
|
|
|
|
through out the source code, not limiting itself to the first line. This might |
237
|
|
|
|
|
|
|
however change in the future, but will propably be made configurable if possible. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 BUG REPORTING |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Please use Requets Tracker for bug reporting: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=over |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Perl-Critic-logicLAB-RequireSheBang> |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=back |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 TEST AND QUALITY |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
The following policies have been disabled for this distribution |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=over |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitConstantPragma> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
Constants are good, - see the link below. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item * L<https://logiclab.jira.com/wiki/display/OPEN/Perl-Critic-Policy-ValuesAndExpressions-ProhibitConstantPragma> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=back |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item * L<Perl::Critic::Policy::NamingConventions::Capitalization> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * L<Data::Dumper> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
See also F<t/perlcriticrc> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head2 TEST COVERAGE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Coverage test executed the following way, the coverage report is based on the |
276
|
|
|
|
|
|
|
version described in this documentation (see L</VERSION>). |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
./Build testcover |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
281
|
|
|
|
|
|
|
File stmt bran cond sub pod time total |
282
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
283
|
|
|
|
|
|
|
...ogicLAB/RequireSheBang.pm 70.4 64.3 44.4 100.0 100.0 100.0 72.1 |
284
|
|
|
|
|
|
|
Total 70.4 64.3 44.4 100.0 100.0 100.0 72.1 |
285
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 SEE ALSO |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=over |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item * L<Perl::Critic> |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * L<http://perldoc.perl.org/perlrun.html> |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item * L<http://logiclab.jira.com/wiki/display/OPEN/Development#Development-MakeyourComponentsEnvironmentAgnostic> |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * L<http://logiclab.jira.com/wiki/display/PCPLRSB/Home> |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=item * L<http://logiclab.jira.com/wiki/display/PCLL/Home> |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=back |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=head1 AUTHOR |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=over |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=item * Jonas B. Nielsen, jonasbn C<< <jonasbn@cpan.org> >> |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=back |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENT |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=over |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item * Erik Johansen (uniejo), feedback to version 0.01 |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=back |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Copyright (c) 2011-2014 Jonas B. Nielsen, jonasbn. All rights reserved. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the |
324
|
|
|
|
|
|
|
same terms as Perl itself. |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=cut |