Make tests match the order of the instructions for test 03
[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
39182c07 13has first_name => (
14 is => 'rw',
15 required => 1,
16);
8d1ce1d7 17
39182c07 18has last_name => (
19 is => 'rw',
20 required => 1,
21);
8d1ce1d7 22
1d405ed6 23sub 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 37sub 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
47sub as_string { $_[0]->full_name }
48
49no Moose;
50
51__PACKAGE__->meta->make_immutable;
52
531;