Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 71168
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: o.trosien [...] epages.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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;
Subject: Re: [rt.cpan.org #71168] New policy: Prohibit old-style smart match operator
Date: Thu, 22 Sep 2011 14:34:06 -0500
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
On 9/22/11 2:15 PM, Oliver Trosien via RT wrote: Show quoted text
> In perl 5.12 the support for the smart match style @Array ~~ $Element > was dropped.
It wasn't dropped, it was changed. (Actually, the change happened in 5.10.1, and it looks like they may change it again in 5.16.) Depending upon what the right hand side is, different things can happen. I don't know that this is appropriate for core Perl::Critic because the construct is still valid, especially if the right hand side is an object or a regex; perhaps you can release it in your own distribution.
From: o.trosien [...] epages.com
I've just discovered Perl::Critic::Compatibility. Maybe it's suitable in there, as you run into compatibility problems, when using the smart match like that. One could argue, that you of course can specify the min perl version to use, in order to get the right behaviour. Feel free to close this ticket, and I'll put it in my own list then. Oliver
Please also see bug #65191. Show quoted text
>I don't know that this is appropriate for core >Perl::Critic because the construct is still valid, especially if >the right hand side is an object or a regex;
I guess that if RHS is an object or regexp it makes some sense. But if not, (@a ~~ $x) is a fairly useless construct and likely to be a bug. Unfortunately the need to avoid false positives probably rules out turning on this check by default.