| 1 | package Net::CLI::Interact::Transport::Net_OpenSSH; | ||
| 2 | $Net::CLI::Interact::Transport::Net_OpenSSH::VERSION = '2.400001'; | ||
| 3 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Sub::Quote; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(InstanceOf ArrayRef Str); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | extends 'Net::CLI::Interact::Transport::Base'; | ||
| 8 | |||
| 9 | { | ||
| 10 | package # hide from pause | ||
| 11 | Net::CLI::Interact::Transport::Net_OpenSSH::Options; | ||
| 12 | |||
| 13 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 1 | ▶ | use Sub::Quote; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 1 | ▶ | use MooX::Types::MooseLike::Base qw(InstanceOf Any Str HashRef ArrayRef); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | extends 'Net::CLI::Interact::Transport::Options'; | ||
| 18 | |||
| 19 | has 'master' => ( | ||
| 20 | is => 'rw', | ||
| 21 | isa => InstanceOf['Net::OpenSSH'], | ||
| 22 | required => 1, | ||
| 23 | ); | ||
| 24 | |||
| 25 | has 'opts' => ( | ||
| 26 | is => 'rw', | ||
| 27 | isa => HashRef[Any], | ||
| 28 | default => sub { {} }, | ||
| 29 | ); | ||
| 30 | |||
| 31 | has 'shell_cmd' => ( | ||
| 32 | is => 'rw', | ||
| 33 | coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? [$_[0]] : $_[0] }), | ||
| 34 | isa => ArrayRef[Str], | ||
| 35 | default => sub { [] }, | ||
| 36 | ); | ||
| 37 | } | ||
| 38 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 39 | |||
| 40 | has 'connect_options' => ( | ||
| 41 | is => 'ro', | ||
| 42 | isa => InstanceOf['Net::CLI::Interact::Transport::Net_OpenSSH::Options'], | ||
| 43 | coerce => quote_sub(q{ (ref '' eq ref $_[0]) ? $_[0] : | ||
| 44 | Net::CLI::Interact::Transport::Net_OpenSSH::Options->new(@_) }), | ||
| 45 | required => 1, | ||
| 46 | ); | ||
| 47 | |||
| 48 | has app_and_runtime_options => ( | ||
| 49 | is => 'lazy', | ||
| 50 | isa => ArrayRef[Str], | ||
| 51 | ); | ||
| 52 | |||
| 53 | sub _build_app_and_runtime_options { | ||
| 54 | 0 | ▶ | my $self = shift; |
|
Subroutine
_build_app_and_runtime_options: not called CC=1 SCAR=6.9
| |||
| 55 | 0 | my $master = $self->connect_options->master; | |
| 56 | [ $master->make_remote_command($self->connect_options->opts, | ||
| 57 | 0 | @{$self->connect_options->shell_cmd}) ] | |
| 58 | } | ||
| 59 | |||
| 60 | sub app { | ||
| 61 | 0 | ▶ | shift->app_and_runtime_options->[0] |
|
Subroutine
app: not called CC=1 SCAR=6.9
| |||
| 62 | } | ||
| 63 | |||
| 64 | sub runtime_options { | ||
| 65 | 0 | ▶ | my @cmd = @{ shift->app_and_runtime_options }; |
|
Subroutine
runtime_options: not called CC=1 SCAR=6.9
| |||
| 66 | 0 | shift @cmd; | |
| 67 | 0 | @cmd; | |
| 68 | } | ||
| 69 | |||
| 70 | 1; | ||
| 71 | |||
| 72 | =pod | ||
| 73 | |||
| 74 | =for Pod::Coverage runtime_options | ||
| 75 | |||
| 76 | =encoding UTF-8 | ||
| 77 | |||
| 78 | =head1 NAME | ||
| 79 | |||
| 80 | Net::CLI::Interact::Transport::Net_OpenSSH - Net::OpenSSH based CLI connection | ||
| 81 | |||
| 82 | =head1 DESCRIPTION | ||
| 83 | |||
| 84 | This module provides a wrapped instance of a L<Net::OpenSSH> SSH | ||
| 85 | client object for use by L<Net::CLI::Interact>. | ||
| 86 | |||
| 87 | This allows one to combine the capability of Net::CLI::Interact to | ||
| 88 | talk to remote servers for which Net::OpenSSH one-command-per-session | ||
| 89 | approach is not well suited (i.e. network equipment running custom | ||
| 90 | administration shells) and still use the capability of Net::OpenSSH to | ||
| 91 | run several sessions over one single SSH connection, including | ||
| 92 | accessing SCP and SFTP services. | ||
| 93 | |||
| 94 | Note that this transport is not supported on Windows as Net::OpenSSH | ||
| 95 | is not supported there either. | ||
| 96 | |||
| 97 | =head1 INTERFACE | ||
| 98 | |||
| 99 | =head2 app_and_runtime_options | ||
| 100 | |||
| 101 | Based on the C<connect_options> hash provided to Net::CLI::Interact on | ||
| 102 | construction, selects and formats the command and arguments required | ||
| 103 | to run the SSH session over the Net::OpenSSH connection. | ||
| 104 | |||
| 105 | Under the hood, this method just wraps Net::OpenSSH | ||
| 106 | C<make_remote_command> method. | ||
| 107 | |||
| 108 | Supported attributes: | ||
| 109 | |||
| 110 | =over 4 | ||
| 111 | |||
| 112 | =item master | ||
| 113 | |||
| 114 | Reference to the Net::OpenSSH object wrapping the SSH master connection. | ||
| 115 | |||
| 116 | =item opts | ||
| 117 | |||
| 118 | Optional hash of extra options to be forwarded to Net::OpenSSH | ||
| 119 | C<make_remote_command> method. | ||
| 120 | |||
| 121 | =item shell_cmd | ||
| 122 | |||
| 123 | Remote command to start the shell. Can be a single string or an array reference. | ||
| 124 | |||
| 125 | The default is to pass nothing which on conforming SSH implementations | ||
| 126 | starts the shell configured for the user. | ||
| 127 | |||
| 128 | Examples: | ||
| 129 | |||
| 130 | # interact with default user shell: | ||
| 131 | $s->new({ | ||
| 132 | # ...other parameters to new()... | ||
| 133 | connect_options => { master => $ssh }, | ||
| 134 | }); | ||
| 135 | |||
| 136 | # interact with csh: | ||
| 137 | $s->new({ | ||
| 138 | # ...other parameters to new()... | ||
| 139 | connect_options => { | ||
| 140 | master => $ssh, | ||
| 141 | shell_cmd => ['csh', '-i'], | ||
| 142 | }, | ||
| 143 | }); | ||
| 144 | |||
| 145 | =item reap | ||
| 146 | |||
| 147 | Only used on Unix platforms, this installs a signal handler which attempts to | ||
| 148 | reap the C<ssh> child process. Pass a true value to enable this feature only | ||
| 149 | if you notice zombie processes are being left behind after use. | ||
| 150 | |||
| 151 | =back | ||
| 152 | |||
| 153 | =head1 COMPOSITION | ||
| 154 | |||
| 155 | See the following for further interface details: | ||
| 156 | |||
| 157 | =over 4 | ||
| 158 | |||
| 159 | =item * | ||
| 160 | |||
| 161 | L<Net::CLI::Interact::Transport::Base> | ||
| 162 | |||
| 163 | =back | ||
| 164 | |||
| 165 | =head1 AUTHORS | ||
| 166 | |||
| 167 | Oliver Gorwits <oliver@cpan.org> | ||
| 168 | Salvador FandiE<ntilde>o <sfandino@yahoo.com> | ||
| 169 | |||
| 170 | =head1 COPYRIGHT AND LICENSE | ||
| 171 | |||
| 172 | This software is copyright (c) 2014 by Oliver Gorwits. | ||
| 173 | This software is copyright (c) 2014 by Salvador FandiƱo. | ||
| 174 | |||
| 175 | This is free software; you can redistribute it and/or modify it under | ||
| 176 | the same terms as the Perl 5 programming language system itself. | ||
| 177 | |||
| 178 | =cut | ||
| 179 | |||