line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
27624
|
use 5.010001; |
|
40
|
|
|
|
|
189
|
|
4
|
40
|
|
|
40
|
|
243
|
use strict; |
|
40
|
|
|
|
|
104
|
|
|
40
|
|
|
|
|
849
|
|
5
|
40
|
|
|
40
|
|
210
|
use warnings; |
|
40
|
|
|
|
|
98
|
|
|
40
|
|
|
|
|
988
|
|
6
|
|
|
|
|
|
|
|
7
|
40
|
|
|
40
|
|
223
|
use Readonly; |
|
40
|
|
|
|
|
93
|
|
|
40
|
|
|
|
|
2108
|
|
8
|
|
|
|
|
|
|
|
9
|
40
|
|
|
40
|
|
284
|
use Perl::Critic::Utils qw{ :severities }; |
|
40
|
|
|
|
|
106
|
|
|
40
|
|
|
|
|
2137
|
|
10
|
40
|
|
|
40
|
|
5543
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
108
|
|
|
40
|
|
|
|
|
269
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Hash my %SPECIAL_LITERAL => map { '__' . $_ . '__' => 1 } |
17
|
|
|
|
|
|
|
qw( FILE LINE PACKAGE END DATA ); |
18
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => |
19
|
|
|
|
|
|
|
q{Heredoc terminator must not be a special literal}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
|
23
|
95
|
|
|
95
|
0
|
1781
|
sub supported_parameters { return () } |
24
|
88
|
|
|
88
|
1
|
435
|
sub default_severity { return $SEVERITY_MEDIUM } |
25
|
74
|
|
|
74
|
1
|
341
|
sub default_themes { return qw(core maintenance) } |
26
|
36
|
|
|
36
|
1
|
180
|
sub applies_to { return 'PPI::Token::HereDoc' } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub violates { |
31
|
16
|
|
|
16
|
1
|
50
|
my ( $self, $elem, undef ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# remove << and (optional) quotes from around terminator |
34
|
16
|
|
|
|
|
60
|
( my $heredoc_terminator = $elem ) =~ |
35
|
|
|
|
|
|
|
s{ \A << ~? \s* (["']?) (.*) \1 \z }{$2}xms; |
36
|
|
|
|
|
|
|
|
37
|
16
|
100
|
|
|
|
285
|
if ( $SPECIAL_LITERAL{ $heredoc_terminator } ) { |
38
|
14
|
|
|
|
|
146
|
my $expl = qq{Used "$heredoc_terminator" as heredoc terminator}; |
39
|
14
|
|
|
|
|
58
|
return $self->violation( $DESC, $expl, $elem ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
29
|
return; #ok! |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=pod |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator - Don't write C< print <<'__END__' >. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 AFFILIATION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
61
|
|
|
|
|
|
|
distribution. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Using one of Perl's special literals as a HEREDOC terminator could be |
67
|
|
|
|
|
|
|
confusing to tools that try to parse perl. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
print <<'__END__'; #not ok |
70
|
|
|
|
|
|
|
Hello world |
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
print <<'__END_OF_WORLD__'; #ok |
74
|
|
|
|
|
|
|
Goodbye world! |
75
|
|
|
|
|
|
|
__END_OF_WORLD__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The special literals that this policy prohibits are: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item __END__ |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item __DATA__ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item __PACKAGE__ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item __FILE__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item __LINE__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CONFIGURATION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SEE ALSO |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator|Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator|Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Kyle Hasselbacher <kyle@cpan.org> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Copyright (c) 2009-2011 Kyle Hasselbacher. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
116
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
117
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Local Variables: |
122
|
|
|
|
|
|
|
# mode: cperl |
123
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
124
|
|
|
|
|
|
|
# fill-column: 78 |
125
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
126
|
|
|
|
|
|
|
# c-indentation-style: bsd |
127
|
|
|
|
|
|
|
# End: |
128
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |