Todd Hepler wrote:
Dmitri wrote:
Is there a clean way to share data from class in a role?
If it was an object method I would probably set up attribute for
that, but it's a class method.
package FN::Utils;
use Moose::Role;
# class method
sub some_db_op {
need $TABLE from consuming class here
}
package FN::User;
use Moose;
with qw(FN::Utils FN::Contact);
my $TABLE = 'fnuser';
.....
You could actually use a (class) method instead of "my $TABLE".
Something like:
package FN::Utils;
use Moose::Role;
requires '_table';
sub some_db_op {
my $self = shift;
# call $self->_table somewhere
# ...
}
package FN::User;
use Moose;
with qw(FN::Utils FN::Contact);
sub _table { 'fnuser' }
For another way to associate a SQL table with a Moose class, see
Fey::ORM.
-Todd
!DSPAM:2337,4a01d3e470671455712449!
That's pretty cool, thanks a lot!
--
Dmitri Ostapenko,
Lead Software Engineer
Farematrix Inc.
www.farematrix.com