From: Karen Etheridge Date: Tue, 31 May 2011 23:42:18 +0000 (+0000) Subject: new tests for initializers and triggers on rebless_instance X-Git-Tag: 2.0009~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=719d666911736b26c0aa20b11dc1c92d52fe3cfd;hp=01f07d050a71aa3c08e54e26e087d0cc847f2846;p=gitmo%2FMoose.git new tests for initializers and triggers on rebless_instance initializers work, as this comes from CMOP, but Moose::Meta::Class needs an override - so this test is marked TODO for now. --- diff --git a/t/basics/rebless.t b/t/basics/rebless.t index 17808d2..18a2812 100644 --- a/t/basics/rebless.t +++ b/t/basics/rebless.t @@ -51,6 +51,21 @@ subtype 'Positive' isa => 'Int', default => 100, ); + + our %trigger_calls; + our %initializer_calls; + + has new_attr => ( + is => 'rw', isa => 'Str', + trigger => sub { + my ($self, $val, $attr) = @_; + $trigger_calls{new_attr}++; + }, + initializer => sub { + my ($self, $value, $set, $attr) = @_; + $initializer_calls{new_attr}++; + }, + ); } my @classes = qw(Parent Child); @@ -73,7 +88,7 @@ with_immutable $bar->type_constrained(5); Child->meta->rebless_instance($foo); - Child->meta->rebless_instance($bar); + Child->meta->rebless_instance($bar, new_attr => 'blah'); is(blessed($foo), 'Child', 'successfully reblessed into Child'); is($foo->name, 'Junior', "Child->name's default came through"); @@ -83,6 +98,16 @@ with_immutable like( exception { $foo->type_constrained(10.5) }, qr/^Attribute \(type_constrained\) does not pass the type constraint because\: Validation failed for 'Int' with value 10\.5/, '... this failed because of type check' ); + + TODO: { + local $TODO = 'Moose::Meta::Class does not yet call triggers for rebless_instance!'; + is_deeply(\%Child::trigger_calls, { new_attr => 1 }, 'Trigger fired on rebless_instance'); + } + is_deeply(\%Child::initializer_calls, { new_attr => 1 }, 'Initializer fired on rebless_instance'); + + undef %Child::trigger_calls; + undef %Child::initializer_calls; + } @classes;