On Tue, 15 Mar 2016, Toby Blake wrote:
I'm trying to convert an existing project to Moose 2 (from Moose 1.15).
I've run into a tricky issue where the original author of the project (not
me!) has overridden part of Moose's private API - this part has now
changed. I'll try and explain the situation briefly, in the hope that
somebody can advise:
We have an attribute trait which uses a custom accessor_metaclass.
This accessor metaclass extends 'Moose::Meta::Method::Accessor' and
overrides _inline_store, like this:
override _inline_store => sub {
my ($self, $instance, $value) = @_;
my $attr = $self->associated_attribute;
if ($attr->has_logger) {
return sprintf('$attr->logger->($attr, %s, %s);', $instance, $value) .
super;
}
return super;
};
So, essentially, it puts a call to the attribute trait's $attr->logger
subroutine in the chain when setting a value (this is needed because we
have code here which needs to know when an object's attribute values have
changed - this is the function of the "logger"). And of course this code
doesn't work with Moose 2, as there is no longer an _inline_store method in
Moose::Meta::Method::Accessor.
The lesson here is that we shouldn't be using parts of the private api, as
they may change. However, I would like to get this working without
rewriting large chunks of it. I naively tried changing _inline_store to
_inline_store_value for Moose 2, but this doesn't appear to be called in
the same way.
I think you can override Moose::Meta::Attribute->_inline_instance_set.
This will work for any attribute that doesn't have an initializer (but no
one uses that Moose feature).
Cheers,
-dave
/*============================================================
http://VegGuide.org http://blog.urth.org
Your guide to all that's veg House Absolute(ly Pointless)
============================================================*/