| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
16120
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
55
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package IPC::Open3::Callback::Command; |
|
5
|
|
|
|
|
|
|
$IPC::Open3::Callback::Command::VERSION = '1.17'; |
|
6
|
|
|
|
|
|
|
# ABSTRACT: A utility class that provides subroutines for building shell command strings. |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
45
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = |
|
10
|
|
|
|
|
|
|
qw(batch_command command command_options cp_command mkdir_command pipe_command rm_command sed_command write_command); |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3
|
use File::Spec; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1609
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub batch_command { |
|
15
|
0
|
|
|
0
|
|
|
my ( @commands, $batch_options, $command_options ); |
|
16
|
0
|
|
|
|
|
|
(@commands) = @_; |
|
17
|
0
|
0
|
|
|
|
|
$command_options = pop(@commands) |
|
18
|
|
|
|
|
|
|
if ( ref( $commands[$#commands] ) eq 'IPC::Open3::Callback::Command::CommandOptions' ); |
|
19
|
0
|
0
|
|
|
|
|
$batch_options = pop(@commands) if ( ref( $commands[$#commands] ) eq 'HASH' ); |
|
20
|
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
push( @commands, $command_options ) if ($command_options); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
wrap( |
|
24
|
|
|
|
|
|
|
$batch_options || {}, |
|
25
|
|
|
|
|
|
|
@commands, |
|
26
|
|
|
|
|
|
|
sub { |
|
27
|
0
|
|
|
0
|
|
|
return @_; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
0
|
|
0
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub command_options { |
|
33
|
0
|
|
|
0
|
|
|
return IPC::Open3::Callback::Command::CommandOptions->new(@_); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub command { |
|
37
|
|
|
|
|
|
|
wrap( |
|
38
|
|
|
|
|
|
|
{}, |
|
39
|
|
|
|
|
|
|
@_, |
|
40
|
|
|
|
|
|
|
sub { |
|
41
|
0
|
|
|
0
|
|
|
return shift; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
|
|
0
|
|
|
); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub cp_command { |
|
47
|
0
|
|
|
0
|
|
|
my ( $source_path, $source_command_options, $destination_path, $destination_command_options, |
|
48
|
|
|
|
|
|
|
%cp_options ); |
|
49
|
0
|
|
|
|
|
|
$source_path = _escape_path(shift); |
|
50
|
0
|
0
|
|
|
|
|
$source_command_options = shift |
|
51
|
|
|
|
|
|
|
if ( ref( $_[0] ) eq 'IPC::Open3::Callback::Command::CommandOptions' ); |
|
52
|
0
|
|
|
|
|
|
$destination_path = _escape_path(shift); |
|
53
|
0
|
0
|
|
|
|
|
$destination_command_options = shift |
|
54
|
|
|
|
|
|
|
if ( ref( $_[0] ) eq 'IPC::Open3::Callback::Command::CommandOptions' ); |
|
55
|
0
|
|
|
|
|
|
%cp_options = @_; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
$source_command_options = command_options() if ( !$source_command_options ); |
|
58
|
0
|
0
|
|
|
|
|
$destination_command_options = command_options() if ( !$destination_command_options ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $source_command; |
|
61
|
|
|
|
|
|
|
my $destination_command; |
|
62
|
0
|
0
|
|
|
|
|
if ( $cp_options{file} ) { |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# is a file, so use cat | dd |
|
65
|
0
|
0
|
|
|
|
|
if ( $cp_options{compress} ) { |
|
66
|
0
|
|
|
|
|
|
$source_command = command( "gzip -c $source_path", $source_command_options ); |
|
67
|
0
|
|
|
|
|
|
$destination_command = |
|
68
|
|
|
|
|
|
|
pipe_command( "gunzip", "dd of=$destination_path", $destination_command_options ); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
else { |
|
71
|
0
|
|
|
|
|
|
$source_command = command( "cat $source_path", $source_command_options ); |
|
72
|
0
|
|
|
|
|
|
$destination_command = |
|
73
|
|
|
|
|
|
|
command( "dd of=$destination_path", $destination_command_options ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
else { |
|
77
|
|
|
|
|
|
|
# is a directory, so use tar or unzip |
|
78
|
0
|
0
|
0
|
|
|
|
if ( $cp_options{archive} && $cp_options{archive} eq 'zip' ) { |
|
79
|
0
|
|
0
|
|
|
|
my $temp_zip = File::Spec->catfile( $destination_path, |
|
80
|
|
|
|
|
|
|
$cp_options{unzip_temp_file} || "temp_cp_command.zip" ); |
|
81
|
0
|
|
|
|
|
|
$source_command = |
|
82
|
|
|
|
|
|
|
command( |
|
83
|
|
|
|
|
|
|
batch_command( "cd $source_path", "zip -qr - .", { subshell => "bash -c " } ), |
|
84
|
|
|
|
|
|
|
$source_command_options ); |
|
85
|
0
|
|
|
|
|
|
$destination_command = batch_command( |
|
86
|
|
|
|
|
|
|
"dd of=$temp_zip", "unzip -qod $destination_path $temp_zip", |
|
87
|
|
|
|
|
|
|
rm_command($temp_zip), $destination_command_options |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
else { |
|
91
|
|
|
|
|
|
|
# default, use tar |
|
92
|
0
|
|
|
|
|
|
my @parts = ("tar c -C $source_path ."); |
|
93
|
0
|
|
|
|
|
|
my @destination_parts = (); |
|
94
|
0
|
0
|
|
|
|
|
if ( $cp_options{status} ) { |
|
95
|
0
|
|
0
|
|
|
|
push( |
|
96
|
|
|
|
|
|
|
@parts, |
|
97
|
|
|
|
|
|
|
join( |
|
98
|
|
|
|
|
|
|
'', |
|
99
|
|
|
|
|
|
|
'pv -f -s `', |
|
100
|
|
|
|
|
|
|
_sudo_command( |
|
101
|
|
|
|
|
|
|
$source_command_options |
|
102
|
|
|
|
|
|
|
&& $source_command_options->get_sudo_username(), |
|
103
|
|
|
|
|
|
|
pipe_command( "du -sb $source_path", 'cut -f1' ) |
|
104
|
|
|
|
|
|
|
), |
|
105
|
|
|
|
|
|
|
'`' |
|
106
|
|
|
|
|
|
|
) |
|
107
|
|
|
|
|
|
|
); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
0
|
0
|
|
|
|
|
if ( $cp_options{compress} ) { |
|
110
|
0
|
|
|
|
|
|
push( @parts, 'gzip' ); |
|
111
|
0
|
|
|
|
|
|
push( @destination_parts, 'gunzip' ); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
push( |
|
114
|
0
|
|
0
|
|
|
|
@destination_parts, |
|
115
|
|
|
|
|
|
|
_sudo_command( |
|
116
|
|
|
|
|
|
|
$destination_command_options |
|
117
|
|
|
|
|
|
|
&& $destination_command_options->get_sudo_username(), |
|
118
|
|
|
|
|
|
|
"tar x -C $destination_path" |
|
119
|
|
|
|
|
|
|
) |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$source_command = command( pipe_command(@parts), $source_command_options ); |
|
123
|
0
|
|
|
|
|
|
$destination_command = command( pipe_command(@destination_parts), |
|
124
|
|
|
|
|
|
|
$destination_command_options->clone( sudo_username => undef ) ); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return pipe_command( $source_command, $destination_command ); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub mkdir_command { |
|
132
|
|
|
|
|
|
|
wrap( |
|
133
|
|
|
|
|
|
|
{}, |
|
134
|
|
|
|
|
|
|
@_, |
|
135
|
|
|
|
|
|
|
sub { |
|
136
|
0
|
|
|
0
|
|
|
return 'mkdir -p "' . join( '" "', @_ ) . '"'; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
0
|
|
|
0
|
|
|
); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub pipe_command { |
|
142
|
|
|
|
|
|
|
wrap( |
|
143
|
|
|
|
|
|
|
{ command_separator => '|' }, |
|
144
|
|
|
|
|
|
|
@_, |
|
145
|
|
|
|
|
|
|
sub { |
|
146
|
0
|
|
|
0
|
|
|
return @_; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
0
|
|
|
0
|
|
|
); |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub _quote_command { |
|
152
|
0
|
|
|
0
|
|
|
my ($command) = @_; |
|
153
|
0
|
|
|
|
|
|
$command =~ s/\\/\\\\/g; |
|
154
|
0
|
|
|
|
|
|
$command =~ s/`/\\`/g; # for `command` |
|
155
|
0
|
|
|
|
|
|
$command =~ s/"/\\"/g; |
|
156
|
0
|
|
|
|
|
|
return "\"$command\""; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _escape_path { |
|
160
|
0
|
|
|
0
|
|
|
my ($path) = @_; |
|
161
|
0
|
|
|
|
|
|
$path =~ s/(['"`\s])/\\$1/g; |
|
162
|
0
|
|
|
|
|
|
return $path; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub rm_command { |
|
166
|
|
|
|
|
|
|
wrap( |
|
167
|
|
|
|
|
|
|
{}, |
|
168
|
|
|
|
|
|
|
@_, |
|
169
|
|
|
|
|
|
|
sub { |
|
170
|
0
|
|
|
0
|
|
|
return 'rm -rf "' . join( '" "', @_ ) . '"'; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
0
|
|
|
0
|
|
|
); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub sed_command { |
|
176
|
|
|
|
|
|
|
wrap( |
|
177
|
|
|
|
|
|
|
{}, |
|
178
|
|
|
|
|
|
|
@_, |
|
179
|
|
|
|
|
|
|
sub { |
|
180
|
0
|
|
|
0
|
|
|
my @args = @_; |
|
181
|
0
|
|
|
|
|
|
my $options = {}; |
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
0
|
|
|
|
|
if ( ref( $args[$#args] ) eq 'HASH' ) { |
|
184
|
0
|
|
|
|
|
|
$options = pop(@args); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
my $command = 'sed'; |
|
188
|
0
|
0
|
|
|
|
|
$command .= ' -i' if ( $options->{in_place} ); |
|
189
|
0
|
0
|
|
|
|
|
if ( defined( $options->{temp_script_file} ) ) { |
|
190
|
0
|
|
|
|
|
|
my $temp_script_file_name = $options->{temp_script_file}->filename(); |
|
191
|
0
|
0
|
|
|
|
|
print( { $options->{temp_script_file} } join( ' ', '', map {"$_;"} @args ) ) |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
if ( scalar(@args) ); |
|
193
|
0
|
|
|
|
|
|
print( |
|
194
|
0
|
|
|
|
|
|
{ $options->{temp_script_file} } join( ' ', |
|
195
|
|
|
|
|
|
|
'', |
|
196
|
0
|
|
|
|
|
|
map {"s/$_/$options->{replace_map}{$_}/g;"} |
|
197
|
0
|
0
|
|
|
|
|
keys( %{ $options->{replace_map} } ) ) |
|
198
|
|
|
|
|
|
|
) if ( defined( $options->{replace_map} ) ); |
|
199
|
0
|
|
|
|
|
|
$options->{temp_script_file}->flush(); |
|
200
|
0
|
|
|
|
|
|
$command .= " -f $temp_script_file_name"; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
else { |
|
203
|
0
|
0
|
|
|
|
|
$command .= join( ' ', '', map {"-e '$_'"} @args ) if ( scalar(@args) ); |
|
|
0
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$command .= join( ' ', |
|
205
|
|
|
|
|
|
|
'', |
|
206
|
0
|
|
|
|
|
|
map {"-e 's/$_/$options->{replace_map}{$_}/g'"} |
|
207
|
0
|
0
|
|
|
|
|
keys( %{ $options->{replace_map} } ) ) |
|
208
|
|
|
|
|
|
|
if ( defined( $options->{replace_map} ) ); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
0
|
0
|
|
|
|
|
$command .= join( ' ', '', @{ $options->{files} } ) if ( $options->{files} ); |
|
|
0
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return $command; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
0
|
|
|
0
|
|
|
); |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub _sudo_command { |
|
218
|
0
|
|
|
0
|
|
|
my ( $sudo_username, $command ) = @_; |
|
219
|
0
|
0
|
|
|
|
|
if ( defined($sudo_username) ) { |
|
220
|
0
|
0
|
|
|
|
|
$command = "sudo " . ( $sudo_username ? "-u $sudo_username " : '' ) . $command; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
0
|
|
|
|
|
|
return $command; |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub write_command { |
|
226
|
0
|
|
|
0
|
|
|
my ( $filename, @lines, $write_options, $command_options ); |
|
227
|
0
|
|
|
|
|
|
$filename = shift; |
|
228
|
0
|
|
|
|
|
|
@lines = @_; |
|
229
|
0
|
0
|
|
|
|
|
$command_options = pop(@lines) |
|
230
|
|
|
|
|
|
|
if ( ref( $lines[$#lines] ) eq 'IPC::Open3::Callback::Command::CommandOptions' ); |
|
231
|
0
|
0
|
|
|
|
|
$write_options = pop(@lines) if ( ref( $lines[$#lines] ) eq 'HASH' ); |
|
232
|
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
my $remote_command = "dd of=$filename"; |
|
234
|
0
|
0
|
0
|
|
|
|
if ( defined($write_options) && defined( $write_options->{mode} ) ) { |
|
|
|
0
|
|
|
|
|
|
|
235
|
0
|
0
|
|
|
|
|
if ( defined($command_options) ) { |
|
|
|
0
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
$remote_command = |
|
237
|
|
|
|
|
|
|
batch_command( $remote_command, "chmod $write_options->{mode} $filename", |
|
238
|
|
|
|
|
|
|
$command_options ); |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
elsif ( defined($command_options) ) { |
|
241
|
0
|
|
|
|
|
|
$remote_command = |
|
242
|
|
|
|
|
|
|
batch_command( $remote_command, "chmod $write_options->{mode} $filename" ); |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
elsif ( defined($command_options) ) { |
|
246
|
0
|
|
|
|
|
|
$remote_command = command( $remote_command, $command_options ); |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
0
|
0
|
0
|
|
|
|
my $line_separator = |
|
250
|
|
|
|
|
|
|
( defined($write_options) && defined( $write_options->{line_separator} ) ) |
|
251
|
|
|
|
|
|
|
? $write_options->{line_separator} |
|
252
|
|
|
|
|
|
|
: '\n'; |
|
253
|
0
|
|
|
|
|
|
return pipe_command( 'printf "' . join( $line_separator, @lines ) . '"', $remote_command ); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Handles wrapping commands with possible ssh and command prefix |
|
257
|
|
|
|
|
|
|
sub wrap { |
|
258
|
0
|
|
|
0
|
|
|
my $wrap_options = shift; |
|
259
|
0
|
|
|
|
|
|
my $builder = pop; |
|
260
|
0
|
|
|
|
|
|
my @args = @_; |
|
261
|
0
|
|
|
|
|
|
my ( $ssh, $username, $hostname, $sudo_username, $pretty ); |
|
262
|
|
|
|
|
|
|
|
|
263
|
0
|
0
|
|
|
|
|
if ( ref( $args[$#args] ) eq 'IPC::Open3::Callback::Command::CommandOptions' ) { |
|
264
|
0
|
|
|
|
|
|
my $options = pop(@args); |
|
265
|
0
|
|
0
|
|
|
|
$ssh = $options->get_ssh() || 'ssh'; |
|
266
|
0
|
|
|
|
|
|
$username = $options->get_username(); |
|
267
|
0
|
|
|
|
|
|
$hostname = $options->get_hostname(); |
|
268
|
0
|
|
|
|
|
|
$sudo_username = $options->get_sudo_username(); |
|
269
|
0
|
|
|
|
|
|
$pretty = $options->get_pretty(); |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
my $destination_command = ''; |
|
273
|
0
|
|
0
|
|
|
|
my $command_separator = $wrap_options->{command_separator} || ';'; |
|
274
|
0
|
|
|
|
|
|
my $commands = 0; |
|
275
|
0
|
|
|
|
|
|
foreach my $command ( &$builder(@args) ) { |
|
276
|
0
|
0
|
|
|
|
|
if ( defined($command) ) { |
|
277
|
0
|
0
|
|
|
|
|
if ( $commands++ > 0 ) { |
|
278
|
0
|
|
|
|
|
|
$destination_command .= $command_separator; |
|
279
|
0
|
0
|
|
|
|
|
if ($pretty) { |
|
280
|
0
|
|
|
|
|
|
$destination_command .= "\n"; |
|
281
|
|
|
|
|
|
|
} |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
$command =~ s/^(.*?[^\\]);$/$1/; # from find -exec |
|
285
|
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
$command = _sudo_command( $sudo_username, $command ); |
|
287
|
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
|
$destination_command .= $command; |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
0
|
|
|
|
|
if ( $wrap_options->{subshell} ) { |
|
293
|
0
|
|
|
|
|
|
$destination_command = $wrap_options->{subshell} . _quote_command($destination_command); |
|
294
|
|
|
|
|
|
|
} |
|
295
|
|
|
|
|
|
|
|
|
296
|
0
|
0
|
0
|
|
|
|
if ( !defined($username) && !defined($hostname) ) { |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# silly to ssh to localhost as current user, so dont |
|
299
|
0
|
|
|
|
|
|
return $destination_command; |
|
300
|
|
|
|
|
|
|
} |
|
301
|
|
|
|
|
|
|
|
|
302
|
0
|
0
|
|
|
|
|
my $userAt = |
|
|
|
0
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
$username |
|
304
|
|
|
|
|
|
|
? ( ( $ssh =~ /plink(?:\.exe)?$/ ) ? "-l $username " : "$username\@" ) |
|
305
|
|
|
|
|
|
|
: ''; |
|
306
|
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
|
$destination_command = _quote_command($destination_command); |
|
308
|
0
|
|
0
|
|
|
|
return "$ssh $userAt" . ( $hostname || 'localhost' ) . " $destination_command"; |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
package IPC::Open3::Callback::Command::CommandOptions; |
|
312
|
|
|
|
|
|
|
$IPC::Open3::Callback::Command::CommandOptions::VERSION = '1.17'; |
|
313
|
1
|
|
|
1
|
|
504
|
use parent qw(Class::Accessor); |
|
|
1
|
|
|
|
|
246
|
|
|
|
1
|
|
|
|
|
5
|
|
|
314
|
|
|
|
|
|
|
__PACKAGE__->follow_best_practice; |
|
315
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors(qw(hostname pretty ssh sudo_username username)); |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub new { |
|
318
|
|
|
|
|
|
|
my ( $class, @args ) = @_; |
|
319
|
|
|
|
|
|
|
return bless( {}, $class )->_init(@args); |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
sub clone { |
|
323
|
|
|
|
|
|
|
my ( $instance, %options ) = @_; |
|
324
|
|
|
|
|
|
|
if ( exists( $instance->{hostname} ) && !exists( $options{hostname} ) ) { |
|
325
|
|
|
|
|
|
|
$options{hostname} = $instance->{hostname}; |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
if ( exists( $instance->{ssh} ) && !exists( $options{ssh} ) ) { |
|
328
|
|
|
|
|
|
|
$options{ssh} = $instance->{ssh}; |
|
329
|
|
|
|
|
|
|
} |
|
330
|
|
|
|
|
|
|
if ( exists( $instance->{username} ) && !exists( $options{username} ) ) { |
|
331
|
|
|
|
|
|
|
$options{username} = $instance->{username}; |
|
332
|
|
|
|
|
|
|
} |
|
333
|
|
|
|
|
|
|
if ( exists( $instance->{sudo_username} ) && !exists( $options{sudo_username} ) ) { |
|
334
|
|
|
|
|
|
|
$options{sudo_username} = $instance->{sudo_username}; |
|
335
|
|
|
|
|
|
|
} |
|
336
|
|
|
|
|
|
|
if ( exists( $instance->{pretty} ) && !exists( $options{pretty} ) ) { |
|
337
|
|
|
|
|
|
|
$options{pretty} = $instance->{pretty}; |
|
338
|
|
|
|
|
|
|
} |
|
339
|
|
|
|
|
|
|
return new( ref($instance), %options ); |
|
340
|
|
|
|
|
|
|
} |
|
341
|
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub _init { |
|
343
|
|
|
|
|
|
|
my ( $self, %options ) = @_; |
|
344
|
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
$self->{hostname} = $options{hostname} if ( defined( $options{hostname} ) ); |
|
346
|
|
|
|
|
|
|
$self->{ssh} = $options{ssh} if ( defined( $options{ssh} ) ); |
|
347
|
|
|
|
|
|
|
$self->{username} = $options{username} if ( defined( $options{username} ) ); |
|
348
|
|
|
|
|
|
|
$self->{sudo_username} = $options{sudo_username} if ( defined( $options{sudo_username} ) ); |
|
349
|
|
|
|
|
|
|
$self->{pretty} = $options{pretty} if ( defined( $options{pretty} ) ); |
|
350
|
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
return $self; |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
1; |
|
355
|
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
__END__ |