{ package Grid;; use Moose; use Moose::Util::TypeConstraints; # coerce an 'ArrayRef[ArrayRef[Cell]]' struct provided by the caller into an 'ArrayRef[Row]' type subtype 'A::Row' => as 'ArrayRef[Row]'; coerce 'A::Row' => from 'ArrayRef[ArrayRef[Cell]]' => via { [ map {Row->new( row => $_ )} @$_ ] }; # coerce an 'ArrayRef[Cell]' struct provided by the caller into a 'Row' type coerce 'Row' => from 'ArrayRef[Cell]' => via { Row->new( row => $_ ) }; has 'grid' => ( traits => ['Array'], is => 'ro', isa => 'A::Row', required => 1, default => sub { [] }, coerce => 1, handles => { addRow => 'push', getRow => 'get', allRows => 'elements', }, ); }