Contracts in Perl 'Class::Agreement' #30

Example 3

dependent increase_foo => sub {
    my ( $self, $amount ) = @_;
    my $old_foo = $self->get_foo;
    return sub {
      my ( $self, $amount ) = @_;
      return ( $old_foo 
            < $self->get_foo );
    }
};
sub increase_foo {
    my ( $self, $amount ) = @_;
    $self->set_foo( $self->get_foo 
        + $amount );
}
Copyright © 2005 Ian Langworth