--- ProhibitMatchVars.bak Fri Dec 26 20:51:09 2008
+++ ProhibitMatchVars.pm Fri Dec 26 22:41:35 2008
@@ -28,7 +28,7 @@
#-----------------------------------------------------------------------------
sub supported_parameters { return () }
-sub default_severity { return $SEVERITY_HIGH }
+sub default_severity { return $SEVERITY_MEDIUM }
sub default_themes { return qw( core bugs pbp ) }
sub applies_to { return qw( PPI::Token::Symbol
PPI::Statement::Include ) }
@@ -37,7 +37,9 @@
sub violates {
my ( $self, $elem, undef ) = @_;
- if (_is_use_english($elem) || _is_forbidden_var($elem)) {
+ if (_is_use_english($elem) ||
+ #Explicit import of match vars
+ _is_use_english($elem)
return $self->violation( $DESC, $EXPL, $elem );
}
return; #ok!
@@ -75,7 +77,7 @@
=head1 NAME
-Perl::Critic::Policy::Variables::ProhibitMatchVars - Avoid C<$`>, C<$&>, C<$'> and their English equivalents.
+Perl::Critic::Policy::Variables::ProhibitMatchVars - Avoid Saw Ampersand et al.
=head1 AFFILIATION
@@ -86,14 +88,24 @@
=head1 DESCRIPTION
-Using the "match variables" C<$`>, C<$&>, and/or C<$'> can
-significantly degrade the performance of a program. This policy
-forbids using them or their English equivalents. See B<perldoc
-English> or PBP page 82 for more information.
-
-It used to forbid plain C<use English;> because it ends up causing the
-performance side-effects of the match variables. However, the message
-emitted for that situation was not at all clear and there is now
+Using the "match variables" C<$`>, C<$&>, and/or C<$'> can significantly
+degrade the performance of perl's regular expression engine.
+See B<perldoc English> or PBP page 82 for more information.
+
+This policy forbids using these variables; the C<English> aliases
+I<$PREMATCH>, I<$MATCH>, I<$POSTMATCH>; or any other variables with
+those names. As an alternative, consider the following idiom:
+
+ /\A(.*?)(PATTERN)(.*)\Z/;
+
+Or to avoid throwing off any numbered captures:
+
+ /PATTERN/;
+ substr($_, 0, $-[0]), substr($_, $-[0], $+[0]-$-[0]), substr($_, $+[0]);
+
+This policy used to forbid plain C<use English;> because its aliasing of the
+match variables involved triggers the aforementioned performance hit. However,
+the message emitted for that situation was not at all clear and there is now
L<Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish|Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish>,
which addresses this situation directly.