6 Moose::Cookbook::Recipe2
15 has 'balance' => (isa => 'Int', is => 'rw', default => 0);
18 my ($self, $amount) = @_;
19 $self->balance($self->balance + $amount);
23 my ($self, $amount) = @_;
24 my $current_balance = $self->balance();
25 ($current_balance >= $amount)
26 || confess "Account overdrawn";
27 $self->balance($current_balance - $amount);
30 package CheckingAccount;
35 extends 'BankAccount';
37 has 'overdraft_account' => (isa => 'BankAccount', is => 'rw');
39 before 'withdraw' => sub {
40 my ($self, $amount) = @_;
41 my $overdraft_amount = $amount - $self->balance();
42 if ($overdraft_amount > 0) {
43 $self->overdraft_account->withdraw($overdraft_amount);
44 $self->deposit($overdraft_amount);
52 Stevan Little E<lt>stevan@iinteractive.comE<gt>
54 =head1 COPYRIGHT AND LICENSE
56 Copyright 2006 by Infinity Interactive, Inc.
58 L<http://www.iinteractive.com>
60 This library is free software; you can redistribute it and/or modify
61 it under the same terms as Perl itself.