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 | |
by Your Mother (Archbishop) on Jan 15, 2019 at 18:02 UTC |