line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OpenSSH::Compat::SSH; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
13140
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
6
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
7
|
1
|
|
|
1
|
|
3
|
use Carp (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
8
|
1
|
|
|
1
|
|
413
|
use IPC::Open2; |
|
1
|
|
|
|
|
3428
|
|
|
1
|
|
|
|
|
48
|
|
9
|
1
|
|
|
1
|
|
5
|
use IPC::Open3; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
10
|
1
|
|
|
1
|
|
828
|
use Net::OpenSSH; |
|
1
|
|
|
|
|
28986
|
|
|
1
|
|
|
|
|
50
|
|
11
|
1
|
|
|
1
|
|
10
|
use Net::OpenSSH::Constants qw(OSSH_MASTER_FAILED OSSH_SLAVE_CMD_FAILED); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
216
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(ssh ssh_cmd sshopen2 sshopen3); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $supplant; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %DEFAULTS = ( connection => [] ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub import { |
22
|
1
|
|
|
1
|
|
11
|
my $class = shift; |
23
|
1
|
50
|
33
|
|
|
12
|
if (!$supplant and |
|
|
|
33
|
|
|
|
|
24
|
|
|
|
|
|
|
$class eq __PACKAGE__ and |
25
|
|
|
|
|
|
|
grep($_ eq ':supplant', @_)) { |
26
|
0
|
|
|
|
|
0
|
$supplant = 1; |
27
|
0
|
|
|
|
|
0
|
for my $end ('') { |
28
|
0
|
|
|
|
|
0
|
my $this = __PACKAGE__; |
29
|
0
|
|
|
|
|
0
|
my $pkg = "Net::SSH"; |
30
|
0
|
|
|
|
|
0
|
my $file = "Net/SSH"; |
31
|
0
|
0
|
|
|
|
0
|
if ($end) { |
32
|
0
|
|
|
|
|
0
|
$this .= "::$end"; |
33
|
0
|
|
|
|
|
0
|
$pkg .= "::$end"; |
34
|
0
|
|
|
|
|
0
|
$file .= "/$end"; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
$INC{$file . '.pm'} = __FILE__; |
37
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
499
|
|
38
|
0
|
|
|
|
|
0
|
@{"${pkg}::ISA"} = ($this); |
|
0
|
|
|
|
|
0
|
|
39
|
0
|
|
|
|
|
0
|
${"${pkg}::VERSION"} = __PACKAGE__->version; |
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
95
|
__PACKAGE__->export_to_level(1, $class, |
43
|
|
|
|
|
|
|
grep $_ ne ':supplant', @_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
0
|
0
|
|
sub version { "0.09 (".__PACKAGE__."-$VERSION)" } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub ssh { |
49
|
0
|
|
|
0
|
0
|
|
my $host = shift; |
50
|
0
|
|
|
|
|
|
my $ssh = Net::OpenSSH->new($host); |
51
|
0
|
0
|
|
|
|
|
if ($ssh->error) { |
52
|
0
|
|
|
|
|
|
$? = (255<<8); |
53
|
0
|
|
|
|
|
|
return -1; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
my @cmd = $ssh->make_remote_command({quote_args => 0}, @_); |
56
|
0
|
|
|
|
|
|
system (@cmd); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub ssh_cmd { |
60
|
0
|
|
|
0
|
0
|
|
my ($host, $user, $command, @args, $stdin); |
61
|
0
|
0
|
|
|
|
|
if (ref $_[0] eq 'HASH') { |
62
|
0
|
|
|
|
|
|
my %opts = $_[0]; |
63
|
0
|
|
|
|
|
|
$host = delete $opts{host}; |
64
|
0
|
|
|
|
|
|
$user = delete $opts{user}; |
65
|
0
|
|
|
|
|
|
$command = delete $opts{command}; |
66
|
0
|
|
|
|
|
|
$stdin = delete $opts{stdin_string}; |
67
|
0
|
|
|
|
|
|
my $args = delete $opts{args}; |
68
|
0
|
0
|
|
|
|
|
@args = @$args if defined $args; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
else { |
71
|
0
|
|
|
|
|
|
($host, $command, @args) = @_; |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
$stdin = '' unless defined $stdin; |
74
|
0
|
|
|
|
|
|
my $ssh = Net::OpenSSH->new($host, user => $user); |
75
|
0
|
0
|
|
|
|
|
if ($ssh->error) { |
76
|
0
|
|
|
|
|
|
$? = (255<<8); |
77
|
0
|
|
|
|
|
|
die $ssh->error; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
my ($out, $err) = $ssh->capture2({quote_args => 0, stdin_data => $stdin}, |
80
|
|
|
|
|
|
|
$command, @args); |
81
|
0
|
0
|
|
|
|
|
die $err if length $err; |
82
|
0
|
|
|
|
|
|
$out; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub sshopen2 { |
86
|
0
|
|
|
0
|
0
|
|
my($host, $reader, $writer, $cmd, @args) = @_; |
87
|
0
|
|
|
|
|
|
my $ssh = Net::OpenSSH->new($host); |
88
|
0
|
|
|
|
|
|
$ssh->die_on_error; |
89
|
0
|
|
|
|
|
|
my @cmd = $ssh->make_remote_command({quote_args => 0}, $cmd, @args); |
90
|
0
|
|
|
|
|
|
open2($reader, $writer, @cmd); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub sshopen3 { |
94
|
0
|
|
|
0
|
0
|
|
my($host, $writer, $reader, $error, $cmd, @args) = @_; |
95
|
0
|
|
|
|
|
|
my $ssh = Net::OpenSSH->new($host); |
96
|
0
|
|
|
|
|
|
$ssh->die_on_error; |
97
|
0
|
|
|
|
|
|
my @cmd = $ssh->make_remote_command({quote_args => 0}, $cmd, @args); |
98
|
0
|
|
|
|
|
|
open3($writer, $reader, $error, @cmd); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |