blob: 9f2014978d85f34f241bf2169c285ffa9bbdc151 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
|