Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Newsgroups | perl.moose |
|---|---|
| Date | 2016-03-15 11:13 -0500 |
| Subject | Re: custom accessor_metaclass override of _inline_store (Moose 1 to 2) |
| Message-ID | <alpine.DEB.2.10.1603151109540.1663@urth.org> (permalink) |
| References | <DDBB5E3F-11B2-4EAA-B3A6-6634A6CF9115@inf.ed.ac.uk> |
| From | autarch@urth.org (Dave Rolsky) |
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)
============================================================*/
Back to perl.moose | Previous | Next — Previous in thread | Next in thread | Find similar
custom accessor_metaclass override of _inline_store (Moose 1 to 2) toby@inf.ed.ac.uk (Toby Blake) - 2016-03-15 16:06 +0000
Re: custom accessor_metaclass override of _inline_store (Moose 1 to 2) autarch@urth.org (Dave Rolsky) - 2016-03-15 11:13 -0500
Re: custom accessor_metaclass override of _inline_store (Moose 1 to 2) toby@inf.ed.ac.uk (Toby Blake) - 2016-03-15 16:22 +0000
Re: custom accessor_metaclass override of _inline_store (Moose 1 to 2) toby@inf.ed.ac.uk (Toby Blake) - 2016-03-22 12:41 +0000
Re: custom accessor_metaclass override of _inline_store (Moose 1 to 2) toby@inf.ed.ac.uk (Toby Blake) - 2016-03-23 11:25 +0000
csiph-web