package FunkyNum;
use strict;
use Class::Contract;
contract {
attr 'val';
ctor 'new';
impl { ${self->val} = $_[0] || 0; }; #arn't I tricky
method 'plusequal';
pre { defined $_[0] };
impl {
${self->val} += $_[0];
};
method 'printval';
impl {
return ${self->val};
}
};
####
use strict;
use FunkyNum;
my $x = new FunkyNum 2;
$x->plusequal(2);
print "num is " . $x->printval . "\n";
$x->plusequal(("woah", "there", "fella"));
print "num is " . $x->printval . "\n";
$x->nomethod;
##
##
pre { ref $_[0] && $_[0]->isa("FunkyNum") };