« blib/lib/Perl/Critic/Policy/RegularExpressions/RequireDotMatchAnything.pm
↑ Summary
blib/lib/Perl/Critic/Policy/ControlStructures/ProhibitCascadingIfElse.pm »
| 1 | package Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching; | ||||||||||
| 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 | 40 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 40 | our $VERSION = '1.150'; | |||||||||
| 13 | |||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||
| 15 | |||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q{Regular expression without "/m" flag}; | |||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => [ 237 ]; | |||||||||
| 18 | |||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||
| 20 | |||||||||||
| 21 | 90 | ▶ | sub supported_parameters { return () } | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | 76 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | 84 | ▶ | sub default_themes { return qw(core pbp cosmetic) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 24 | 31 | ▶ | sub applies_to { return qw(PPI::Token::Regexp::Match | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 25 | PPI::Token::Regexp::Substitute | ||||||||||
| 26 | PPI::Token::QuoteLike::Regexp) } | ||||||||||
| 27 | |||||||||||
| 28 | #----------------------------------------------------------------------------- | ||||||||||
| 29 | |||||||||||
| 30 | sub violates { | ||||||||||
| 31 | 1 | ▶ | my ( $self, $elem, $doc ) = @_; | ||||||||
|
Subroutine
violates: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||
| 32 | |||||||||||
| 33 | 1 | ▶ | my $re = $doc->ppix_regexp_from_element( $elem ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | or return; | ||||||||||
| 35 | 1 | ▶ | $re->modifier_asserted( 'm' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | or return $self->violation( $DESC, $EXPL, $elem ); | ||||||||||
| 37 | |||||||||||
| 38 | 0 | return; #ok!; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 40 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||
| 44 | |||||||||||
| 45 | #----------------------------------------------------------------------------- | ||||||||||
| 46 | |||||||||||
| 47 | =pod | ||||||||||
| 48 | |||||||||||
| 49 | =head1 NAME | ||||||||||
| 50 | |||||||||||
| 51 | Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching - Always use the C</m> modifier with regular expressions. | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | =head1 AFFILIATION | ||||||||||
| 55 | |||||||||||
| 56 | This Policy is part of the core L<Perl::Critic|Perl::Critic> | ||||||||||
| 57 | distribution. | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||
| 61 | |||||||||||
| 62 | Folks coming from a C<sed> or C<awk> background tend to assume that | ||||||||||
| 63 | C<'$'> and C<'^'> match the beginning and end of the line, rather than | ||||||||||
| 64 | then beginning and end of the string. Adding the '/m' flag to your | ||||||||||
| 65 | regex makes it behave as most people expect it should. | ||||||||||
| 66 | |||||||||||
| 67 | my $match = m{ ^ $pattern $ }x; #not ok | ||||||||||
| 68 | my $match = m{ ^ $pattern $ }xm; #ok | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | =head1 CONFIGURATION | ||||||||||
| 72 | |||||||||||
| 73 | This Policy is not configurable except for the standard options. | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | =head1 NOTES | ||||||||||
| 77 | |||||||||||
| 78 | For common regular expressions like e-mail addresses, phone numbers, | ||||||||||
| 79 | dates, etc., have a look at the L<Regexp::Common|Regexp::Common> module. | ||||||||||
| 80 | Also, be cautions about slapping modifier flags onto existing regular | ||||||||||
| 81 | expressions, as they can drastically alter their meaning. See | ||||||||||
| 82 | L<http://www.perlmonks.org/?node_id=484238> for an interesting | ||||||||||
| 83 | discussion on the effects of blindly modifying regular expression | ||||||||||
| 84 | flags. | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | =head1 AUTHOR | ||||||||||
| 88 | |||||||||||
| 89 | Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | =head1 COPYRIGHT | ||||||||||
| 93 | |||||||||||
| 94 | Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. | ||||||||||
| 95 | |||||||||||
| 96 | This program is free software; you can redistribute it and/or modify | ||||||||||
| 97 | it under the same terms as Perl itself. The full text of this license | ||||||||||
| 98 | can be found in the LICENSE file included with this module. | ||||||||||
| 99 | |||||||||||
| 100 | =cut | ||||||||||
| 101 | |||||||||||
| 102 | # Local Variables: | ||||||||||
| 103 | # mode: cperl | ||||||||||
| 104 | # cperl-indent-level: 4 | ||||||||||
| 105 | # fill-column: 78 | ||||||||||
| 106 | # indent-tabs-mode: nil | ||||||||||
| 107 | # c-indentation-style: bsd | ||||||||||
| 108 | # End: | ||||||||||
| 109 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||