From: Shawn M Moore Date: Wed, 16 Jul 2008 05:45:07 +0000 (+0000) Subject: Some tests for before/after triggers in Mouse X-Git-Tag: 0.19~253 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b5febd3d53867abcaba658628c3302fd9d52261;p=gitmo%2FMouse.git Some tests for before/after triggers in Mouse --- diff --git a/t/016-trigger.t b/t/016-trigger.t index 99bf942..4ba0743 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 => 10; +use Test::More tests => 16; use Test::Exception; my @trigger; @@ -50,3 +50,39 @@ my $object2 = Class->new(attr => 100); 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; + use Mouse; + + has attr => ( + is => 'rw', + default => 10, + trigger => { + before => sub { + push @trigger, ['before', @_]; + }, + after => sub { + push @trigger, ['after', @_]; + }, + around => sub { + my $code = shift; + push @trigger, ['around-before', @_]; + $code->(); + push @trigger, ['around-after', @_]; + }, + }, + ); +}; + +my $o2 = Class2->new; +is(@trigger, 0, "trigger not called on constructor with default"); + +is($o2->attr, 10, "reader"); +is(@trigger, 0, "trigger not called on reader"); + +is($o2->attr(5), 5, "writer"); +is_deeply([splice @trigger], [ + ['before', $o2, 5, $o2->meta->get_attribute('attr')], + ['after', $o2, 5, $o2->meta->get_attribute('attr')], +]); +