Hello dear esteemed monks,
I would like to be able to add per-package configuration parameters to the use statement of my module, but also let the module export some functions. Something like:
use My::Module { hairiness => 2 }, qw(:core frobnicate); frobnicate( $foo ); # with hairiness = 2
I came up with the following:
package My::Module; use parent qw(Exporter); our @EXPORT_OK = qw(frobnicate); our %EXPORT_TAGS = ( core => [], ); sub import { # or do it via a foreach and extra @args array my %setup = map { %$_ } grep { ref $_ eq 'HASH' } @_; @_ = grep { ref $_ ne 'HASH' } @_; $_[0]->per_package_setup( scalar caller, %setup ); goto \&Exporter::import; }; my %per_package_conf; # or our?.. sub per_package_setup { my ($self, $target, %options) = @_; # setup for target }; sub frobnicate { my $x = shift; return $x; # TODO actually use parameters here };
I don't want to remove exporter because it does the job and is predictable (and also has export tags).
Are there better/shorter/more common ways to do the same?
Thank you.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |