| 1 | package Net::SSH::Mechanize::Multi; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Net::SSH::Mechanize; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Coro; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.1.3'; # VERSION | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | ###################################################################### | ||||||||||||||||||||||||||||
| 10 | # attributes | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | has 'ssh_instances' => ( | ||||||||||||||||||||||||||||
| 13 | isa => 'ArrayRef[Net::SSH::Mechanize]', | ||||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | 1 | ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has 'names' => ( | ||||||||||||||||||||||||||||
| 20 | isa => 'HashRef[Net::SSH::Mechanize]', | ||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | default => sub { +{} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 23 | 1 | ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has 'constructor_defaults' => ( | ||||||||||||||||||||||||||||
| 26 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | default => sub { +{} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | 1 | ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | ###################################################################### | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _to_ssh { | ||||||||||||||||||||||||||
|
Subroutine
_to_ssh: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 0 | my @instances; | |||||||||||||||||||||||||||
| 36 | 0 | my $defaults = $self->constructor_defaults; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | while(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($name, $connection) = splice @_, 0, 2; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | $connection = Net::SSH::Mechanize->new(%$defaults, %$connection) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | if ref $connection eq 'HASH'; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $connection = Net::SSH::Mechanize->new(%$defaults, connection_params => $connection) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($connection) and $connection->isa("Net::SSH::Mechanize::ConnectParams")
MC/DC0%0/2
builtin::blessed($connection) and $connection->isa("Net::SSH::Mechanize::ConnectParams")
builtin::blessed($connection)
$connection->isa("Net::SSH::Mechanize::ConnectParams")
Truth table0%0/3
A and B
A= builtin::blessed($connection)B= $connection->isa("Net::SSH::Mechanize::ConnectParams")
| |||||||||||||||||||||||||||||
| 44 | if blessed $connection | ||||||||||||||||||||||||||||
| 45 | && $connection->isa('Net::SSH::Mechanize::ConnectParams'); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | croak "Connection '$name' is not a hashref, Net::SSH::Mechanize::ConnectParams instance, nor a", | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($connection) and $connection->isa("Net::SSH::Mechanize")
MC/DC0%0/2
builtin::blessed($connection) and $connection->isa("Net::SSH::Mechanize")
builtin::blessed($connection)
$connection->isa("Net::SSH::Mechanize")
Truth table0%0/3
A and B
A= builtin::blessed($connection)B= $connection->isa("Net::SSH::Mechanize")
| |||||||||||||||||||||||||||||
| 48 | "Net::SSH::Mechanize instance (it is $connection)" | ||||||||||||||||||||||||||||
| 49 | unless blessed $connection | ||||||||||||||||||||||||||||
| 50 | && $connection->isa('Net::SSH::Mechanize'); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | push @instances, $connection; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return @instances; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | croak "uneven number of name => connection parameters" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | if @_ % 2; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my %new_instances = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my @new_names = keys %new_instances; | |||||||||||||||||||||||||||
| 67 | 0 | my $names = $self->names; | |||||||||||||||||||||||||||
| 68 | 0 | my @defined = grep { $names->{$_} } @new_names; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | croak "These names are already defined: @defined" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | if @defined; | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my @new_instances = $self->_to_ssh(%new_instances); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $instances = $self->ssh_instances; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | @$names{@new_names} = @new_instances; | |||||||||||||||||||||||||||
| 78 | 0 | push @$instances, @new_instances; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | return @new_instances; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub in_parallel { | ||||||||||||||||||||||||||
|
Subroutine
in_parallel: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 0 | my $cb = pop; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | croak "you must supply a callback" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | unless ref $cb eq 'CODE'; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my @names = @_; | |||||||||||||||||||||||||||
| 91 | 0 | my $known_names = $self->names; | |||||||||||||||||||||||||||
| 92 | 0 | my @instances = map { $known_names->{$_} } @names; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if (@names != grep { defined } @instances) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | my @unknown = grep { !$known_names->{$_} } @names; | |||||||||||||||||||||||||||
| 95 | 0 | croak "These names are unknown: @unknown"; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my @threads; | |||||||||||||||||||||||||||
| 99 | 0 | my $ix = 0; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | foreach my $ix (0..$#instances) { | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | push @threads, async { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 103 | 0 | my $name = $names[$ix]; | |||||||||||||||||||||||||||
| 104 | 0 | my $ssh = $instances[$ix]; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | eval { | ||||||||||||||||||||||||||||
| 107 | 0 | $cb->($name, $ssh); | |||||||||||||||||||||||||||
| 108 | 0 | 1; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | print "error ($name): $@"; | |||||||||||||||||||||||||||
| 111 | }; | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | } | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | return \@threads; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||