summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Granum <exodist7@gmail.com>2016-08-21 16:07:14 -0700
committerChad Granum <exodist7@gmail.com>2016-08-21 16:09:16 -0700
commitc38b7e56ec9008f9921388287555529915d7ad0e (patch)
tree41ee67a926d51083d7d938340cebbb6ade56e2c2
parentb88245af9ebccbd501072b63f309e5b1592cd8b2 (diff)
Make it possible to rename 'v0'
-rw-r--r--Changes2
-rw-r--r--lib/Importer.pm14
-rw-r--r--t/versions.t23
3 files changed, 33 insertions, 6 deletions
diff --git a/Changes b/Changes
index 0ab79cf..ee19047 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
{{$NEXT}}
+ - Allow renaming of the 'v0' version set
+
0.017 2016-08-20 22:57:17-07:00 America/Los_Angeles (TRIAL RELEASE)
- Add on_use/sub EXPORT_ON_USE { ... } feature
diff --git a/lib/Importer.pm b/lib/Importer.pm
index 024860a..8ae5e7b 100644
--- a/lib/Importer.pm
+++ b/lib/Importer.pm
@@ -424,8 +424,9 @@ sub _build_menu {
my $common_v = delete $export_vers->{'*'};
+ my $root_ver = delete $export_vers->{'root_name'} || 'v0';
my $versions = {
- v0 => { # Add base as v0, do not use the same hashref to avoid self-refrencing
+ $root_ver => { # Add root as v0 or root_name, do not use the same hashref to avoid self-refrencing
lookup => $lookup,
exports => $exports,
fail => $fail,
@@ -643,7 +644,7 @@ sub { *{"$into\\::\$_[0]"} = \$_[1] }
EOT
my $menu = $main_menu;
- my $ver = 'v0';
+ my $ver = '<NO VERSION SPECIFIED>';
my $ver_str = "";
my %used;
for my $set (@$import) {
@@ -974,7 +975,7 @@ to provide alternate versions of exports. This is useful for maintaining
backwards compatibility while providing a path forward.
Importing without specifying a version set uses the default version set, which
-is also called 'v0'.
+is usually called 'v0', but can be given a different name by an exporter.
You can specify an alternate version set with the '+' prefix:
@@ -1006,7 +1007,8 @@ v0 set.
=back
Not all exporters provide versioned exports, but '+v0' is automatically
-generated and always present.
+generated and always present (though may be given a different name by the
+exporter).
See L</%EXPORT_VERSIONS> for details on providing version-sets from an
exporter.
@@ -1198,6 +1200,10 @@ changes.
);
our %EXPORT_VERSIONS = (
+ # The 'root_name' option is special, ot lets you rename 'v0' to
+ # anything you want.
+ root_name => 'v0',
+
# The '*' version is special, it gets mixed into all versions
# (including v0 and the root menu).
'*' => {
diff --git a/t/versions.t b/t/versions.t
index 2bb8061..2e70245 100644
--- a/t/versions.t
+++ b/t/versions.t
@@ -74,6 +74,20 @@ BEGIN {
},
);
}
+
+ $INC{'My/Exporter2.pm'} = 1;
+ package My::Exporter2;
+
+ sub IMPORTER_MENU {
+ return (
+ export_anon => {
+ foo => sub { 'foo' },
+ },
+ export_versions => {
+ root_name => 'my_root_ver',
+ },
+ );
+ }
}
{
@@ -115,17 +129,22 @@ BEGIN {
::ok(!__PACKAGE__->can('d'), "Did not import d()");
}
+{
+ package My::Importer::D;
+ Importer->import('My::Exporter2', '+my_root_ver', 'foo');
+ ::can_ok(__PACKAGE__, 'foo');
+}
$main::ON_USE = 1;
{
package My::On::Use::A;
Importer->import('My::Exporter');
::can_ok(__PACKAGE__, 'x');
- ::is($main::USED{v0}, 1, "noted that we used v0");
+ ::is($main::USED{'<NO VERSION SPECIFIED>'}, 1, "noted that we used v0");
package My::On::Use::B;
Importer->import('My::Exporter');
- ::is($main::USED{v0}, 2, "noted that we used v0 again");
+ ::is($main::USED{'<NO VERSION SPECIFIED>'}, 2, "noted that we used v0 again");
package My::On::Use::C;
Importer->import('My::Exporter', ':v1');