Subject: | trigger is not compatible at all with (very old) Moose >= 0.73_01 |
Hi there!
the "trigger" behavior changed a lot in Moose.
In 0.73_01 we had:
-------8<-------
- Attribute triggers no longer receive the meta-attribute object as an
argument in any circumstance. Previously, triggers called during
instance construction were passed the meta-attribute, but triggers
called by normal accessors were not. Fixes RT#44429, reported by Mark
Swayne. (hdp)
------->8-------
Then, in 0.89:
-------8<-------
- A trigger now receives the old value as a second argument, if the
attribute had one. (Dave Rolsky)
------->8-------
I don't think neither is implemented in Mouse at the moment. Mouse docs say:
-------8<-------
trigger => CodeRef
Any time the attribute's value is set (either through the accessor
or the constructor), the trigger is called on it. The trigger receives
as arguments the instance, the new value, and the attribute instance.
------->8-------
Since, according to Mouse::Spec, anything that has the same name as
Moose is expected to be compatible, I'm think this is either a bug or
something that need to be marked on the docs.
To reproduce the problem is easy:
-------8<-------
package Foo;
use Mouse;
use Data::Dumper;
has 'bar' => ( trigger => \&_foo );
sub _foo { warn Dumper(@_) }
package main;
my $foo = Foo->new( bar => 1 );
$foo->bar( 2 );
------->8-------
If you s/Mouse/Moose/ in the code above, you'll see 2 arguments printed
by Data::Dumper on the first run, and 3 on the second run. With Mouse,
it's always 2 arguments - which doesn't even comply with its own docs.
I really enjoy Mouse and hope you guys can make it more awesome at every
run. Hope this report helps to achieve that :)
Thanks!