projects
/
gitmo/moose-presentations.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
76ea15e6021d3fdd7f2442be8d8306530f3e26b7
[gitmo/moose-presentations.git]
/
moose-class
/
exercises
/
answers
/
04-method-modifiers
/
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;