Type coercions
package Person;
has $_ for qw/firstname lastname/;
package Project;
use Moose;
use Moose::Util::TypeConstraints;
coerce 'Person',
from 'Str',
via {
my ($f, $l) = split /\s/, $_;
Person->new( firstname => $f, lastname => $l )
};
has 'manager' => (
isa => 'Person',
coerce => 1,
);
Project->new( manager => 'Jonathan Rockway' ); # fails without coerce => 1
Project->new( manager => Person->new( ... ) ); # always OK