added exercises for part 5
[gitmo/moose-presentations.git] / moose-class / exercises / answers / 05-types / HasAccount.pm
1 package HasAccount;
2
3 use Moose::Role;
4
5 has balance => (
6     is      => 'rw',
7     default => 100,
8 );
9
10 sub deposit {
11     my $self   = shift;
12     my $amount = shift;
13
14     $self->balance( $self->balance + $amount );
15 }
16
17 sub withdraw {
18     my $self   = shift;
19     my $amount = shift;
20
21     die "Balance cannot be negative"
22         if $self->balance < $amount;
23
24     $self->balance( $self->balance - $amount );
25 }
26
27 no Moose::Role;
28
29 1;