export constants nicely from perl module...
Wesley Darlington
wesley at yelsew.com
Fri Feb 6 05:49:53 CST 2004
Hi Folks,
I'm a little bit leery of asking a perl question on belfast-pm, but
here goes... :-)
Imagine a module that does nothing more than export a load of constants:
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
package Widget::Config;
use base 'Exporter';
our @EXPORT_OK = qw(widget_dir max_widgets);
use constant widget_dir => '/usr/local/widget/conf';
use constant max_widgets => 42;
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
I resent having to give the name of each constant twice. (I'm going to
call this 'syntactic soot' - better descriptions welcome!)
I'm wondering if there's a better way. Perhaps something like...
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
package Widget::Config;
use base 'Exporter::Constants';
econst widget_dir => '/usr/local/widget/conf';
econst max_widgets => 42;
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
...but as long as its syntactically reasonably sweet, I don't mind
what it looks like. There will be lots of constants.
Does anything like this exist? Would some kind soul like to nudge me in
an appropriate direction...? :-)
Thanks,
Wesley.
More information about the Belfast-pm
mailing list