summaryrefslogtreecommitdiffstats
path: root/lib/Sub/Exporter/Declare.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sub/Exporter/Declare.pm')
-rw-r--r--lib/Sub/Exporter/Declare.pm38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Sub/Exporter/Declare.pm b/lib/Sub/Exporter/Declare.pm
new file mode 100644
index 0000000..9f20149
--- /dev/null
+++ b/lib/Sub/Exporter/Declare.pm
@@ -0,0 +1,38 @@
+package Sub::Exporter::Declare;
+use strict;
+use warnings;
+
+my %EXPORT_DATA;
+
+use Sub::Exporter 'build_exporter', -setup => {
+ exports => [qw(export export_default), import => \&import_generator],
+ groups => {
+ default => [qw(export export_default import)],
+ },
+};
+
+sub export {
+ my @exports = @_;
+ my $caller = caller;
+ $EXPORT_DATA{$caller} ||= {};
+ push @{ $EXPORT_DATA{$caller}->{exports} ||= [] }, @exports;
+}
+
+sub export_default {
+ my @exports = @_;
+ my $caller = caller;
+ $EXPORT_DATA{$caller} ||= {};
+ push @{ $EXPORT_DATA{$caller}->{exports} ||= [] }, @exports;
+ push @{ $EXPORT_DATA{$caller}->{groups}{default} ||= [] }, @exports;
+}
+
+sub import_generator {
+ my ($class, $name, $arg, $col) = @_;
+ return sub {
+ my ($package) = @_;
+ my $import = build_exporter($EXPORT_DATA{$package});
+ goto $import;
+ };
+}
+
+1;