{ package Server;
use Carp;
use Moose;
use Net::OpenSSH;
use Config::Simple;
with 'MyOpenSSH';
has 'ssh' => (is => 'ro', isa => 'Net::OpenSSH', required => 1, handles => 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');
####
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 and create a name-for-name mapping for each of those methods.
####
has 'ssh' => (is => 'ro', isa => 'Net::OpenSSH', required => 1, handles => 'MyOpenSSH', );
####
You cannot overwrite a locally defined method (grab) with a delegation