summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Granum <exodist7@gmail.com>2016-07-12 21:53:09 -0700
committerChad Granum <exodist7@gmail.com>2016-07-12 21:53:09 -0700
commite1778049ea3b945efb8103d41e0413931f4d9c20 (patch)
tree699729e57e32ddf222151284ae9ed7da748cd754
parenta0a355a48d62ab39203ab81855928363db51f2de (diff)
Add :ALL tag
-rw-r--r--Changes2
-rw-r--r--lib/Importer.pm9
-rw-r--r--t/all_tag.t47
-rw-r--r--t/units.t4
4 files changed, 60 insertions, 2 deletions
diff --git a/Changes b/Changes
index 25525d8..77448c8 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
{{$NEXT}}
+ - Add :ALL tag when none is pre-defined
+
0.013 2016-07-09 16:00:05-07:00 America/Los_Angeles
- Add extra params to custom symbol setters
diff --git a/lib/Importer.pm b/lib/Importer.pm
index ee3ffd2..39e9407 100644
--- a/lib/Importer.pm
+++ b/lib/Importer.pm
@@ -2,7 +2,7 @@ package Importer;
use strict qw/vars subs/; # Not refs!
use warnings; no warnings 'once';
-our $VERSION = '0.013';
+our $VERSION = '0.014';
my %SIG_TO_SLOT = (
'&' => 'CODE',
@@ -400,6 +400,9 @@ sub reload_menu {
'DEFAULT' => [ @$export ],
};
+ # Add 'ALL' tag unless already specified. We want to normalize it.
+ $tags->{ALL} ||= [ sort grep {m/^[\&\$\@\%\*]/} keys %$lookup ];
+
my $fail = @$export_fail ? {
map {
my ($sig, $name) = (m/^(\W?)(.*)$/);
@@ -860,6 +863,10 @@ You can define/import subsets of symbols using predefined tags.
use Importer 'Some::Thing' => ':tag';
+L<Importer> will automatically populate the C<:DEFAULT> tag for you.
+L<Importer> will also give you an C<:ALL> tag with ALL exports so long as the
+exporter does not define a C<:ALL> tag already.
+
=head2 /PATTERN/ or qr/PATTERN/
You can import all symbols that match a pattern. The pattern can be supplied a
diff --git a/t/all_tag.t b/t/all_tag.t
new file mode 100644
index 0000000..f8a8468
--- /dev/null
+++ b/t/all_tag.t
@@ -0,0 +1,47 @@
+use Test::More;
+use strict;
+use warnings;
+
+BEGIN {
+ $INC{'My/Exporter/A.pm'} = __FILE__;
+ $INC{'My/Exporter/B.pm'} = __FILE__;
+
+ package My::Exporter::A;
+
+ our @EXPORT = qw/foo bar/;
+ our @EXPORT_OK = qw/baz bat/;
+
+ sub foo { 'foo' }
+ sub bar { 'bar' }
+ sub baz { 'baz' }
+ sub bat { 'bat' }
+
+ package My::Exporter::B;
+
+ our @EXPORT = qw/foo bar/;
+ our @EXPORT_OK = qw/baz bat/;
+
+ our %EXPORT_TAGS = (
+ ALL => [qw/foo/],
+ );
+
+ sub foo { 'foo' }
+ sub bar { 'bar' }
+ sub baz { 'baz' }
+ sub bat { 'bat' }
+}
+
+subtest "define ALL tag if missing" => sub {
+ package Importer::A;
+ use Importer 'My::Exporter::A' => ':ALL';
+ main::can_ok(__PACKAGE__, qw/foo bar baz bar/);
+};
+
+subtest "do not override ALL tag if defined" => sub {
+ package Importer::B;
+ use Importer 'My::Exporter::B' => ':ALL';
+ main::can_ok(__PACKAGE__, qw/foo/);
+ main::ok(!__PACKAGE__->can($_), "Did not import $_") for qw/bar baz bat/;
+};
+
+done_testing;
diff --git a/t/units.t b/t/units.t
index 35da589..850da4e 100644
--- a/t/units.t
+++ b/t/units.t
@@ -287,7 +287,7 @@ subtest reload_menu => sub {
{
lookup => {},
exports => {},
- tags => { DEFAULT => [] },
+ tags => { DEFAULT => [], ALL => [] },
fail => undef,
generate => undef,
magic => {},
@@ -386,6 +386,7 @@ subtest reload_menu => sub {
tags => {
b => [qw/bar baz/],
DEFAULT => [qw/foo &bar $ZAP %ZAP @ZAP/],
+ ALL => [sort qw/&foo &bar &baz &ick &missing &x &z &gena &genb %ZAP $ZAP @ZAP/],
},
fail => { '&ick' => 1, ick => 1 },
magic => {},
@@ -472,6 +473,7 @@ subtest reload_menu => sub {
tags => {
b => [qw/bar baz/],
DEFAULT => [qw/foo &bar $ZAP %ZAP @ZAP/],
+ ALL => [sort qw/&foo &bar &baz &ick &missing &x &z &gena &genb %ZAP $ZAP @ZAP/],
},
fail => { '&ick' => 1, ick => 1 },
magic => {},