Skip Menu |
 

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

Report information
The Basics
Id: 110356
Status: resolved
Priority: 0/
Queue: Regexp-Grammars

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

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



Subject: $MATCH var no longer visible in grammar syntax

Take this otherwise slightly contrived code:

 

use strict;
use warnings;

use Regexp::Grammars;
my $grammar = qr{
        "
        <[MATCH=(.)]>+
        "
        <MATCH=(?{ join q[], @{$MATCH} })>
}x;

use Data::Dumper qw(Dumper);
if( q["helloworld"] =~ $grammar ) {
  print Dumper( \%/ );
}

 

On 1.042 , this code executes as expected without error.

On 1.043, this code fails with

---

Global symbol "$MATCH" requires explicit package name (did you forget to declare "my $MATCH"?) at /tmp/reg.pl line 10.
---

 

Explicitly declaring "our $MATCH" before the `my $grammar` does indeed resolve the issue, but it was not documented in 1.043's changes that this was to be expected.

 

If I had to guess why its not working as expected, I'd say the change to using `vars.pm` to create those vars may be importing them into the wrong package.

( seeing vars.pm uses caller() and not compile-context,  https://metacpan.org/source/RJBS/perl-5.22.0/lib/vars.pm#L11 , and given I cant see anything that would change what caller reported in R:G:import

 

 

Attached is a simple test that tests that Regexp::Grammars can see any of the MATCH variables, and it fails all of them on 1.043 and passes all of them on 1.042
Subject: regx_grammars.t
Download regx_grammars.t
text/x-perl 413b
use strict; use warnings; # ABSTRACT: Test Regexp::Grammars exports package symbols. use Regexp::Grammars; use Test::More; sub has_var { my ($varname) = @_; local $@; eval <<"EOF"; my \$grammar = qr{<MATCH=(?{ $varname })>} EOF note $@ if $@; return !$@; } for my $varname (qw( $CAPTURE $CONTEXT $DEBUG $INDEX $MATCH %ARG %MATCH )) { ok( has_var($varname), "Has $varname" ); } done_testing;
Attached is the simplest patch that might work, and does, and other tests continue passing.
Subject: grammars.patch
Download grammars.patch
text/x-diff 582b
--- lib/Regexp/Grammars.pm 2015-12-15 23:29:46.000000000 +1300 +++ lib/Regexp/Grammars.pm 2015-12-15 23:30:36.997096571 +1300 @@ -63,7 +63,9 @@ # Sanctify the standard Regexp::Grammars pseudo-variables from # Perl 5.18's early enforcement of strictures... - vars->import( '$CAPTURE', '$CONTEXT', '$DEBUG', '$INDEX', '$MATCH', '%ARG', '%MATCH' ); + eval q[package ] . [ caller() ]->[0]. q[; + vars->import( '$CAPTURE', '$CONTEXT', '$DEBUG', '$INDEX', '$MATCH', '%ARG', '%MATCH' ); + ]; warnings->unimport('once'); } }
Download (untitled) / with headers
text/plain 251b
Thanks for the report, and more especially for the test file and the patch. I've just uploaded a new release that uses a variation on your fix, and seems to solve the problem. Please let me know if you find otherwise. Very much appreciated, Damian


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.