New Skool Constants
package NewSkool::Constants; use strict; use warnings; use base 'Badger::Exporter'; use constant { MESSAGE => 'Hello World!', VOLUME => 11, TRUE => 1, FALSE => 0, }; our $VERSION = 2; our $EXPORT_ALL = 'MESSAGE'; our $EXPORT_ANY = 'TRUE FALSE VOLUME'; our $EXPORT_TAGS = { truth => 'TRUE FALSE' }
Thus Spake Andy:
The Badger::Exporter version is more-or-less the same as the previous
example with just a few name changes. This time you're subclassing from
Badger::Exporter instead of Exporter and you set $EXPORT_ALL,
$EXPORT_ANY and $EXPORT_TAGS ($EXPORT_HOOKS and $EXPORT_FAIL are also
available). We use different variables from Exporter to avoid any potential
clashes with modules that aren't expecting to be used in an OO fashion. We use
scalar variables because... and here comes the science bit... scalar variables
in Perl are polymorphic. What that means in practice is that a scalar variable
can hold a simple string, or a reference to a list, hash array, subroutine, or
something else. We can let the coder choose whatever is best for them (e.g. a
simple string for the simple cases, a hash or list ref for more complex stuff)
and leave it to Badger to Do The Right Thing™.