custom accessor_metaclass override of _inline_store (Moose 1 to 2)
[email protected] (Toby Blake) Tue, 15 Mar 2016 16:06:55 +0000
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Hello,
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 =3D> sub {
my ($self, $instance, $value) =3D @_;
my $attr =3D $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'd be grateful for any advice on how I can get this code working again,
without substantial changes.
Thanks
Toby Blake
School of Informatics
University of Edinburgh
--=20
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.