in reply to Proxying (almost) all methods in a class for mass memoization
This:
return $outputs->{ $call_key } if defined $outputs->{ $call_key +}; $outputs->{ $call_key } = $self->$orig( @args ); return $outputs->{ $call_key };
Would be more concise like this:
return( $outputs->{$call_key} //= $self->$orig(@args) );
As it's the last line in the sub, you don't even need the return keyword. (And sub calls are slightly optimized if you leave it out.)
One thing to beware: get_method_list doesn't return a list of all methods — it doesn't include inherited methods. You could use get_all_methods (which retuns Moose::Meta::Method objects instead of a list of method names as strings, so you will need to do $_->name on each).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Proxying (almost) all methods in a class for mass memoization
by hippo (Archbishop) on Aug 16, 2018 at 08:06 UTC | |
by choroba (Cardinal) on Aug 16, 2018 at 10:01 UTC | |
by davido (Cardinal) on Aug 16, 2018 at 20:24 UTC | |
by tobyink (Canon) on Aug 16, 2018 at 11:44 UTC | |
|
Re^2: Proxying (almost) all methods in a class for mass memoization
by Anonymous Monk on Aug 16, 2018 at 10:59 UTC |