Skip Menu |

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 93891
Status: rejected
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc: rsrchboy [...] cpan.org
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Install trigger coderef as $class::_trigger_${attr_name}
It'd be nice if, similarly to how 'builder => sub{...}' is handled, a coderef passed to 'trigger' would result in installation of the coderef in $class::_trigger_${attr_name}. Thanks, Diab
On Sat Mar 15 15:42:11 2014, DJERIUS wrote: Show quoted text
> It'd be nice if, similarly to how 'builder => sub{...}' is handled, a > coderef passed to 'trigger' would result in installation of the > coderef in $class::_trigger_${attr_name}. > > Thanks, > Diab
trigger is more analogous to default than to builder. Without the shortcut, giving builder a sub is an error. Changing a sub call to a method call is a behavior change, not just a syntax change. It also breaks Moo's ability to inline triggers.
On Tue Apr 01 18:37:43 2014, haarg wrote: Show quoted text
> On Sat Mar 15 15:42:11 2014, DJERIUS wrote:
> > It'd be nice if, similarly to how 'builder => sub{...}' is handled, a > > coderef passed to 'trigger' would result in installation of the > > coderef in $class::_trigger_${attr_name}. > > > > Thanks, > > Diab
> > trigger is more analogous to default than to builder. Without the > shortcut, giving builder a sub is an error.
Ok, upon rereading the documentation and code, I see that the builder routine is ultimately accessed by name, not by coderef; that's a significant difference to how trigger is implemented. Changing trigger to follow that behavior (which would be the only means of ensuring there's no confusion over which code is run) would be detrimental. So, I'll close this; sorry for the noise. Diab
On Wed Apr 02 10:39:42 2014, DJERIUS wrote: Show quoted text
> On Tue Apr 01 18:37:43 2014, haarg wrote:
> > On Sat Mar 15 15:42:11 2014, DJERIUS wrote:
> > > It'd be nice if, similarly to how 'builder => sub{...}' is handled, > > > a > > > coderef passed to 'trigger' would result in installation of the > > > coderef in $class::_trigger_${attr_name}. > > > > > > Thanks, > > > Diab
> > > > trigger is more analogous to default than to builder. Without the > > shortcut, giving builder a sub is an error.
> > Ok, upon rereading the documentation and code, I see that the builder > routine > is ultimately accessed by name, not by coderef; that's a significant > difference > to how trigger is implemented. > > Changing trigger to follow that behavior (which would be the only > means of > ensuring there's no confusion over which code is run) would be > detrimental.
Note that when Moose and MooseX::AttributeShortcuts are used, if an attribute is created with 'trigger => 1' then the coderef 'sub { shift->_trigger_$name(@_) }' is used as a trigger, emulating the syntax of 'builder => 1'. (That is, the attribute will appear to call the correctly named method when the trigger is fired.) However, this neither conflicts nor supplants any existing trigger conventions: it's just a bit of slight-of-hand. This is an informational append only :)