Ovid,
Moose does not have built in support for class methods (the rationale
for this is almost certainly not interesting to you at the moment :)
(see my class-methods rant on p6-language from a few years ago, that
about sums it up)), you simply use the techniques you have always
used, like Class::Data::Inheritable or package level variables and
methods to access them.
I suspect that you might find MooseX::ClassAttribute useful, it is
class-level attributes (which then means class-level accessors too)
and sounds like it would do what you need.
- Stevan
On Oct 22, 2008, at 11:16 AM, Ovid wrote:
I'm working on a legacy system with a database which has some
issues. Right now, I need to populate a Moose enum with allowable
enum values from a database. The problem is that the Moose objects
don't know about the database when they're used (or even when
they're instantiated), thus making it impossible to populate those
enums.
Until we have time to fix this bug, I need a work around. It seems
to me that if I had access to class data in Moose, I could have
something like this (by the time this is called, we're guaranteed to
have database access):
sub authorities {
my ( $self, $schema ) = @_;
unless ( $self->_authorities ) { # class data
$self->_authories(
# get enum values from the database
);
}
return $self->_authories;
}
This is a really nasty hack, but we simply don't have time to fix
this issue prior to our next release. However, I can't figure out
how to declare a method as a class method short of using
Class::Data::Inheritable. Is there a better way of handling this?
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6