in reply to
Idea: Moose Mutual Coercion
It seems like you're making your life harder than you have to. You would be much better off picking one standard data representation and supplying multiple initialization functions, e.g.:
package Identity;
sub init_first_last
{
my ($c, $first, $last) = @_;
die unless $first =~ /^\S+$/ && $last =~ /^\S+$/;
bless { first => $first, last => $last }, $c;
}
sub init_fullname
{
my $c = shift;
my ($first, $last) = split ' ', shift;
init_first_last $c, $first, $last;
}
sub fullname
{
join ' ', @{$_[0]}{qw(first last)};
}
sub first
{
shift->{first};
}
sub last
{
shift->{last};
}