X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-weaken.t;h=245ea7a83227d118f330a341992153ac2448dfb3;hb=85de1ef9dedd1a60115e475036dabaed68dc6ae2;hp=ec5b0691902299938c0435e58f4d681723c26ed8;hpb=6998abed26a68b7adc6254bb6e1900623b2ac903;p=gitmo%2FMoo.git diff --git a/t/accessor-weaken.t b/t/accessor-weaken.t index ec5b069..245ea7a 100644 --- a/t/accessor-weaken.t +++ b/t/accessor-weaken.t @@ -1,18 +1,24 @@ use strictures 1; use Test::More; +use Moo::_Utils; + +ok(Moo::_Utils::lt_5_8_3, "pretending to be pre-5.8.3") + if $ENV{MOO_TEST_PRE_583}; { package Foo; use Moo; - has one => (is => 'ro', weak_ref => 1); + has one => (is => 'rw', weak_ref => 1); package Foo2; use Moo; - has one => (is => 'lazy', weak_ref => 1, default => sub { {} }); + our $preexist = {}; + has one => (is => 'rw', lazy => 1, weak_ref => 1, default => sub { $preexist }); + has two => (is => 'rw', lazy => 1, weak_ref => 1, default => sub { {} }); } my $ref = {}; @@ -23,11 +29,21 @@ undef $ref; ok(!defined $foo->{one}, 'weak value gone'); my $foo2 = Foo2->new; -ok(my $ref2 = $foo2->one, 'value returned'); +ok(my $ref2 = $foo2->one, 'external value returned'); +is($foo2->one, $ref2, 'value maintained'); ok(Scalar::Util::isweak($foo2->{one}), 'value weakened'); +is($foo2->one($ref2), $ref2, 'value returned from setter'); undef $ref2; ok(!defined $foo->{one}, 'weak value gone'); +is($foo2->two, undef, 'weak+lazy ref not returned'); +is($foo2->{two}, undef, 'internal value not set'); +my $ref3 = {}; +is($foo2->two($ref3), $ref3, 'value returned from setter'); +undef $ref3; +ok(!defined $foo->{two}, 'weak value gone'); + + # test readonly SVs sub mk_ref { \ 'yay' }; my $foo_ro = eval { Foo->new(one => mk_ref()) };