ragnaev has asked for the wisdom of the Perl Monks concerning the following question:
So I would like to have in class Parent->children the Collection of child. How to specify that 'children' => isa 'MyCollection[Child]' I try to do so but with no luck. Got and error. Then I try to create a subtype look likeuse MooseX::Declare class MyCollection { has 'items' => ( is => 'rw', isa => 'HashRef[Object]', traits => ['Hash'], defaults => sub { {} } ) some..methods } use MooseX::Declare; class Child { has 'name' => ( is => 'rw', isa => 'Str' ); some..methods } use MooseX::Declare; use MyCollection class Parent { has 'children => ( is => 'rw', isa => 'MyCollection' ) some..methods }
and use insubtype 'MyChildrenCollection' => as 'Collection', where => { $_->isa('Child') }
but again no luck. Please dear PerlMontks give me your advice Thanks in advancehas 'children' => (is => 'rw', 'isa' => 'MyChildrenCollection'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose(X) create my own Collection
by tobyink (Canon) on Jan 19, 2012 at 09:38 UTC |