HTML validation fixes
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 06-advanced-attributes / Person.pm
CommitLineData
66b226e5 1package Person;
2
3use BankAccount;
4use Moose;
5
6with 'Printable', 'OutputsXML';
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
43sub as_xml {
44 my $self = shift;
45
46 return
47 ( map { "<$_>" . ( $self->$_ || q{} ) . "</$_>" } qw( first_name last_name title ) ),
48 inner();
49}
50
51no Moose;
52
53__PACKAGE__->meta->make_immutable;
54
551;