Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using attribute notation for a reference argument to an option gives an error :Export( -(?) ) #2

Closed
tabulon opened this issue May 21, 2023 · 2 comments

Comments

@tabulon
Copy link

tabulon commented May 21, 2023

The following example from the documentation doesn't actually compile :

# Ask for one argument but only if it is a ref of some kind.
# If it is a hashref, this also processes import options like -prefix, -replace, etc.
sub name : Export( -name(?) ) {
  my ($exporter, $maybe_arg)= @_;
  ...
}

Instead, it gives the following error : Couldn't compile '...' to inspect: Invalid export notation '-name(?)'

Same thing for the shorter version:

sub name : Export( -(?) ) {
  my ($exporter, $maybe_arg)= @_;
  ...
}

A quick inspection suggests a missing part in the relevant regex -- at line 622 of Exporter/Extensible.pm (as of version 0.10 at commit bd91114):

...
elsif ($token =~ /^-(\w*)(?:\(([0-9]+|\*)\))?$/) {
   ...
}

It should probably have a term for the question mark (?) in there, like so:

...
elsif ($token =~ /^-(\w*)(?:\(([0-9]+|\*|\?)\))?$/) {
   ...
}
tabulon pushed a commit to tabulon-ext/perl-Exporter-Extensible that referenced this issue May 21, 2023
nrdvana added a commit that referenced this issue May 21, 2023
Fix issue #2: Attribute notation for a ref. arg. gives an error
@nrdvana
Copy link
Owner

nrdvana commented May 21, 2023

Indeed! I've apparently never tried using this feature declared as an attribute. Thanks for the fix.

nrdvana added a commit that referenced this issue May 21, 2023
I had commented out the unit tests for options with parameters
because is_deeply can't compare anonymous coderefs.  I changed
the mechanism of the test to eval the entire is_deeply line
instead of trying to eval individual pieces, because the latter
was very confusing to read.  Now that it's evaled code, I can
just test that the options with parameters created coderefs.

Meanwhile, I also discovered that the test for EXPORT_TAGS was
not getting run at all.  I fixed that, and fixed some typos in
the code.

I also added a test for option-with-params notation '-(?)'
as reported in #2.
@nrdvana
Copy link
Owner

nrdvana commented May 21, 2023

Released in version 0.11

@nrdvana nrdvana closed this as completed May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants