line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::SSH::Client::Exec; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use XAS::Class |
6
|
1
|
|
|
|
|
5
|
debug => 0, |
7
|
|
|
|
|
|
|
version => $VERSION, |
8
|
|
|
|
|
|
|
base => 'XAS::Lib::SSH::Client', |
9
|
|
|
|
|
|
|
utils => ':validation trim', |
10
|
|
|
|
|
|
|
constants => 'CODEREF', |
11
|
1
|
|
|
1
|
|
1237
|
; |
|
1
|
|
|
|
|
2
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#use Data::Hexdumper; |
14
|
|
|
|
|
|
|
#use Data::Dumper; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# Public Methods |
18
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub setup { |
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $output; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Merge stderr and stdout. |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->chan->ext_data('merge'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub run { |
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
33
|
0
|
|
|
|
|
|
my ($command) = validate_params(\@_, [1] ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub call { |
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
my ($command, $parser) = validate_params(\@_, [ |
40
|
|
|
|
|
|
|
1, |
41
|
|
|
|
|
|
|
{ type => CODEREF }, |
42
|
|
|
|
|
|
|
]); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @output; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# execute a command, retrieve the output and dispatch to a parser. |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->chan->exec($command); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self->{'exit_code'} = $self->chan->exit_status(); |
51
|
0
|
|
|
|
|
|
$self->{'exit_signal'} = $self->chan->exit_signal(); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
do { |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $line = $self->gets; |
56
|
0
|
|
|
|
|
|
push(@output, trim($line)); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} while ($self->pending); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $parser->(\@output); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
65
|
|
|
|
|
|
|
# Private Methods |
66
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |