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