summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-10 17:21:17 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-10 17:21:17 -0400
commitaa3f08493d04303e253459eeb8182d8352984ace (patch)
tree224ef2737939349d370e994673cc559b07d5d4d7
parent4fcfb4266551771b302eb4d4a3fcf40c7bffada8 (diff)
downloadexporter-lexical-aa3f08493d04303e253459eeb8182d8352984ace.tar.gz
exporter-lexical-aa3f08493d04303e253459eeb8182d8352984ace.zip
allow getting functions to export from other places
-rw-r--r--lib/Exporter/Lexical.pm10
-rw-r--r--t/export-hash.t22
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/Exporter/Lexical.pm b/lib/Exporter/Lexical.pm
index 48e4d72..5714dca 100644
--- a/lib/Exporter/Lexical.pm
+++ b/lib/Exporter/Lexical.pm
@@ -77,8 +77,14 @@ sub build_exporter {
no strict 'refs';
\%{ $caller . '::' };
};
- my @exports = @{ $opts->{'-exports'} };
- my %exports = map { $_ => \&{ $caller_stash->{$_} } } @exports;
+ my %exports;
+ if (ref($opts->{'-exports'}) eq 'ARRAY') {
+ %exports = map { $_ => \&{ $caller_stash->{$_} } }
+ @{ $opts->{'-exports'} };
+ }
+ elsif (ref($opts->{'-exports'}) eq 'HASH') {
+ %exports = %{ $opts->{'-exports'} };
+ }
for my $export (keys %exports) {
lexical_import($export, $exports{$export});
diff --git a/t/export-hash.t b/t/export-hash.t
new file mode 100644
index 0000000..e637a40
--- /dev/null
+++ b/t/export-hash.t
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+
+package Foo {
+ use Exporter::Lexical -exports => {
+ foo => sub { "FOO" },
+ };
+ BEGIN { $INC{'Foo.pm'} = __FILE__ }
+}
+
+sub foo { 'foo' }
+
+is(foo(), 'foo');
+{
+ use Foo;
+ is(foo(), 'FOO');
+}
+is(foo(), 'foo');
+
+done_testing;