in reply to Re: How to do "use Mumble ':all' " ala CGI.pm
in thread How to do "use Mumble ':all' " ala CGI.pm
Even better, a version that expands ':' deeply (Update:) AND handles !:tag...
package MyExporter; use Exporter (); BEGIN { our @ISA = 'Exporter'; } sub import { our @EXPORT; our @EXPORT_OK; our @EXPORT_TAGS; #my $pkg = \%::; #$pkg = $pkg->{$_} foreach ((caller().'::') =~ /\G(.*::)/g); my $pkg = caller() . '::'; { no strict 'refs'; $pkg = *$pkg; } local *EXPORT = $pkg->{'EXPORT'}; local *EXPORT_OK = $pkg->{'EXPORT_OK'}; local *EXPORT_TAGS = $pkg->{'EXPORT_TAGS'}; $EXPORT_TAGS{'all'} = [ @EXPORT, @EXPORT_OK, @EXPORT_TAGS ]; { # Expand :tag into components, deeply. # Cycles are silently broken in an arbitrary manner. my %expanded; my $expand = sub { my ($key) = @_; return if ($expanded{$key}++); my %list; foreach (@{$EXPORT_TAGS{$key}}) { if (/^!(:.*)/) { my $tag = $1; &$expand($tag); delete(@list{@{$EXPORT_TAGS{$tag}}}); } elsif (/^:.*/) { my $tag = $_; &$expand($tag); %list = (%list, map { $_ => 1 } @{$EXPORT_TAGS{$tag}}); } else { $list{$_} = 1; } } @{$EXPORT_TAGS{$key}} = keys(%list); }; &$expand($_) foreach (keys(%EXPORT_TAGS)); } &Exporter::import; }
(untested)
|
|---|