K
kj
One thing that bugs me about the Export module is that even when
you want the module to export everything, one still has to register
things in @EXPORT. I find it particularly annoying in cases when
I have a module that contains only constants to be shared by other
modules and scripts, like this:
# file My_Constants.pm
package My_Constants;
use base 'Exporter';
our @EXPORT = qw(FOO BAR ... );
use constant FOO => 1;
use constant BAR => 4;
# etc.
1;
# file some_script.pl
use My_Constants;
printf "%d %d\n", FOO, BAR;
Instead, I think I would prefer to do something like this:
# file My_Constants.pm
package My_Constants;
use constant FOO => 1;
use constant BAR => 4;
# etc.
1;
# file some_script.pl
use My_Constants;
our $Const = bless \{ my $c }, 'My_Constants';
printf "%d %d\n", $Const->FOO, $Const->BAR;
It works, though I've never thing anything like this done. Is
there anything particularly wrong with it?
Thanks,
kj
you want the module to export everything, one still has to register
things in @EXPORT. I find it particularly annoying in cases when
I have a module that contains only constants to be shared by other
modules and scripts, like this:
# file My_Constants.pm
package My_Constants;
use base 'Exporter';
our @EXPORT = qw(FOO BAR ... );
use constant FOO => 1;
use constant BAR => 4;
# etc.
1;
# file some_script.pl
use My_Constants;
printf "%d %d\n", FOO, BAR;
Instead, I think I would prefer to do something like this:
# file My_Constants.pm
package My_Constants;
use constant FOO => 1;
use constant BAR => 4;
# etc.
1;
# file some_script.pl
use My_Constants;
our $Const = bless \{ my $c }, 'My_Constants';
printf "%d %d\n", $Const->FOO, $Const->BAR;
It works, though I've never thing anything like this done. Is
there anything particularly wrong with it?
Thanks,
kj