blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitSpecialLiteralHeredocTerminator.pm

filter: Statementstmt 81.2% 26 / 32 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 80.0% 4 / 5 totaltotal 80.0% 40 / 50 CC 2 SCAR 6.1
CC
2
Cov
76%
violates
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« blib/lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm ↑ Summary blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.150';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Hash my %SPECIAL_LITERAL => map { '__' . $_ . '__' => 1 }
17 qw( FILE LINE PACKAGE END DATA );
18 40 Readonly::Scalar my $DESC =>
19 q{Heredoc terminator must not be a special literal};
20  
21 #-----------------------------------------------------------------------------
22  
23 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 75 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 74 ▶sub default_themes { return qw(core maintenance) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 31 ▶sub applies_to { return 'PPI::Token::HereDoc' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 sub violates {
31 0 ▶ my ( $self, $elem, undef ) = @_;
Subroutine violates: not called CC=2 SCAR=17.9
Pod documented
32  
33 # remove << and (optional) quotes from around terminator
34 0 ( my $heredoc_terminator = $elem ) =~
35 s{ \A << ~? \s* (["']?) (.*) \1 \z }{$2}xms;
36  
37 0 ▶ if ( $SPECIAL_LITERAL{ $heredoc_terminator } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SPECIAL_LITERAL{$heredoc_terminator}) 0 0 0
38 0 my $expl = qq{Used "$heredoc_terminator" as heredoc terminator};
39 0 return $self->violation( $DESC, $expl, $elem );
40 }
41  
42 0 return; #ok!
43 }
44  
45 40 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 :
« blib/lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm ↑ Summary blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm »