stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

Passing test case: methods closing over lexicals. #87

Closed tobyink closed 11 years ago

tobyink commented 11 years ago

Sorry this isn't a pull request - for some reason my fork isn't playing ball. I may need to wipe it and refork. In the mean time, a passing test case for you...

use strict;
use warnings;
use Test::More;

use mop;

my $x;
BEGIN { $x = 1 };

class Foo {
    method inc { ++$x }
    method dec { --$x }
}

my $foo = Foo->new;

is($x, 1);
is($foo->inc, 2);
is($foo->inc, 3);
is($x, 3);
is($foo->dec, 2);
is($foo->dec, 1);
is($x, 1);

done_testing;