in reply to Using AUTOLOAD with Moo

I think handles is the clearest and most flexible way to let method calls go through. I use it often when wrapping up objects into an ad hoc API.

use 5.14.0; use strictures; package SomeMangagedObject { use Moo; sub exterminate { 1 } sub Exterminate { 10 } sub EXTERMINATE { 100 } 1; }; package MyWrApper { use Moo; use Scalar::Util "blessed"; use Carp; has "robot" => is => "ro", required => 1, handles => [qw/ exterminate Exterminate EXTERMINATE /], default => sub { SomeMangagedObject->new }, isa => sub { "SomeMangagedObject" eq blessed $_[0] or confess "Nope" }; 1; }; my $wrap = MyWrApper->new; say $wrap->robot; say $wrap->exterminate;

Replies are listed 'Best First'.
Re^2: Using AUTOLOAD with Moo
by tobyink (Canon) on Jan 15, 2019 at 15:47 UTC

    That works if you know in advance what methods you need to be handled.

      I'm a whitelist kinda monk. :P And excepting prototyping or personal/non-production stuff I see $AUTOLOAD as false economy.