File Coverage

blib/lib/Perl/Critic/Policy/RegularExpressions/RequireDotMatchAnything.pm
Criterion Covered Total %
statement 25 25 100.0
branch 3 4 75.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 43 45 95.5


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::RegularExpressions::RequireDotMatchAnything;
2              
3 40     40   27073 use 5.010001;
  40         200  
4 40     40   297 use strict;
  40         134  
  40         881  
5 40     40   250 use warnings;
  40         151  
  40         1007  
6              
7 40     40   250 use Readonly;
  40         130  
  40         1990  
8              
9 40     40   779 use Perl::Critic::Utils qw{ :severities };
  40         112  
  40         1955  
10              
11 40     40   5300 use parent 'Perl::Critic::Policy';
  40         135  
  40         286  
12              
13             our $VERSION = '1.146';
14              
15             #-----------------------------------------------------------------------------
16              
17             Readonly::Scalar my $DESC => q{Regular expression without "/s" flag};
18             Readonly::Scalar my $EXPL => [ 240, 241 ];
19              
20             #-----------------------------------------------------------------------------
21              
22 96     96 0 1765 sub supported_parameters { return () }
23 93     93 1 432 sub default_severity { return $SEVERITY_LOW }
24 84     84 1 350 sub default_themes { return qw<core pbp cosmetic> }
25 37     37 1 134 sub applies_to { return qw<PPI::Token::Regexp::Match
26             PPI::Token::Regexp::Substitute
27             PPI::Token::QuoteLike::Regexp> }
28              
29             #-----------------------------------------------------------------------------
30              
31             sub violates {
32 38     38 1 99 my ( $self, $elem, $doc ) = @_;
33              
34 38 50       127 my $re = $doc->ppix_regexp_from_element( $elem )
35             or return;
36 38 100       146347 $re->modifier_asserted( 's' )
37             or return $self->violation( $DESC, $EXPL, $elem );
38              
39 19         409 return; #ok!;
40             }
41              
42             1;
43              
44             __END__
45              
46             #-----------------------------------------------------------------------------
47              
48             =pod
49              
50             =head1 NAME
51              
52             Perl::Critic::Policy::RegularExpressions::RequireDotMatchAnything - Always use the C</s> modifier with regular expressions.
53              
54              
55             =head1 AFFILIATION
56              
57             This Policy is part of the core L<Perl::Critic|Perl::Critic>
58             distribution.
59              
60              
61             =head1 DESCRIPTION
62              
63             When asked what C<.> in a regular expression means, most people will
64             say that it matches any character, which isn't true. It's actually
65             shorthand for C<[^\n]>. Using the C<s> modifier makes C<.> act like
66             people expect it to.
67              
68             my $match = m< foo.bar >xm; # not ok
69             my $match = m< foo.bar >xms; # ok
70              
71              
72             =head1 CONFIGURATION
73              
74             This Policy is not configurable except for the standard options.
75              
76              
77             =head1 NOTES
78              
79             Be cautious about slapping modifier flags onto existing regular
80             expressions, as they can drastically alter their meaning. See
81             L<http://www.perlmonks.org/?node_id=484238> for an interesting
82             discussion on the effects of blindly modifying regular expression
83             flags.
84              
85              
86             =head1 AUTHOR
87              
88             Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
89              
90              
91             =head1 COPYRIGHT
92              
93             Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
94              
95             This program is free software; you can redistribute it and/or modify
96             it under the same terms as Perl itself. The full text of this license
97             can be found in the LICENSE file included with this module.
98              
99             =cut
100              
101             # Local Variables:
102             # mode: cperl
103             # cperl-indent-level: 4
104             # fill-column: 78
105             # indent-tabs-mode: nil
106             # c-indentation-style: bsd
107             # End:
108             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :