in reply to How to do "use Mumble ':all' " ala CGI.pm

You could create a class that inherits from Exporter to do the magic, thus hiding the "oogliness".
package MyExporter; use Exporter (); BEGIN { our @ISA = 'Exporter'; } sub import { our @EXPORT_OK; our @EXPORT_TAGS; #my $pkg = \%::; #$pkg = $pkg->{$_} foreach ((caller().'::') =~ /\G(.*::)/g); my $pkg = caller() . '::'; { no strict 'refs'; $pkg = *$pkg; } local *EXPORT_OK = $pkg->{'EXPORT_OK'}; local *EXPORT_TAGS = $pkg->{'EXPORT_TAGS'}; { # Expand tag names into referenced name sets my %seen; $EXPORT_TAGS{all} = [ grep { !$seen{$_}++ } map { m/^:(.*)$/ ? @{$EXPORT_TAGS{$1}} : $_ } @{$EXPORT_TAGS{all}} ]; } { # Add tag set names not already listed into @EXPORT_OK my %seen; $seen{$_}++ foreach @EXPORT_OK; push @EXPORT_OK, grep { !$seen{$_}++ } @{$EXPORT_TAGS{$_}} foreach keys %EXPORT_TAGS; } &Exporter::import; }

Then your module becomes:

package LISConst; use vars qw($VERSION @ISA %EXPORT_TAGS); require MyExporter; @ISA = qw(MyExporter); $VERSION = '0.01'; %EXPORT_TAGS = ( hdr_lens => [qw( LIS_TIF_HDR_LEN LIS_TIF_HDR_DATA_MAX LIS_PHY_HDR_LEN LIS_LR_HDR_LEN )], phyhdr_flags => [qw( . . . . )], lr_types => [qw( . . . . )], );

Replies are listed 'Best First'.
Re^2: How to do "use Mumble ':all' " ala CGI.pm
by ikegami (Patriarch) on Sep 20, 2004 at 05:55 UTC

    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)