Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Sub-Exporter-Progressive CPAN distribution.

Report information
The Basics
Id: 83491
Status: resolved
Priority: 0/
Queue: Sub-Exporter-Progressive

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc: ribasushi [...] leporine.io
AdminCc:

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



Subject: Inconsistency handling numeric import arguments between Exporter.pm and Sub::Exporter
I've discussed this with mst before and he suggested a patch for Sub::Exporter::Progressive. Well, here it is. Brief summary: Exporter.pm tries to replicate the Perl built-in module version check, e.g. use Carp 1.0; ... but allowing the version number to appear anywhere in the import list, a la: use Carp 'croak', 1.0; It's not an especially well-implemented or well-documented feature, and it's a difference between Exporter.pm and Sub::Exporter. So this patch bans it from being used with Sub::Exporter::Progressive.
Subject: Sub-Exporter-Progressive-no_leading_digits.patch
diff -urN Sub-Exporter-Progressive-0.001008/lib/Sub/Exporter/Progressive.pm Sub-Exporter-Progressive-0.001008-tobyink/lib/Sub/Exporter/Progressive.pm --- Sub-Exporter-Progressive-0.001008/lib/Sub/Exporter/Progressive.pm 2013-01-21 23:08:15.000000000 +0000 +++ Sub-Exporter-Progressive-0.001008-tobyink/lib/Sub/Exporter/Progressive.pm 2013-02-20 22:13:53.919555563 +0000 @@ -29,6 +29,8 @@ $full_exporter ||= Sub::Exporter::build_exporter($export_data->{original}); goto $full_exporter; + } elsif (defined(my $num = first { !ref and m/^\d/ } @args)) { + croak "cannot export symbols with a leading digit: '$num'"; } else { require Exporter; s/ \A - /:/xm for @args; diff -urN Sub-Exporter-Progressive-0.001008/t/version-check.t Sub-Exporter-Progressive-0.001008-tobyink/t/version-check.t --- Sub-Exporter-Progressive-0.001008/t/version-check.t 1970-01-01 01:00:00.000000000 +0100 +++ Sub-Exporter-Progressive-0.001008-tobyink/t/version-check.t 2013-02-20 22:14:13.815654228 +0000 @@ -0,0 +1,78 @@ +=head1 PURPOSE + +Exporter.pm does this silly thing where it interprets import arguments +starting with a digit as being a version check. + +For example, given this, Exporter.pm will check that Carp.pm's version +number is at least 1000 (unlikely!) + + $ perl -e'use Carp carp => "1000"' + +If the number appears first in the import list, Perl will already do +this for you, not involving Exporter.pm at all: + + $ perl -e'use Carp 1000, "carp"' + +So it's not obvious why this feature was included in Exporter.pm at all. +Not many people seem to have noticed the feature is even there, though +it is documented. (However, the documentation of it does not quite match +its implementation!) + +Anyhow, this feature seems a bad idea to use, and more importantly it +leads to a difference between how Exporter.pm and Sub::Exporter work. +Sub::Exporter::Progressive should attempt to smooth over such differences, +so it should I<always> croak in this situation, whether Exporter.pm or +Sub::Exporter is being used. + +=head1 AUTHOR + +Toby Inkster (cpan:TOBYINK) + +=cut + +use strict; +use warnings; +use Test::More; + +BEGIN { + package AAA; + our $VERSION = 2; + use Sub::Exporter::Progressive -setup => { + exports => ['aaa'], + }; + sub aaa { 'aaa' }; + $INC{'AAA.pm'} = __FILE__; +}; + +ok( + eval('use AAA 1; 1'), + "Plain old Perl built-in module version check; eval expected to live", +); + +{ + local $@; + ok( + !eval('use AAA 3; 1'), + "Plain old Perl built-in module version check; eval expected to die", + ); + like( + $@, + qr{^AAA version 3 required}, + "Correct error message from Perl built-in module version check", + ); +} + +{ + local $@; + ok( + !eval('use AAA aaa => 1; 1'), + "Exporter.pm-style version check blocked by Sub::Exporter::Progressive", + ); + like( + $@, + qr{^cannot export symbols with a leading digit: '1'}, + "Correct error message from Sub::Exporter::Progressive", + ); +} + +done_testing;
On Wed Feb 20 17:20:01 2013, TOBYINK wrote: Show quoted text
> I've discussed this with mst before and he suggested a patch for > Sub::Exporter::Progressive. Well, here it is. > > Brief summary: Exporter.pm tries to replicate the Perl built-in module > version check, e.g. > > use Carp 1.0; > > ... but allowing the version number to appear anywhere in the import > list, a la: > > use Carp 'croak', 1.0; > > It's not an especially well-implemented or well-documented feature, and > it's a difference between Exporter.pm and Sub::Exporter. > > So this patch bans it from being used with Sub::Exporter::Progressive.
The goal of Sub::Exporter::Progressive is to work on the importee with Sub::Exporter if the user tries to use Sub::Exporter features, and just Exporter.pm if the user does not use such featuers. This patch completely breaks that feature if the user uses a certain Sub::Exporter feature. Please fix the patch so it just upgrades to Sub::Exporter instead of die'ing.
On Fri Mar 08 09:22:31 2013, frew wrote: Show quoted text
> On Wed Feb 20 17:20:01 2013, TOBYINK wrote:
> > I've discussed this with mst before and he suggested a patch for > > Sub::Exporter::Progressive. Well, here it is. > > > > Brief summary: Exporter.pm tries to replicate the Perl built-in module > > version check, e.g. > > > > use Carp 1.0; > > > > ... but allowing the version number to appear anywhere in the import > > list, a la: > > > > use Carp 'croak', 1.0; > > > > It's not an especially well-implemented or well-documented feature, and > > it's a difference between Exporter.pm and Sub::Exporter. > > > > So this patch bans it from being used with Sub::Exporter::Progressive.
> > The goal of Sub::Exporter::Progressive is to work on the importee with > Sub::Exporter if the user tries to use Sub::Exporter features, and just > Exporter.pm if the user does not use such featuers. This patch > completely breaks that feature if the user uses a certain Sub::Exporter > feature. Please fix the patch so it just upgrades to Sub::Exporter > instead of die'ing.
.:09:24:20:. >> ilmari<< frew: the numeric argument is an Exporter feature that's _not_ in Sub::Exporter .:09:24:35:. < frew> oh did I read what he said backwards? .:09:24:38:. < ilmari> yes .:09:24:47:. < ilmari> https://metacpan.org/module/Exporter#Module-Version-Checking DOH! Sorry about that :) Ok, so your patch is correct then. Will merge shortly.
On Fri Mar 08 09:26:32 2013, frew wrote: snip Show quoted text
> DOH! Sorry about that :) Ok, so your patch is correct then. Will > merge shortly.
Ok, I took the patch. I changed it some but fundamentally it's the same content: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit/Sub-Exporter-Progressive.git;a=commitdiff;h=d9568f3addf9f9abf5f9e6dc4821a08f008c4d43 (Surely RT will ruin that url.)