Commit | Line | Data |
---|---|---|
10086130 | 1 | package HasAccount; |
2 | ||
3 | use Moose::Role; | |
4 | ||
8d1ce1d7 | 5 | has balance => ( is => 'rw' ); |
10086130 | 6 | |
7 | sub deposit { | |
8 | my $self = shift; | |
9 | my $amount = shift; | |
10 | ||
11 | $self->balance( $self->balance + $amount ); | |
12 | } | |
13 | ||
14 | sub withdraw { | |
15 | my $self = shift; | |
16 | my $amount = shift; | |
17 | ||
18 | die "Balance cannot be negative" | |
19 | if $self->balance < $amount; | |
20 | ||
21 | $self->balance( $self->balance - $amount ); | |
22 | } | |
23 | ||
24 | no Moose::Role; | |
25 | ||
26 | 1; |