From: Shawn M Moore Date: Thu, 17 Jul 2008 08:38:51 +0000 (+0000) Subject: Saved by the peri grin! (trigger doc) X-Git-Tag: 0.19~235 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2a1372ddb2076d74977a4563e6d052bd894ad52;p=gitmo%2FMouse.git Saved by the peri grin! (trigger doc) --- diff --git a/Changes b/Changes index f8fbaf9..d83d60b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for Mouse 0.06 + * Mouse + - updated trigger doc (thanks perigrin) 0.05 Thu Jul 17 01:53:20 2008 * Mouse::Role diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 99fab48..92ee9af 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -342,18 +342,18 @@ Lets you automatically weaken any reference stored in the attribute. =item trigger => CodeRef | HashRef -Triggers are like method modifiers for setting attribute values. You can have -a "before" and an "after" trigger, each of which receive as arguments the instance, the new value, and the attribute metaclass. Historically, triggers have -only been "after" modifiers, so if you use a coderef for the C option, -it will maintain that compatibility. Like method modifiers, you can't really -affect the act of setting the attribute value, and the return values of the -modifiers are ignored. - -There's also an "around" trigger which you can use to change the value that -is being set on the attribute, or even prevent the attribute from being -updated. The around trigger receives as arguments a code reference to invoke -to set the attribute's value (which expects as arguments the instance and -the new value), the instance, the new value, and the attribute metaclass. +Historically, triggers have been like "after" method modifiers. They allowed +you to run code after your attribute had been set. Passing a coderef to the +C option still works this way. + +By passing a hashref to C, you also get "before" and "around" +triggers. The "before" and "after" triggers don't affect the act of setting +the attribute value, and their return values are ignored. The "around" trigger +can be used to change the value that is being set on the attribute, or prevent +the attribute from being updated altogether. The "around" trigger's arguments +are a code reference to set the attribute's value (this coderef expects the +instance and the new value), the instance, the new value, and the attribute +metaclass. =item builder => Str