develooper Front page | perl.moose | Postings from March 2016

custom accessor_metaclass override of _inline_store (Moose 1 to 2)

Thread Next
From:
Toby Blake
Date:
March 15, 2016 16:07
Subject:
custom accessor_metaclass override of _inline_store (Moose 1 to 2)
Message ID:
DDBB5E3F-11B2-4EAA-B3A6-6634A6CF9115@inf.ed.ac.uk
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 => 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'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


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About