Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / RegularExpressions / RequireExtendedFormatting.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/RegularExpressions/RequireExtendedFormatting.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::RegularExpressions::RequireExtendedFormatting;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use Perl::Critic::Utils::PPIRegexp qw{ &get_modifiers };
17 use base 'Perl::Critic::Policy';
18
19 our $VERSION = '1.088';
20
21 #-----------------------------------------------------------------------------
22
23 Readonly::Scalar my $DESC => q{Regular expression without "/x" flag};
24 Readonly::Scalar my $EXPL => [ 236 ];
25
26 #-----------------------------------------------------------------------------
27
28 sub supported_parameters { return ()                       }
29 sub default_severity     { return $SEVERITY_MEDIUM         }
30 sub default_themes       { return qw(core pbp maintenance) }
31 sub applies_to           { return qw(PPI::Token::Regexp::Match
32                                      PPI::Token::Regexp::Substitute
33                                      PPI::Token::QuoteLike::Regexp) }
34
35 #-----------------------------------------------------------------------------
36
37 sub violates {
38     my ( $self, $elem, undef ) = @_;
39
40     my %mods = get_modifiers($elem);
41     if ( ! $mods{x} ) {
42         return $self->violation( $DESC, $EXPL, $elem );
43     }
44     return; #ok!;
45 }
46
47 1;
48
49 __END__
50
51 #-----------------------------------------------------------------------------
52
53 =pod
54
55 =head1 NAME
56
57 Perl::Critic::Policy::RegularExpressions::RequireExtendedFormatting - Always use the C</x> modifier with regular expressions.
58
59 =head1 AFFILIATION
60
61 This Policy is part of the core L<Perl::Critic> distribution.
62
63
64 =head1 DESCRIPTION
65
66 Extended regular expression formatting allows you mix whitespace and
67 comments into the pattern, thus making them much more readable.
68
69     # Match a single-quoted string efficiently...
70
71     m{'[^\\']*(?:\\.[^\\']*)*'};  #Huh?
72
73     #Same thing with extended format...
74
75     m{ '           #an opening single quote
76        [^\\']      #any non-special chars (i.e. not backslash or single quote)
77        (?:         #then all of...
78           \\ .     #   any explicitly backslashed char
79           [^\\']*  #   followed by an non-special chars
80        )*          #...repeated zero or more times
81        '           # a closing single quote
82      }x;
83
84
85 =head1 CONFIGURATION
86
87 This Policy is not configurable except for the standard options.
88
89
90 =head1 NOTES
91
92 For common regular expressions like e-mail addresses, phone numbers,
93 dates, etc., have a look at the L<Regex::Common> module.  Also, be
94 cautions about slapping modifier flags onto existing regular
95 expressions, as they can drastically alter their meaning.  See
96 L<http://www.perlmonks.org/?node_id=484238> for an interesting
97 discussion on the effects of blindly modifying regular expression
98 flags.
99
100 =head1 AUTHOR
101
102 Jeffrey Ryan Thalhammer  <thaljef@cpan.org>
103
104 =head1 COPYRIGHT
105
106 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
107
108 This program is free software; you can redistribute it and/or modify
109 it under the same terms as Perl itself.  The full text of this license
110 can be found in the LICENSE file included with this module.
111
112 =cut
113
114 # Local Variables:
115 #   mode: cperl
116 #   cperl-indent-level: 4
117 #   fill-column: 78
118 #   indent-tabs-mode: nil
119 #   c-indentation-style: bsd
120 # End:
121 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :