File Coverage

blib/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireQuotedHeredocTerminator.pm
Criterion Covered Total %
statement 25 25 100.0
branch 2 2 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator;
2              
3 40     40   30383 use 5.010001;
  40         171  
4 40     40   262 use strict;
  40         109  
  40         988  
5 40     40   213 use warnings;
  40         96  
  40         1094  
6 40     40   355 use Readonly;
  40         151  
  40         2292  
7              
8 40     40   315 use Perl::Critic::Utils qw{ :severities };
  40         214  
  40         2215  
9 40     40   5597 use parent 'Perl::Critic::Policy';
  40         124  
  40         227  
10              
11             our $VERSION = '1.146';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $HEREDOC_RX => qr/ \A << ~? \s* ["'] .* ['"] \z /xms;
16             Readonly::Scalar my $DESC => q{Heredoc terminator must be quoted};
17             Readonly::Scalar my $EXPL => [ 64 ];
18              
19             #-----------------------------------------------------------------------------
20              
21 97     97 0 1626 sub supported_parameters { return () }
22 76     76 1 371 sub default_severity { return $SEVERITY_MEDIUM }
23 86     86 1 383 sub default_themes { return qw(core pbp maintenance) }
24 38     38 1 126 sub applies_to { return 'PPI::Token::HereDoc' }
25              
26             #-----------------------------------------------------------------------------
27              
28             sub violates {
29 8     8 1 26 my ( $self, $elem, undef ) = @_;
30 8 100       61 if ( $elem !~ $HEREDOC_RX ) {
31 2         25 return $self->violation( $DESC, $EXPL, $elem );
32             }
33 6         68 return; #ok!
34             }
35              
36             1;
37              
38             __END__
39              
40             #-----------------------------------------------------------------------------
41              
42             =pod
43              
44             =head1 NAME
45              
46             Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator - Write C< print <<'THE_END' > or C< print <<"THE_END" >.
47              
48             =head1 AFFILIATION
49              
50             This Policy is part of the core L<Perl::Critic|Perl::Critic>
51             distribution.
52              
53              
54             =head1 DESCRIPTION
55              
56             Putting single or double-quotes around your HEREDOC terminator make it
57             obvious to the reader whether the content is going to be interpolated
58             or not.
59              
60             print <<END_MESSAGE; #not ok
61             Hello World
62             END_MESSAGE
63              
64             print <<'END_MESSAGE'; #ok
65             Hello World
66             END_MESSAGE
67              
68             print <<"END_MESSAGE"; #ok
69             $greeting
70             END_MESSAGE
71              
72              
73             =head1 CONFIGURATION
74              
75             This Policy is not configurable except for the standard options.
76              
77              
78             =head1 SEE ALSO
79              
80             L<Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator|Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator>
81              
82             =head1 AUTHOR
83              
84             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
85              
86             =head1 COPYRIGHT
87              
88             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
89              
90             This program is free software; you can redistribute it and/or modify
91             it under the same terms as Perl itself. The full text of this license
92             can be found in the LICENSE file included with this module.
93              
94             =cut
95              
96             # Local Variables:
97             # mode: cperl
98             # cperl-indent-level: 4
99             # fill-column: 78
100             # indent-tabs-mode: nil
101             # c-indentation-style: bsd
102             # End:
103             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :