nysus has asked for the wisdom of the Perl Monks concerning the following question:
I'm pretty sure I've made a bad design decision but not sure what else I can do with Moo. I want a attribute to handle methods if they don't exist:
package Mac::ApperlScript::App::Finder::Window ; use Moo; use Mac::AppleScript::Glue::Object; use namespace::autoclean; our $AUTOLOAD; has 'obj' => (is => 'ro', required => 1, isa => sub { die 'Improper object passed' unless ref $_[0] eq 'Mac::AppleScript::Glue::Object' }, writer => '_set_obj', ); sub AUTOLOAD { my $s = shift; my @al = split /::/, $AUTOLOAD; my $method = $al[-1]; return $s->obj->$method; }
So I delegate all methods that don't exist to the obj attribute. The problem is that methods like DESTROY seem to get diverted to the AUTOLOAD subroutine. Is there a better way to achieve what I want to do?
$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using AUTOLOAD with Moo
by kroach (Pilgrim) on Jan 15, 2019 at 02:13 UTC | |
|
Re: Using AUTOLOAD with Moo
by kcott (Archbishop) on Jan 15, 2019 at 06:38 UTC | |
|
Re: Using AUTOLOAD with Moo
by Your Mother (Archbishop) on Jan 15, 2019 at 14:54 UTC | |
by tobyink (Canon) on Jan 15, 2019 at 15:47 UTC | |
by Your Mother (Archbishop) on Jan 15, 2019 at 18:02 UTC | |
|
Re: Using AUTOLOAD with Moo
by Anonymous Monk on Jan 15, 2019 at 09:31 UTC |