Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass a regex to isa() with Moose-based objects?

Tags:

perl

moose

Can I use isa in Moose with a regex as a parameter ? If not possible can I achieve the same thing with someothing other than ->isa ?

ok, having the following types Animal::Giraffe , Animal::Carnivore::Crocodile , I want to do ->isa(/^Animal::/), can I do that ? if I can't, what can I use to reach the desired effect ?

like image 897
xxxxxxx Avatar asked Dec 06 '22 03:12

xxxxxxx


1 Answers

These related types should all "do" the same role, Animal. Then you can write:

has 'animal' => (
    is       => 'ro',
    does     => 'Animal',
    required => 1,
);

Now you have something much more reliable than a regex to ensure the consistency of your program.

like image 159
jrockway Avatar answered Dec 17 '22 09:12

jrockway