in reply to Exporting constants from a Moo role
I think that constants are not object-oriented, at least not the way that Moo thinks, and thus they are not exported.
I think the somewhat hacky, but somewhat yet established way to get at the constants would be to call them as (class) methods, just like Java implements some constants:
$self->INDEX_FOO # or MyClass->INDEX_FOO
Of course, you then incur the penalty of making a method call where a real constant could even have been inlined.
I'm not sure how well Moo (and Moo::Role) and Exporter mix, but maybe you can implicitly export your constants to all modules using your role:
package MyRole; use Moo::Role; use constant INDEX_FOO => 42; use Exporter 'import'; our @EXPORT = ('INDEX_FOO');
If all else fails, you'll have to create a special module that just contains the constants...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Exporting constants from a Moo role
by 1nickt (Canon) on Aug 02, 2018 at 21:25 UTC |