Commit | Line | Data |
8d1ce1d7 |
1 | package Person; |
2 | |
3 | use Moose; |
4 | |
5 | with 'Printable', 'HasAccount'; |
6 | |
7 | has title => ( |
8 | is => 'rw', |
9 | predicate => 'has_title', |
10 | clearer => 'clear_title', |
11 | ); |
12 | |
39182c07 |
13 | has first_name => ( |
14 | is => 'rw', |
15 | required => 1, |
16 | ); |
8d1ce1d7 |
17 | |
39182c07 |
18 | has last_name => ( |
19 | is => 'rw', |
20 | required => 1, |
21 | ); |
8d1ce1d7 |
22 | |
1d405ed6 |
23 | sub BUILDARGS { |
24 | my $class = shift; |
25 | |
26 | if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) { |
27 | return { |
28 | first_name => $_[0]->[0], |
29 | last_name => $_[0]->[1], |
30 | }; |
31 | } |
32 | else { |
33 | return $class->SUPER::BUILDARGS(@_); |
34 | } |
35 | } |
36 | |
8d1ce1d7 |
37 | sub full_name { |
38 | my $self = shift; |
39 | |
40 | my $title = join q{ }, $self->first_name, $self->last_name; |
41 | $title .= q[ (] . $self->title . q[)] |
42 | if $self->has_title; |
43 | |
44 | return $title; |
45 | } |
46 | |
47 | sub as_string { $_[0]->full_name } |
48 | |
49 | no Moose; |
50 | |
51 | __PACKAGE__->meta->make_immutable; |
52 | |
53 | 1; |