- Make init_meta() examples explicitly return the metaclass and point out
this fact. (hdp)
+ * Moose::Meta::Class
+ * Moose::Meta::Method::Constructor
+ - Attribute triggers now consistently do not receive the meta-attribute
+ object as an argument. 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)
+
+ * Moose::Manual::Attributes
+ - Remove references to triggers receving the meta-attribute object as an
+ argument. (hdp)
0.73 Fri, March 29, 2009
* No changes from 0.72_01.
);
sub _size_set {
- my ( $self, $size, $meta_attr ) = @_;
+ my ( $self, $size ) = @_;
warn $self->name, " size is now $size\n";
}
-The trigger is called as a method, and receives the new value as well
-as the L<Moose::Meta::Attribute> object for the attribute. The trigger
-is called I<after> the value is set.
+The trigger is called as a method, and receives the new value as its argument.
+The trigger is called I<after> the value is set.
This differs from an after method modifier in two ways. First, a
trigger is only called when the attribute is set, as opposed to
? $attr->get_read_method_ref->($self)
: $params->{$init_arg}
),
- $attr
);
}
$attr->name,
)
. ', '
- . '$attrs->['
- . $i . ']' . ');' . "\n}";
+ . ');' . "\n}";
}
return join ";\n" => @trigger_calls;
use Scalar::Util 'isweak';
-use Test::More tests => 36;
+use Test::More tests => 40;
use Test::Exception;
is_deeply(\%Blarg::trigger_vals, { map { $_ => "Yet another $_ value" } qw/foo bar baz/ }, 'All triggers given assigned values');
}
+# Triggers receive the meta-attribute as an argument
+
+{
+ package Foo;
+ use Moose;
+ our @calls;
+ has foo => (is => 'rw', trigger => sub { push @calls, [@_] });
+}
+
+{
+ my $attr = Foo->meta->get_attribute('foo');
+ my $foo = Foo->new(foo => 2);
+ is_deeply(
+ \@Foo::calls,
+ [ [ $foo, 2 ] ],
+ 'trigger called correctly on construction',
+ );
+ @Foo::calls = ();
+
+ $foo->foo(3);
+ is_deeply(
+ \@Foo::calls,
+ [ [ $foo, 3 ] ],
+ 'trigger called correctly on set',
+ );
+ @Foo::calls = ();
+ Foo->meta->make_immutable, redo if Foo->meta->is_mutable;
+}
+
+