Subject: | New policy: Prohibit old-style smart match operator |
In perl 5.12 the support for the smart match style @Array ~~ $Element
was dropped. To find and eliminate any remaining existing code that was
relying this behaviour, I have come up with a perlcritic rule (see
attachment)
Subject: | ProhibitOldSmartMatch.pm |
package Perl::Critic::Policy::Operators::ProhibitOldSmartMatch;
use strict;
use warnings;
use Readonly;
use Perl::Critic::Utils qw{ :severities };
use base 'Perl::Critic::Policy';
#-----------------------------------------------------------------------------
Readonly::Scalar my $DESC => q{Perl 5.12 incompatible smart match};
Readonly::Scalar my $EXPL => q{Rewrite as $SCALAR ~~ @ARRAY instead.};
#-----------------------------------------------------------------------------
sub supported_parameters { return () }
sub default_severity { return $SEVERITY_HIGH }
sub default_themes { return qw( core ) }
sub applies_to { return 'PPI::Token::Operator' }
#-----------------------------------------------------------------------------
sub violates {
my $self = shift;
my ( $Elem, undef ) = @_;
return if $Elem ne '~~';
my $Predecessor = $Elem->sprevious_sibling();
my $Successor = $Elem->snext_sibling();
return if ( !$Predecessor || !$Successor );
if ( substr( $Predecessor, 0, 1 ) eq '@' && substr( $Successor, 0, 1 ) eq '$' ) {
return $self->violation( $DESC, $EXPL, $Elem );
}
return;
}
1;