3 use List::Util qw( sum );
10 trigger => sub { $_[0]->_record_difference( $_[1] ) },
21 isa => 'ArrayRef[Int]',
22 default => sub { [] },
28 $self->_record_difference( $self->balance );
35 $self->balance( $self->balance + $amount );
42 die "Balance cannot be negative"
43 if $self->balance < $amount;
45 $self->balance( $self->balance - $amount );
48 sub _record_difference {
50 my $new_value = shift;
52 my $old_value = sum @{ $self->history };
54 push @{ $self->history }, $new_value - ( $old_value || 0 );
59 __PACKAGE__->meta->make_immutable;