Let's say I define an abstract implementation of My :: Object and the specific role My :: Object :: TypeA and My :: Object :: TypeB. For reasons of ease of maintenance, I would not want to have a hard-coded table that looks at the type of object and applies roles. As a DWIMmy example, I am looking for something in these lines in My :: Object:
has => 'id' (isa => 'Str', required => 1); sub BUILD { my $self = shift; my $type = $self->lookup_type();
Let me get an object My :: Object with My :: Object :: TypeB by doing the following:
my $obj = My::Object(id = 'foo')
Will it do what I want, or am I on a completely wrong path?
Edit: I have simplified this too much; I do not want to know the type when I instantiate the object, I want the object to determine its type and apply the correct role methods accordingly. I edited my question to make this clearer.
perl moose roles
Oesor
source share