PopeFelix has asked for the wisdom of the Perl Monks concerning the following question:
Suppose I want to do the following:
use MyModule 'foo' => 'bar', qw/do_something do_something_else/;
So I want to:
- Set the global configuration value foo to 'bar'
- import the class methods do_something and do_something_else into my namespace
Assume for this example that I don't need to be able to specify the value for foo at runtime.
I can define MyModule like so:package MyModule; our @EXPORT_OK = qw/do_something do_something_else/; my $FOO; sub import { my ($class, %config) = @_; $FOO = $config{'foo'}; } sub do_something { if ($FOO eq 'foo') { # do something here } else { # do something else } } sub do_something_else { if ($FOO eq 'foo') { # do something else here } else { # do something other than else } } 1;
But how would I then pass ('do_something', 'do_something_else') to Exporter?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Importing methods and configuration at the same time?
by tobyink (Canon) on Aug 29, 2013 at 17:37 UTC |
Back to
Seekers of Perl Wisdom