added exercises for part 5
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 06-advanced-attributes / Person.pm
CommitLineData
66b226e5 1package Person;
2
3use BankAccount;
4use Moose;
5
8883f849 6with 'Printable';
66b226e5 7
8has account => (
9 is => 'rw',
10 isa => 'BankAccount',
11 default => sub { BankAccount->new },
12 handles => [ 'deposit', 'withdraw' ],
13);
14
15has title => (
16 is => 'rw',
17 predicate => 'has_title',
18 clearer => 'clear_title',
19);
20
21has first_name => ( is => 'rw' );
22
23has last_name => ( is => 'rw' );
24
25sub BUILD {
26 my $self = shift;
27
28 $self->account->owner($self);
29}
30
31sub 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
41sub as_string { $_[0]->full_name }
42
66b226e5 43no Moose;
44
45__PACKAGE__->meta->make_immutable;
46
471;