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;