On Fri, Mar 19, 2010 at 2:22 PM, Sir Robert Burbridge
<rburb...@cisco.com> wrote:
> Hey all,
>
> I've read through the Moose::Manual::Types, Moose::Util::TypeConstraints,
> and other things I could find.  I don't quite see how I am supposed to
> create a property that holds "a derivative of class X".  For example, I
> would like to do:
>
>   package A;
>   use Moose;
>   1;
>
>   package B;
>   use Moose;
>   extends A;
>   1;
>
>   package C;
>   use Moose;
>   has a => (isa=>'A', is=>'rw');
>   1;
>
>   ### Create "B" which extends "A"
>   my $b = B->new();
>
>   ### Create C with property "a" of value $b.  $b is an "A" derivative,
>   ### so I'd like it to be ok with that.
>   my $c = C->new(a=>$b);
>
> Any help would be appreciated.
>
> -Sir


Did you try your example?

use 5.10.0;

package A;
use Moose;

package B;
use Moose;
extends qw(A);

package C;
use Moose;
has attr => ( isa => 'A', is => 'ro' );

package main;

my $o = C->new( attr => B->new );

say $o->dump;

__END__

$VAR1 = bless( {
                 'attr' => bless( {}, 'B' )
               }, 'C' );

Reply via email to