in reply to Idea: Moose Mutual Coercion
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}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Idea: Moose Mutal Coercion
by duelafn (Parson) on Feb 14, 2012 at 15:04 UTC |