projects
/
gitmo/moose-presentations.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
blame
|
history
|
raw
|
HEAD
Add exercises for section 2
[gitmo/moose-presentations.git]
/
moose-class
/
exercises
/
answers
/
02-roles
/
HasAccount.pm
1
package HasAccount;
2
3
use Moose::Role;
4
5
has balance => (
6
is => 'rw',
7
);
8
9
sub deposit {
10
my $self = shift;
11
my $amount = shift;
12
13
$self->balance( $self->balance + $amount );
14
}
15
16
sub withdraw {
17
my $self = shift;
18
my $amount = shift;
19
20
die "Balance cannot be negative"
21
if $self->balance < $amount;
22
23
$self->balance( $self->balance - $amount );
24
}
25
26
no Moose::Role;
27
28
1;