From: Toby Inkster Date: Fri, 19 Apr 2013 12:49:16 +0000 (+0100) Subject: add checks that refaddr of $spec->{isa} and $spec->{coerce} are unchanged X-Git-Tag: v1.002000~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f07812d7a6146b73c3bb772b2b9ab799e1c26ef;p=gitmo%2FMoo.git add checks that refaddr of $spec->{isa} and $spec->{coerce} are unchanged --- diff --git a/t/overloaded-coderefs.t b/t/overloaded-coderefs.t index 66bdc0b..0c195c9 100644 --- a/t/overloaded-coderefs.t +++ b/t/overloaded-coderefs.t @@ -35,11 +35,12 @@ is($darkside->(6), 12, 'check Dark::Side coderef'); my $theforce = The::Force->new('my $dummy = "use the force Luke"; $_[0] * 2'); is($theforce->(6), 12, 'check The::Force coderef'); +my $luke = The::Force->new('my $z = "I am your father"'); { package Doubleena; use Moo; has a => (is => "rw", coerce => $darkside, isa => sub { 1 }); - has b => (is => "rw", coerce => $theforce, isa => The::Force->new('my $z = "I am your father"')); + has b => (is => "rw", coerce => $theforce, isa => $luke); } my $o = Doubleena->new(a => 11, b => 12); @@ -56,4 +57,20 @@ like($constructor, qr{use the force Luke}, 'Sub::Quoted coercion got inlined'); unlike($constructor, qr{join the dark side}, 'non-Sub::Quoted coercion was not inlined'); like($constructor, qr{I am your father}, 'Sub::Quoted isa got inlined'); +require Scalar::Util; +is( + Scalar::Util::refaddr($luke), + Scalar::Util::refaddr( + Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"isa"} + ), + '$spec->{isa} reference is not mutated', +); +is( + Scalar::Util::refaddr($theforce), + Scalar::Util::refaddr( + Moo->_constructor_maker_for("Doubleena")->all_attribute_specs->{"b"}{"coerce"} + ), + '$spec->{coerce} reference is not mutated', +); + done_testing;