blib/lib/Perl/Critic/Policy/RegularExpressions/RequireDotMatchAnything.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 91.8% 45 / 49 CC 3 SCAR 4.5
CC
3
Cov
91%
violates
3.5
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« blib/lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusualDelimiters.pm ↑ Summary blib/lib/Perl/Critic/Policy/RegularExpressions/RequireLineBoundaryMatching.pm »
1 package Perl::Critic::Policy::RegularExpressions::RequireDotMatchAnything;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 our $VERSION = '1.150';
14  
15 #-----------------------------------------------------------------------------
16  
17 40 Readonly::Scalar my $DESC => q{Regular expression without "/s" flag};
18 40 Readonly::Scalar my $EXPL => [ 240, 241 ];
19  
20 #-----------------------------------------------------------------------------
21  
22 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
23 76 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
24 84 ▶sub default_themes { return qw<core pbp cosmetic> }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
25 31 ▶sub applies_to { return qw<PPI::Token::Regexp::Match
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
26 PPI::Token::Regexp::Substitute
27 PPI::Token::QuoteLike::Regexp> }
28  
29 #-----------------------------------------------------------------------------
30  
31 sub violates {
32 1 ▶ my ( $self, $elem, $doc ) = @_;
Subroutine violates: called CC=3 SCAR=12.5
Pod documented
33  
34 1 ▶ my $re = $doc->ppix_regexp_from_element( $elem )
Branch: 1 branch
BranchTrueFalseTotal
my $re = $doc->ppix_regexp_from_element($elem) or return 0 1 1
35 or return;
36 1 ▶ $re->modifier_asserted( 's' )
Branch: 1 branch
BranchTrueFalseTotal
$re->modifier_asserted("s") or return $self->violation($DESC, $EXPL, $elem) 1 0 1
37 or return $self->violation( $DESC, $EXPL, $elem );
38  
39 0 return; #ok!;
40 }
41  
42 40 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 :
« blib/lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusualDelimiters.pm ↑ Summary blib/lib/Perl/Critic/Policy/RegularExpressions/RequireLineBoundaryMatching.pm »