http://qs321.pair.com?node_id=1207142

nysus has asked for the wisdom of the Perl Monks concerning the following question:

I have this code, which works, that allows me to access some custom methods in a role I created. For example:

{ package Server; use Carp; use Moose; use Net::OpenSSH; use Config::Simple; with 'MyOpenSSH'; has 'ssh' => (is => 'ro', isa => 'Net::OpenSSH', required => 1, hand +les => qr/.*/, ); } { package MyOpenSSH; use Moose::Role; sub grab { my $self = shift; $self->_check_command(@_); my $result = $self->ssh->capture(@_); return $result if ($? == 0 && !$self->ssh->error); } } use Server; my $server = Server->new(ssh => Net::OpenSSH->new('me@10.0.1.22')); print $server->grab('ls');

I'm trying to get the above to work following the documentation for Moose delegation which states the following:

You can use a role name as the value of handles: has 'uri' => ( is => 'ro', isa => 'URI', handles => 'HasURI', ); Moose will introspect the role to determine what methods it provides a +nd create a name-for-name mapping for each of those methods.

So I tried modifying the attribute line in the Server code like so:

has 'ssh' => (is => 'ro', isa => 'Net::OpenSSH', required => 1, hand +les => 'MyOpenSSH', );

However, this just results in an error:

You cannot overwrite a locally defined method (grab) with a delegation

Other attempts to get this working resulted in failure as well. What am I missing?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks