Skip Menu |

Preferred bug tracker

Please email the preferred bug tracker to report your issue.

This queue is for tickets about the PPIx-Regexp CPAN distribution.

Report information
The Basics
Id: 102895
Status: resolved
Priority: 0/
Queue: PPIx-Regexp

People
Owner: Nobody in particular
Requestors: PETDANCE [...] cpan.org
Cc:
AdminCc:

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



Subject: Nested hashes confuse the policy
In the following program, %x is seen as unused because of the qr/$x{$y{a}}/. If $x{} doesn't have another dereference as its index, it doesn't report as unused. Also, if it's not in a qr//, it doesn't report as unused. $ cat foo.pl #!/usr/bin/perl use warnings; use strict; my %x = {}; my %y = {}; my @z; my $this = qr/$x{$y{a}}/; my $that = qr/$x{$y->{a}}/; my $other = qr/$x{$z[1]}/; $this = $that = $other; # To make sure everything else is used. $ perlcritic --single-policy=ProhibitUnusedVarsStricter foo.pl %x is declared but not used at line 6, column 4. Unused variables clutter code and make it harder to read. (Severity: 3)
Thank you very much for the report. This looks to me very much like a PPIx-Regexp bug rather than a Perl-Critic bug per se. At any rate, $ predump 'qr/$x{$y{z}}/' qr/$x{$y{z}}/ PPIx::Regexp failures=0 PPIx::Regexp::Token::Structure 'qr' PPIx::Regexp::Structure::Regexp / ... / PPIx::Regexp::Token::Interpolation '$x' PPIx::Regexp::Structure::Quantifier { ... } PPIx::Regexp::Token::Interpolation '$y{z}' PPIx::Regexp::Token::Modifier '' which is incorrect -- everything in the qr// should be interpolation. I am going to requeue this ticket to the PPIx-Regexp queue based on the above dump. In the very unlikely event there turns out to be something in Perl-Critic itslef, I will either open a new ticket or requeue this one again. Unfortunately, though PPIx-Regexp is "my" module, I am not going to be in a position to work on it until maybe Thursday of next week (the 26th). Please feel free to rattle may cage if you get nothing substantive from me by the following week-end.
Well, I was able to do more than I thought. When I apply the attached patches to the PPIx-Regexp distribution and install it, I get what I understand to be the desired behavior. OK, only PPIx-Regexp-Token-Interpolate.patch is needed to fix the problem. The other adds a test of the new behavior. Would you mind giving this a try and see if it does what you want? I still don't see how I can actually upload something to PAUSE until the end of next week.
Subject: PPIx-Regexp-Token-Interpolation.patch
--- lib/PPIx/Regexp/Token/Interpolation.old 2015-03-20 12:44:52.000000000 -0400 +++ lib/PPIx/Regexp/Token/Interpolation.pm 2015-03-20 12:42:52.000000000 -0400 @@ -89,7 +89,7 @@ # Match the beginning of an interpolation. my $interp_re = - qr{ \A (?: [\@\$]? \$ [-\w&`'+^./\\";%=~:?!\@\$<>\[\]\{\},#] | + qr{ \A (?= [\@\$]? \$ [-\w&`'+^./\\";%=~:?!\@\$<>\[\]\{\},#] | \@ [\w\{] ) }smx; @@ -123,7 +123,7 @@ } # Make sure we start off plausibly - $tokenizer->find_regexp( $interp_re ) + defined $tokenizer->find_regexp( $interp_re ) or return; # See if PPI can figure out what we have @@ -280,11 +280,17 @@ and return 1; } - # If we have exactly one child which is a symbol, we accept it as a - # subscript. - @kids == 1 - and $kids[0]->isa( 'PPI::Token::Symbol' ) - and return 1; + # If the first child is a symbol, + if ( @kids && $kids[0]->isa( 'PPI::Token::Symbol' ) ) { + # Accept it if it is the only child + @kids == 1 + and return 1; + # Accept it if there are exactly two children and the second is + # a subscript. + @kids == 2 + and $kids[1]->isa( 'PPI::Structure::Subscript' ) + and return 1; + } # We reject anything else. return;
Subject: t-unit.patch
--- t/unit.old 2015-03-09 14:04:58.000000000 -0400 +++ t/unit.t 2015-03-20 12:50:07.000000000 -0400 @@ -37,6 +37,24 @@ value ( max_capture_number => [], undef ); value ( source => [], 'fubar' ); +tokenize( '/$x{$y{z}}/' ); +count ( 5 ); +choose ( 0 ); +class ( 'PPIx::Regexp::Token::Structure' ); +content ( '' ); +choose ( 1 ); +class ( 'PPIx::Regexp::Token::Delimiter' ); +content ( '/' ); +choose ( 2 ); +class ( 'PPIx::Regexp::Token::Interpolation' ); +content ( '$x{$y{z}}' ); +choose ( 3 ); +class ( 'PPIx::Regexp::Token::Delimiter' ); +content ( '/' ); +choose ( 4 ); +class ( 'PPIx::Regexp::Token::Modifier' ); +content ( '' ); + { # The navigation tests get done in their own local scope so that all
PPIx-Regexp 0.038_01 just went to PAUSE. It fixes (I hope!) this problem, plus adds a boundary (\b{g}) omitted from 0.038.
PPIx-Regexp 0.039 just went to PAUSE, with no changes (except version!) from 0.038_01.