exercises for section 6
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 06-advanced-attributes / Employee.pm
1 package Employee;
2
3 use Moose;
4
5 extends 'Person';
6
7 has '+title' => (
8     default => 'Worker',
9 );
10
11 has salary_level => (
12     is      => 'rw',
13     default => 1,
14 );
15
16 has salary => (
17     is       => 'ro',
18     lazy     => 1,
19     builder  => '_build_salary',
20     init_arg => undef,
21 );
22
23 has ssn    => ( is => 'ro' );
24
25 sub _build_salary {
26     my $self = shift;
27
28     return $self->salary_level * 10000;
29 }
30
31 augment as_xml => sub {
32     my $self = shift;
33
34     return
35         ( map { "<$_>" . ( $self->$_ || q{} ) . "</$_>" } qw( salary salary_level ssn ) ),
36         inner();
37 };
38
39 no Moose;
40
41 __PACKAGE__->meta->make_immutable;
42
43 1;