Extending perigrin's answer so that it works if the class has Animal::* anywhere in its superclasses, and not just in its closest class name (for example, if Helper::Monkey isa Animal::Monkey ):
use Moose; use Moose::Util::TypeConstraints; subtype Animal => as Object => where { grep /^Animal::/, $_->meta->linearized_isa }; has animal => ( is => 'rw', isa => 'Animal' );
I think the jrockway proposal to use the role instead has many advantages, but if you want to go that route, you can also cover all the bases.
source share