File Coverage

blib/lib/Perl/Critic/Policy/RegularExpressions/RequireDotMatchAnything.pm
Criterion Covered Total %
statement 21 25 84.0
branch 0 4 0.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 35 45 77.7


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::RegularExpressions::RequireDotMatchAnything;
2              
3 40     40   26899 use 5.010001;
  40         210  
4 40     40   255 use strict;
  40         172  
  40         838  
5 40     40   245 use warnings;
  40         152  
  40         1016  
6              
7 40     40   277 use Readonly;
  40         141  
  40         2057  
8              
9 40     40   315 use Perl::Critic::Utils qw{ :severities };
  40         121  
  40         2065  
10              
11 40     40   5176 use parent 'Perl::Critic::Policy';
  40         145  
  40         254  
12              
13             our $VERSION = '1.150';
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 89     89 0 2006 sub supported_parameters { return () }
23 74     74 1 327 sub default_severity { return $SEVERITY_LOW }
24 84     84 1 396 sub default_themes { return qw<core pbp cosmetic> }
25 30     30 1 97 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 0     0 1   my ( $self, $elem, $doc ) = @_;
33              
34 0 0         my $re = $doc->ppix_regexp_from_element( $elem )
35             or return;
36 0 0         $re->modifier_asserted( 's' )
37             or return $self->violation( $DESC, $EXPL, $elem );
38              
39 0           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 :