Personally, I don't think we need to pass that meta-attribute, if you
really want/need it, then you can do this:
trigger => sub {
my $self = shift;
$self->meta->find_attribute_by_name('foo')->...
...
}
The only tricky part of the above workaround is that you need to know
the name of the attribute in order to get the meta-attribute. But this
shouldn't be too hard to fix/work-around in most cases.
My vote is for *not* passing the meta-attribute and document the above
work around in Moose::Manual::Delta.
- Stevan
On Mar 29, 2009, at 12:32 AM, Hans Dieter Pearcey wrote:
In December, mst committed ec2e2ee5a0f010fe09d57e0176717b6b4f5671a2,
which
removes the meta-attr object as the third argument to triggers, saying
unsupport passing meta-attr object to triggers because (a) it's
not tested
(b) it's not documented (c) it makes it impossible to not close
over the
meta-attr objects
As far as I can tell, though, it *was* documented and had been for a
long time.
(Also, that commit only removed this behavior from inlined accessors
and
constructors, so anyone not using make_immutable still got the meta-
attr object
passed to their triggers if the constructor invoked them.)
A month later, nothingmuch merged in a big branch that reinstated
the passing
of the meta-attr object to triggers in inline constructors, but I
couldn't find
any comment about why this was done.
(59f5bbde66d61d15b684be88d138fd798ba851d0)
Today, http://rt.cpan.org/Public/Bug/Display.html?id=44429
summarizes the
problem: writers (inline or not) invoking a trigger don't pass in the
meta-attr. Moose::Manual::Attributes document that they do and Moose
document
that they don't. There aren't tests one way or another.
We need to pick one and stick to it. I don't want another fix (in
whichever
direction) that someone else undoes a month later.
If it's "change the code to match the docs", that's done in
http://github.com/hdp/moose/commit/b0871377ee1fb633784cf69cd4d096a0c3183493
If it's "change the docs to match the code", that's easy; remove the
mention of
the meta-attribute object from Moose::Manual::Attributes.
I don't know how to weigh these two concerns, though:
* It has been documented and working for as long as I can remember
that
triggers receive the meta-attr object.
* Passing the meta-attr object to triggers rules out some theoretical
performance improvements.
(When I say it like it that, it sounds like we should change the
code to match
the docs, but optimizing Moose performance is something I have no
experience
with.)
hdp.