Badger::Class for Introspection
package Your::Forager; use Badger::Class base => 'Badger::Base', import => 'class'; our $FOO = 10; sub init { my ($self, $config) = @_; $self->{ foo } = $config->{ foo } || $self->class->any_var('FOO'); return $self; }
Note: Just Works™ with inheritance
Thus Spake Andy:
If you call any_var()
instead of var()
then it will not only look in the
correct package for a variable, but will walk up the inheritance chain. This
means that your subclasses don't have to define their own package variables
and can effectively "inherit" those in the base class. However, at any point
they can define their own package variables and these will be used in
preference to those in the base class.