File Coverage

blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitImplicitNewlines.pm
Criterion Covered Total %
statement 23 24 95.8
branch 1 2 50.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 39 42 92.8


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::ValuesAndExpressions::ProhibitImplicitNewlines;
2              
3 40     40   26078 use 5.010001;
  40         163  
4 40     40   217 use strict;
  40         92  
  40         929  
5 40     40   212 use warnings;
  40         83  
  40         944  
6 40     40   218 use Readonly;
  40         94  
  40         2199  
7              
8 40     40   288 use Perl::Critic::Utils qw{ :severities :classification };
  40         97  
  40         2098  
9 40     40   13911 use parent 'Perl::Critic::Policy';
  40         96  
  40         239  
10              
11             our $VERSION = '1.150';
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 89     89 0 1609 sub supported_parameters { return () }
21 74     74 1 298 sub default_severity { return $SEVERITY_MEDIUM }
22 84     84 1 345 sub default_themes { return qw( core pbp cosmetic ) }
23 30     30 1 108 sub applies_to { return 'PPI::Token::Quote' }
24              
25             #-----------------------------------------------------------------------------
26              
27             sub violates {
28 72     72 1 190 my ( $self, $elem, undef ) = @_;
29              
30 72 50       213 return if $elem->string !~ m/\n/xms;
31              
32 0           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 :