Commit | Line | Data |
66b226e5 |
1 | package Person; |
2 | |
3 | use BankAccount; |
4 | use Moose; |
5 | |
8883f849 |
6 | with 'Printable'; |
66b226e5 |
7 | |
8 | has account => ( |
9 | is => 'rw', |
10 | isa => 'BankAccount', |
11 | default => sub { BankAccount->new }, |
12 | handles => [ 'deposit', 'withdraw' ], |
13 | ); |
14 | |
15 | has title => ( |
16 | is => 'rw', |
17 | predicate => 'has_title', |
18 | clearer => 'clear_title', |
19 | ); |
20 | |
21 | has first_name => ( is => 'rw' ); |
22 | |
23 | has last_name => ( is => 'rw' ); |
24 | |
25 | sub BUILD { |
26 | my $self = shift; |
27 | |
28 | $self->account->owner($self); |
29 | } |
30 | |
31 | sub full_name { |
32 | my $self = shift; |
33 | |
34 | my $title = join q{ }, $self->first_name, $self->last_name; |
35 | $title .= q[ (] . $self->title . q[)] |
36 | if $self->has_title; |
37 | |
38 | return $title; |
39 | } |
40 | |
41 | sub as_string { $_[0]->full_name } |
42 | |
66b226e5 |
43 | no Moose; |
44 | |
45 | __PACKAGE__->meta->make_immutable; |
46 | |
47 | 1; |