File Coverage

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


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::ProhibitImplicitNewlines;
2              
3 40     40   26694 use 5.010001;
  40         167  
4 40     40   248 use strict;
  40         91  
  40         940  
5 40     40   214 use warnings;
  40         91  
  40         1028  
6 40     40   234 use Readonly;
  40         95  
  40         2140  
7              
8 40     40   338 use Perl::Critic::Utils qw{ :severities :classification };
  40         127  
  40         2291  
9 40     40   14220 use parent 'Perl::Critic::Policy';
  40         113  
  40         237  
10              
11             our $VERSION = '1.146';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Literal line breaks in a string};
16             Readonly::Scalar my $EXPL => [60,61];
17              
18             #-----------------------------------------------------------------------------
19              
20 92     92 0 1705 sub supported_parameters { return () }
21 78     78 1 432 sub default_severity { return $SEVERITY_MEDIUM }
22 84     84 1 436 sub default_themes { return qw( core pbp cosmetic ) }
23 33     33 1 105 sub applies_to { return 'PPI::Token::Quote' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 84     84 1 220 my ( $self, $elem, undef ) = @_;
29              
30 84 100       328 return if $elem->string !~ m/\n/xms;
31              
32 4         74 return $self->violation( $DESC, $EXPL, $elem );
33             }
34              
35             1;
36              
37             __END__
38              
39             #-----------------------------------------------------------------------------
40              
41             =pod
42              
43             =head1 NAME
44              
45             Perl::Critic::Policy::ValuesAndExpressions::ProhibitImplicitNewlines - Use concatenation or HEREDOCs instead of literal line breaks in strings.
46              
47             =head1 AFFILIATION
48              
49             This Policy is part of the core L<Perl::Critic|Perl::Critic>
50             distribution.
51              
52              
53             =head1 DESCRIPTION
54              
55             Strings with embedded line breaks are hard to read. Use concatenation
56             or HEREDOCs instead.
57              
58             my $foo = "Line one is quite long
59             Line two"; # Bad
60              
61             my $foo = "Line one is quite long\nLine two"; # Better, but still hard to read
62              
63             my $foo = "Line one is quite long\n"
64             . "Line two"; # Better still
65              
66             my $foo = <<'EOF'; # Use heredoc for longer passages
67             Line one is quite long
68             Line two
69             Line three breaks the camel's back
70             EOF
71              
72              
73             =head1 CONFIGURATION
74              
75             This Policy is not configurable except for the standard options.
76              
77              
78             =head1 AUTHOR
79              
80             Chris Dolan <cdolan@cpan.org>
81              
82              
83             =head1 CREDITS
84              
85             Initial development of this policy was supported by a grant from the
86             Perl Foundation.
87              
88              
89             =head1 COPYRIGHT
90              
91              
92             Copyright (c) 2007-2011 Chris Dolan. Many rights reserved.
93              
94             This program is free software; you can redistribute it and/or modify
95             it under the same terms as Perl itself. The full text of this license
96             can be found in the LICENSE file included with this module.
97              
98             =cut
99              
100             # Local Variables:
101             # mode: cperl
102             # cperl-indent-level: 4
103             # fill-column: 78
104             # indent-tabs-mode: nil
105             # c-indentation-style: bsd
106             # End:
107             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :