carried BUILDARGS in Person.pm from exercise 1 forward through the later answer class...
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 02-roles / Person.pm
1 package Person;
2
3 use Moose;
4
5 with 'Printable', 'HasAccount';
6
7 has first_name => ( is => 'rw' );
8 has last_name  => ( is => 'rw' );
9
10 sub BUILDARGS {
11     my $class = shift;
12
13     if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) {
14         return {
15             first_name => $_[0]->[0],
16             last_name  => $_[0]->[1],
17         };
18     }
19     else {
20         return $class->SUPER::BUILDARGS(@_);
21     }
22 }
23
24 sub full_name {
25     my $self = shift;
26
27     return join q{ }, $self->first_name, $self->last_name;
28 }
29
30 sub as_string { $_[0]->full_name }
31
32 no Moose;
33
34 __PACKAGE__->meta->make_immutable;
35
36 1;