Manipulate TB level in helper subs
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 03-basic-attributes / Person.pm
CommitLineData
8d1ce1d7 1package Person;
2
3use Moose;
4
5with 'Printable', 'HasAccount';
6
7has title => (
8 is => 'rw',
9 predicate => 'has_title',
10 clearer => 'clear_title',
11);
12
13has first_name => ( is => 'rw' );
14
15has last_name => ( is => 'rw' );
16
1d405ed6 17sub BUILDARGS {
18 my $class = shift;
19
20 if ( @_ == 1 && 'ARRAY' eq ref $_[0] ) {
21 return {
22 first_name => $_[0]->[0],
23 last_name => $_[0]->[1],
24 };
25 }
26 else {
27 return $class->SUPER::BUILDARGS(@_);
28 }
29}
30
8d1ce1d7 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
43no Moose;
44
45__PACKAGE__->meta->make_immutable;
46
471;