On Tue, Nov 10, 2009 at 09:02:53PM -0800, roger bush wrote:
> The following doesn't work. The idea is to add a 'Cached' trait by calling
> the default 'clearer' routine on an attribute. The reason it doesn't work
> is that when it is invoked, there is no clearer routine. The code dies
> with the stack trace saying it doesn't exist on the object (the attribute).
> However the _name_ of the clearer routine is known at this point.
>
> use Moose::Role;
>
> around accessor_metaclass => sub
> {
> my $orig = shift;
> my $self = shift;
>
> my $timer = $self->expire_timer;
> if ($timer->reset_if_expired)
> {
> my $clearer = $self->clearer;
> $self->$clearer ();
> }
>
> return $self->$orig (@_);
> };
You're... not really understanding what this is doing.
accessor_metaclass is a method on the attribute which returns the name
of a metaclass to use to generate the accessors. You need to write a
trait for the accessor metaclass (Moose::Meta::Method::Accessor), and
then modify accessor_metaclass to return the name of a subclass of
Moose::Meta::Method::Accessor that has that trait applied.
-doy