X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F016-trigger.t;h=dc331c70cb918293e406599a5c33bbba5f032f6b;hb=84357c9a1f427aafbc648fd4aa25b1b863823afd;hp=61f79f0db887eddde41cd8b7072c59d890b682b4;hpb=cbdd0fa406d4f9d23a0d6a17891daf995e4c84c5;p=gitmo%2FMouse.git diff --git a/t/016-trigger.t b/t/016-trigger.t index 61f79f0..dc331c7 100644 --- a/t/016-trigger.t +++ b/t/016-trigger.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 21; use Test::Exception; my @trigger; @@ -51,12 +51,11 @@ is(@trigger, 1, "trigger was called on new with the attribute specified"); is_deeply([splice @trigger], [[$object2, 100, $object2->meta->get_attribute('attr')]], "correct arguments to trigger in the constructor"); do { - package Class2; + package Parent; use Mouse; has attr => ( is => 'rw', - default => 10, trigger => { before => sub { push @trigger, ['before', @_]; @@ -74,19 +73,46 @@ do { }, }, ); + + package Child; + use Mouse; + extends 'Parent'; + + has '+attr' => ( + default => 10, + ); }; -my $o2 = Class2->new; +my $child = Child->new; is(@trigger, 0, "trigger not called on constructor with default"); -is($o2->attr, 10, "reader"); +is($child->attr, 10, "reader"); +is(@trigger, 0, "trigger not called on reader"); + +is($child->attr(5), 20, "writer"); +is_deeply([splice @trigger], [ + ['before', $child, 5, Child->meta->get_attribute('attr')], + ['around-before', $child, 5, Child->meta->get_attribute('attr')], + ['around-after', $child, 5, Child->meta->get_attribute('attr')], + ['after', $child, 20, Child->meta->get_attribute('attr')], +]); + +my $parent = Parent->new(attr => 2); +is_deeply([splice @trigger], [ + ['before', $parent, 2, Parent->meta->get_attribute('attr')], + ['around-before', $parent, 2, Parent->meta->get_attribute('attr')], + ['around-after', $parent, 2, Parent->meta->get_attribute('attr')], + ['after', $parent, 8, Parent->meta->get_attribute('attr')], +]); + +is($parent->attr, 8, "reader"); is(@trigger, 0, "trigger not called on reader"); -is($o2->attr(5), 20, "writer"); +is($parent->attr(10), 40, "writer"); is_deeply([splice @trigger], [ - ['before', $o2, 5, $o2->meta->get_attribute('attr')], - ['around-before', $o2, 5, $o2->meta->get_attribute('attr')], - ['around-after', $o2, 5, $o2->meta->get_attribute('attr')], - ['after', $o2, 20, $o2->meta->get_attribute('attr')], + ['before', $parent, 10, Parent->meta->get_attribute('attr')], + ['around-before', $parent, 10, Parent->meta->get_attribute('attr')], + ['around-after', $parent, 10, Parent->meta->get_attribute('attr')], + ['after', $parent, 40, Parent->meta->get_attribute('attr')], ]);