in reply to Re: Moose "unions" and inheritance
in thread Moose "unions" and inheritance
Hello tobyinc.
So, I forgot '+' and used subtypes.
package KeyAtom; use Moose; use Moose::Util::TypeConstraints; subtype 'typeKeyAtom', as 'Str | RegexpRef'; has 'data' => ( is => 'rw', isa => 'typeKeyAtom', ); package ValAtom; use Moose; use Moose::Util::TypeConstraints; extends 'KeyAtom'; subtype 'typeValAtom', as 'typeKeyAtom | ArrayRef | HashRef'; #has 'data' => ( #oh my... has '+data' => ( is => 'rw', #re declare isa => 'typeValAtom', ); no Moose; ###test package main; use Data::Dumper; my $test= ValAtom->new(); for ("test str", qr("^test"), [qw/a b c/], {a=>'b',b=>'c'}, sub{'test' +} ){ $test->data($_); print Dumper $test->data; }
We recommend that you exercise caution when changing the type (isa) of an inherited attribute.
I would like to ask what is "caution" here?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Moose "unions" and inheritance
by tobyink (Canon) on Nov 30, 2012 at 12:24 UTC | |
by remiah (Hermit) on Dec 01, 2012 at 00:22 UTC |
In Section
Seekers of Perl Wisdom