lib/Rex/Task.pm

filter: Statementstmt 79.8% 290 / 363 Branchbran 66.6% 80 / 120 Conditioncond 69.3% 52 / 75 MC/DCmcdc 32.6% 15 / 46 Subroutinesub 85.2% 58 / 68 Podpod 96.0% 48 / 50 totaltotal 75.2% 543 / 722 CC 93 SCAR 24.9
CC
93
Cov
76%
connect
45.3
run
25.3
server
14.2
CRAP 12.1
« lib/Rex/Box/KVM.pm ↑ Summary lib/Rex/Interface/Connection/HTTPS.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 =head1 NAME
6  
7 Rex::Task - The Task Object
8  
9 =head1 DESCRIPTION
10  
11 The Task Object. Typically you only need this class if you want to manipulate tasks after their initial creation.
12  
13 =head1 SYNOPSIS
14  
15 use Rex::Task;
16  
17 # create a new task
18 my $task = Rex::Task->new( name => 'testtask' );
19 $task->set_server('remoteserver');
20 $task->set_code( sub { say 'Hello'; } );
21 $task->modify( 'no_ssh', 1 );
22  
23 # retrieve an existing task
24 use Rex::TaskList;
25  
26 my $existing_task = Rex::TaskList->create->get_task('my_task');
27  
28 =head1 METHODS
29  
30 =cut
31  
32 package Rex::Task;
33  
34 56 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 56 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 56 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 56 our $VERSION = '1.16.1'; # VERSION
40  
41 56 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 56 ▶use Rex::TaskList;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 56 ▶use Rex::Interface::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 56 ▶use Rex::Interface::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 56 ▶use Rex::Group::Entry::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 56 ▶use Rex::Profiler;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 56 ▶use Rex::Hardware;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 56 ▶use Rex::Interface::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 56 ▶use Rex::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 56 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 56 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 56 ▶use Rex::Notify;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 56 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 56 require Rex::Commands;
56  
57 56 require Rex::Args;
58  
59 =head2 new
60  
61 This is the constructor.
62  
63 $task = Rex::Task->new(
64 func => sub { some_code_here },
65 server => [ @server ],
66 desc => $description,
67 no_ssh => $no_ssh,
68 hidden => $hidden,
69 auth => {
70 user => $user,
71 password => $password,
72 private_key => $private_key,
73 public_key => $public_key,
74 },
75 before => [sub {}, sub {}, ...],
76 after => [sub {}, sub {}, ...],
77 around => [sub {}, sub {}, ...],
78 before_task_start => [sub {}, sub {}, ...],
79 after_task_finished => [sub {}, sub {}, ...],
80 name => $task_name,
81 executor => Rex::Interface::Executor->create,
82 opts => {key1 => val1, key2 => val2, ...},
83 args => [arg1, arg2, ...],
84 );
85  
86 =cut
87  
88 245 ▶sub new {
Subroutine new: called CC=9 SCAR=22.5
Pod documented
89 245 my $that = shift;
90 245 ▶ my $proto = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
02450
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
91 245 my $self = {@_};
92  
93 245 bless( $self, $proto );
94  
95 245 ▶ if ( !exists $self->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"name"}) 0 245 245
96 0 die("You have to define a task name.");
97 }
98  
99 245 ▶ $self->{no_ssh} ||= 0;
Condition100%2/2
$self->{"no_ssh"} ||= 0
l!l
2243
MC/DC100%1/1
$self->{"no_ssh"} ||= 0
$self->{"no_ssh"}
Truth table100%2/2
A
A= $self->{"no_ssh"}
Aresult
11
00
100 245 ▶ $self->{func} ||= sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.2
Condition66%2/3
$self->{"func"} ||= sub { }
l!l&&r!l&&!r
24410
MC/DC0%0/2
$self->{"func"} ||= sub { }
$self->{"func"} sub { }
Truth table66%2/3
A ||= B
A= $self->{"func"}B= sub { }
ABresult
1X1
011
000
101 245 ▶ $self->{executor} ||= Rex::Interface::Executor->create;
Condition66%2/3
$self->{"executor"} ||= "Rex::Interface::Executor"->create
l!l&&r!l&&!r
24410
MC/DC0%0/2
$self->{"executor"} ||= "Rex::Interface::Executor"->create
$self->{"executor"} "Rex::Interface::Executor"->create
Truth table66%2/3
A ||= B
A= $self->{"executor"}B= "Rex::Interface::Executor"->create
ABresult
1X1
011
000
102 245 ▶ $self->{opts} ||= {};
Condition100%2/2
$self->{"opts"} ||= {}
l!l
32213
MC/DC100%1/1
$self->{"opts"} ||= {}
$self->{"opts"}
Truth table100%2/2
A
A= $self->{"opts"}
Aresult
11
00
103 245 ▶ $self->{args} ||= [];
Condition100%2/2
$self->{"args"} ||= []
l!l
32213
MC/DC100%1/1
$self->{"args"} ||= []
$self->{"args"}
Truth table100%2/2
A
A= $self->{"args"}
Aresult
11
00
104  
105 245 $self->{connection} = undef;
106  
107 # set to true as default
108 245 ▶ if ( !exists $self->{exit_on_connect_fail} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"exit_on_connect_fail"}) 33 212 245
109 33 $self->{exit_on_connect_fail} = 1;
110 }
111  
112 245 return $self;
113 }
114  
115 =head2 connection
116  
117 Returns the current connection object.
118  
119 =cut
120  
121 260 ▶sub connection {
Subroutine connection: called CC=3 SCAR=11.0
Pod documented
122 260 my ($self) = @_;
123 260 ▶ if ( !exists $self->{connection} || !$self->{connection} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"connection"} and $self->{"connection"}) 40 220 260
Condition100%3/3
exists $self->{"connection"} and $self->{"connection"}
!ll&&!rl&&r
391220
MC/DC100%2/2
exists $self->{"connection"} and $self->{"connection"}
exists $self->{"connection"} $self->{"connection"}
Truth table100%3/3
A and B
A= exists $self->{"connection"}B= $self->{"connection"}
ABresult
0X0
100
111
124 $self->{connection} =
125 40 Rex::Interface::Connection->create( $self->get_connection_type );
126 }
127  
128 260 $self->{connection};
129 }
130  
131 7 ▶sub set_connection {
Subroutine set_connection: called CC=1 SCAR=0.0
Pod undocumented
132 7 my ( $self, $conn ) = @_;
133 7 $self->{connection} = $conn;
134 }
135  
136 =head2 executor
137  
138 Returns the current executor object.
139  
140 =cut
141  
142 54 ▶sub executor {
Subroutine executor: called CC=1 SCAR=0.0
Pod documented
143 54 my ($self) = @_;
144 54 $self->{executor}->set_task($self);
145 54 return $self->{executor};
146 }
147  
148 =head2 hidden
149  
150 Returns true if the task is hidden. (Should not be displayed on ,,rex -T''.)
151  
152 =cut
153  
154 60 ▶sub hidden {
Subroutine hidden: called CC=1 SCAR=0.0
Pod documented
155 60 my ($self) = @_;
156 60 return $self->{hidden};
157 }
158  
159 =head2 server
160  
161 Returns the servers on which the task should be executed as an ArrayRef.
162  
163 =cut
164  
165 292 ▶sub server {
Subroutine server: called CC=10 SCAR=26.6
Pod documented
166 292 my ($self) = @_;
167  
168 292 my @server = @{ $self->{server} };
169 292 my @ret = ();
170  
171 292 ▶ if ( ref( $server[-1] ) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $server[-1] eq "HASH") 0 292 292
172 0 Rex::deprecated(
173 undef, "0.40",
174 "Defining extra credentials within the task creation is deprecated.",
175 "Please use set auth => task => 'taskname' instead."
176 );
177  
178 # use extra defined credentials
179 0 my $data = pop(@server);
180 0 $self->set_auth( "user", $data->{'user'} );
181 0 $self->set_auth( "password", $data->{'password'} );
182  
183 0 ▶ if ( exists $data->{"private_key"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"private_key"}) 0 0 0
184 0 $self->set_auth( "private_key", $data->{"private_key"} );
185 0 $self->set_auth( "public_key", $data->{"public_key"} );
186 }
187 }
188  
189 292 ▶ if ( ref( $self->{server} ) eq "ARRAY"
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'server'} eq 'ARRAY' and scalar @{$self->{'server'};} > 0) { } 18 274 292
elsif (ref $self->{'server'} eq 'CODE') { } 0 274 274
Condition66%2/3
ref $self->{"server"} eq "ARRAY" and scalar @{$self->{"server"};} > 0
!ll&&!rl&&r
027418
MC/DC50%1/2
ref $self->{"server"} eq "ARRAY" and scalar @{$self->{"server"};} > 0
ref $self->{"server"} eq "ARRAY" scalar @{$self->{"server"};} > 0
Truth table66%2/3
A and B
A= ref $self->{"server"} eq "ARRAY"B= scalar @{$self->{"server"};} > 0
ABresult
0X0
100
111
190 292 && scalar( @{ $self->{server} } ) > 0 )
191 {
192 18 for my $srv ( @{ $self->{server} } ) {
193 30 ▶ if ( ref($srv) eq "CODE" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $srv eq 'CODE') { } 1 29 30
194 1 push( @ret, &$srv() );
195 }
196 else {
197 29 ▶ if ( ref $srv && $srv->isa("Rex::Group::Entry::Server") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $srv and $srv->isa('Rex::Group::Entry::Server')) { } 28 1 29
Condition66%2/3
ref $srv and $srv->isa("Rex::Group::Entry::Server")
!ll&&!rl&&r
1028
MC/DC50%1/2
ref $srv and $srv->isa("Rex::Group::Entry::Server")
ref $srv $srv->isa("Rex::Group::Entry::Server")
Truth table66%2/3
A and B
A= ref $srvB= $srv->isa("Rex::Group::Entry::Server")
ABresult
0X0
100
111
198 28 push( @ret, $srv->get_servers );
199 }
200 else {
201 1 push( @ret, $srv );
202 }
203 }
204 }
205 }
206 elsif ( ref( $self->{server} ) eq "CODE" ) {
207 0 push( @ret, &{ $self->{server} }() );
208 }
209 else {
210 274 push( @ret, Rex::Group::Entry::Server->new( name => "<local>" ) );
211 }
212  
213 292 return [@ret];
214 }
215  
216 =head2 set_server(@server)
217  
218 With this method you can set new servers on which the task should be executed on.
219  
220 =cut
221  
222 1 ▶sub set_server {
Subroutine set_server: called CC=1 SCAR=0.0
Pod documented
223 1 my ( $self, @server ) = @_;
224 1 $self->{server} = \@server;
225 }
226  
227 =head2 delete_server
228  
229 Delete every server registered to the task.
230  
231 =cut
232  
233 1 ▶sub delete_server {
Subroutine delete_server: called CC=1 SCAR=0.0
Pod documented
234 1 my ($self) = @_;
235 1 delete $self->{current_server};
236 1 delete $self->{server};
237 1 $self->rethink_connection;
238 }
239  
240 =head2 current_server
241  
242 Returns the current server on which the tasks gets executed right now.
243  
244 =cut
245  
246 2 ▶sub current_server {
Subroutine current_server: called CC=2 SCAR=7.1
Pod documented
247 2 my ($self) = @_;
248 return $self->{current_server}
249 2 ▶ || Rex::Group::Entry::Server->new( name => "<local>" );
Condition66%2/3
$self->{'current_server'} || 'Rex::Group::Entry::Server'->new('name', '<local>')
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->{'current_server'} || 'Rex::Group::Entry::Server'->new('name', '<local>')
$self->{'current_server'} 'Rex::Group::Entry::Server'->new('name', '<local>')
Truth table66%2/3
A || B
A= $self->{'current_server'}B= 'Rex::Group::Entry::Server'->new('name', '<local>')
ABresult
1X1
011
000
250 }
251  
252 =head2 desc
253  
254 Returns the description of a task.
255  
256 =cut
257  
258 2 ▶sub desc {
Subroutine desc: called CC=1 SCAR=0.0
Pod documented
259 2 my ($self) = @_;
260 2 return $self->{desc};
261 }
262  
263 =head2 set_desc($description)
264  
265 Set the description of a task.
266  
267 =cut
268  
269 1 ▶sub set_desc {
Subroutine set_desc: called CC=1 SCAR=0.0
Pod documented
270 1 my ( $self, $desc ) = @_;
271 1 $self->{desc} = $desc;
272 }
273  
274 =head2 is_remote
275  
276 Returns true (1) if the task will be executed remotely.
277  
278 =cut
279  
280 142 ▶sub is_remote {
Subroutine is_remote: called CC=5 SCAR=16.1
Pod documented
281 142 my ($self) = @_;
282 142 ▶ if ( exists $self->{current_server} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'current_server'}) { } 118 24 142
283 118 ▶ if ( $self->{current_server} ne '<local>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"current_server"} ne "<local>") 14 104 118
284 14 return 1;
285 }
286 }
287 else {
288 24 ▶ if ( exists $self->{server} && scalar( @{ $self->{server} } ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"server"} and scalar @{$self->{"server"};} > 0) 14 10 24
Condition100%3/3
exists $self->{"server"} and scalar @{$self->{"server"};} > 0
!ll&&!rl&&r
7314
MC/DC100%2/2
exists $self->{"server"} and scalar @{$self->{"server"};} > 0
exists $self->{"server"} scalar @{$self->{"server"};} > 0
Truth table100%3/3
A and B
A= exists $self->{"server"}B= scalar @{$self->{"server"};} > 0
ABresult
0X0
100
111
289 14 return 1;
290 }
291 }
292  
293 114 return 0;
294 }
295  
296 =head2 is_local
297  
298 Returns true (1) if the task gets executed on the local host.
299  
300 =cut
301  
302 5 ▶sub is_local {
Subroutine is_local: called CC=2 SCAR=6.9
Pod documented
303 5 my ($self) = @_;
304 5 ▶ return $self->is_remote() == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_remote == 0 ? : 3 2 5
305 }
306  
307 =head2 is_http
308  
309 Returns true (1) if the task gets executed over http protocol.
310  
311 =cut
312  
313 46 ▶sub is_http {
Subroutine is_http: called CC=2 SCAR=7.1
Pod documented
314 46 my ($self) = @_;
315 return ( $self->{"connection_type"}
316 46 ▶ && lc( $self->{"connection_type"} ) eq "http" );
Condition66%2/3
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'http'
!ll&&!rl&&r
10360
MC/DC0%0/2
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'http'
$self->{'connection_type'} lc $self->{'connection_type'} eq 'http'
Truth table66%2/3
A && B
A= $self->{'connection_type'}B= lc $self->{'connection_type'} eq 'http'
ABresult
0X0
100
111
317 }
318  
319 =head2 is_https
320  
321 Returns true (1) if the task gets executed over https protocol.
322  
323 =cut
324  
325 46 ▶sub is_https {
Subroutine is_https: called CC=2 SCAR=7.1
Pod documented
326 46 my ($self) = @_;
327 return ( $self->{"connection_type"}
328 46 ▶ && lc( $self->{"connection_type"} ) eq "https" );
Condition66%2/3
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'https'
!ll&&!rl&&r
10360
MC/DC0%0/2
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'https'
$self->{'connection_type'} lc $self->{'connection_type'} eq 'https'
Truth table66%2/3
A && B
A= $self->{'connection_type'}B= lc $self->{'connection_type'} eq 'https'
ABresult
0X0
100
111
329 }
330  
331 =head2 is_openssh
332  
333 Returns true (1) if the task gets executed with openssh.
334  
335 =cut
336  
337 10 ▶sub is_openssh {
Subroutine is_openssh: called CC=2 SCAR=7.1
Pod documented
338 10 my ($self) = @_;
339 return ( $self->{"connection_type"}
340 10 ▶ && lc( $self->{"connection_type"} ) eq "openssh" );
Condition66%2/3
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'openssh'
!ll&&!rl&&r
901
MC/DC50%1/2
$self->{'connection_type'} && lc $self->{'connection_type'} eq 'openssh'
$self->{'connection_type'} lc $self->{'connection_type'} eq 'openssh'
Truth table66%2/3
A && B
A= $self->{'connection_type'}B= lc $self->{'connection_type'} eq 'openssh'
ABresult
0X0
100
111
341 }
342  
343 =head2 want_connect
344  
345 Returns true (1) if the task will establish a connection to a remote system.
346  
347 =cut
348  
349 14 ▶sub want_connect {
Subroutine want_connect: called CC=2 SCAR=6.9
Pod documented
350 14 my ($self) = @_;
351 14 ▶ return $self->{no_ssh} == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'no_ssh'} == 0 ? : 7 7 14
352 }
353  
354 =head2 get_connection_type
355  
356 This method tries to guess the right connection type for the task and returns it.
357  
358 Current return values are below:
359  
360 =over 4
361  
362 =item * SSH: connect to the remote server using Net::SSH2
363  
364 =item * OpenSSH: connect to the remote server using Net::OpenSSH
365  
366 =item * Local: runs locally (without any connections)
367  
368 =item * HTTP: uses experimental HTTP connection
369  
370 =item * HTTPS: uses experimental HTTPS connection
371  
372 =item * Fake: populate the connection properties, but do not connect
373  
374 So you can use this type to iterate over a list of remote hosts, but don't let rex build a connection. For example if you want to use Sys::Virt or other modules.
375  
376 =back
377  
378 =cut
379  
380 46 ▶sub get_connection_type {
Subroutine get_connection_type: called CC=9 SCAR=23.4
Pod documented
381 46 my ($self) = @_;
382  
383 46 ▶ if ( $self->is_http ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->is_http) { } 0 46 46
elsif ($self->is_https) { } 0 46 46
elsif ($self->is_remote and $self->is_openssh and $self->want_connect) { } 0 46 46
elsif ($self->is_remote and $self->want_connect) { } 5 41 46
elsif ($self->is_remote) { } 5 36 41
384 0 return "HTTP";
385 }
386 elsif ( $self->is_https ) {
387 0 return "HTTPS";
388 }
389 ▶ elsif ( $self->is_remote && $self->is_openssh && $self->want_connect ) {
Condition83%5/6
$self->is_remote and $self->is_openssh and $self->want_connect
!ll&&!rl&&r
4510
$self->is_remote and $self->is_openssh
!ll&&!rl&&r
3691
MC/DC0%0/3
$self->is_remote and $self->is_openssh and $self->want_connect
$self->is_remote $self->is_openssh $self->want_connect
Truth table75%3/4
A and B and C
A= $self->is_remoteB= $self->is_opensshC= $self->want_connect
ABCresult
0XX0
10X0
1100
1111
390 0 return "OpenSSH";
391 }
392 ▶ elsif ( $self->is_remote && $self->want_connect ) {
Condition100%3/3
$self->is_remote and $self->want_connect
!ll&&!rl&&r
3655
MC/DC100%2/2
$self->is_remote and $self->want_connect
$self->is_remote $self->want_connect
Truth table100%3/3
A and B
A= $self->is_remoteB= $self->want_connect
ABresult
0X0
100
111
393 5 return Rex::Config->get_connection_type();
394 }
395 elsif ( $self->is_remote ) {
396 5 return "Fake";
397 }
398 else {
399 36 return "Local";
400 }
401 }
402  
403 =head2 modify($key, $value)
404  
405 With this method you can modify values of the task.
406  
407 =cut
408  
409 90 ▶sub modify {
Subroutine modify: called CC=2 SCAR=6.9
Pod documented
410 90 my ( $self, $key, $value ) = @_;
411  
412 90 ▶ if ( ref( $self->{$key} ) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key} eq 'ARRAY') { } 87 3 90
413 87 push( @{ $self->{$key} }, $value );
414 }
415 else {
416 3 $self->{$key} = $value;
417 }
418  
419 90 $self->rethink_connection;
420 }
421  
422 =head2 rethink_connection
423  
424 Deletes current connection object.
425  
426 =cut
427  
428 128 ▶sub rethink_connection {
Subroutine rethink_connection: called CC=1 SCAR=0.0
Pod documented
429 128 my ($self) = @_;
430 128 delete $self->{connection};
431 }
432  
433 =head2 user
434  
435 Returns the username the task will use.
436  
437 =cut
438  
439 39 ▶sub user {
Subroutine user: called CC=3 SCAR=12.5
Pod documented
440 39 my ($self) = @_;
441 39 ▶ if ( exists $self->{auth} && $self->{auth}->{user} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"auth"} and $self->{"auth"}{"user"}) 39 0 39
Condition33%1/3
exists $self->{"auth"} and $self->{"auth"}{"user"}
!ll&&!rl&&r
0039
MC/DC0%0/2
exists $self->{"auth"} and $self->{"auth"}{"user"}
exists $self->{"auth"} $self->{"auth"}{"user"}
Truth table33%1/3
A and B
A= exists $self->{"auth"}B= $self->{"auth"}{"user"}
ABresult
0X0
100
111
442 39 return $self->{auth}->{user};
443 }
444 }
445  
446 =head2 set_user($user)
447  
448 Set the username of a task.
449  
450 =cut
451  
452 1 ▶sub set_user {
Subroutine set_user: called CC=1 SCAR=0.0
Pod documented
453 1 my ( $self, $user ) = @_;
454 1 $self->{auth}->{user} = $user;
455 }
456  
457 =head2 password
458  
459 Returns the password that will be used.
460  
461 =cut
462  
463 2 ▶sub password {
Subroutine password: called CC=3 SCAR=12.5
Pod documented
464 2 my ($self) = @_;
465 2 ▶ if ( exists $self->{auth} && $self->{auth}->{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"auth"} and $self->{"auth"}{"password"}) 2 0 2
Condition33%1/3
exists $self->{"auth"} and $self->{"auth"}{"password"}
!ll&&!rl&&r
002
MC/DC0%0/2
exists $self->{"auth"} and $self->{"auth"}{"password"}
exists $self->{"auth"} $self->{"auth"}{"password"}
Truth table33%1/3
A and B
A= exists $self->{"auth"}B= $self->{"auth"}{"password"}
ABresult
0X0
100
111
466 2 return $self->{auth}->{password};
467 }
468 }
469  
470 =head2 set_password($password)
471  
472 Set the password of the task.
473  
474 =cut
475  
476 1 ▶sub set_password {
Subroutine set_password: called CC=1 SCAR=0.0
Pod documented
477 1 my ( $self, $password ) = @_;
478 1 $self->{auth}->{password} = $password;
479 }
480  
481 =head2 name
482  
483 Returns the name of the task.
484  
485 =cut
486  
487 250 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
488 250 my ($self) = @_;
489 250 return $self->{name};
490 }
491  
492 =head2 code
493  
494 Returns the code of the task.
495  
496 =cut
497  
498 54 ▶sub code {
Subroutine code: called CC=1 SCAR=0.0
Pod documented
499 54 my ($self) = @_;
500 54 return $self->{func};
501 }
502  
503 =head2 set_code(\&code_ref)
504  
505 Set the code of the task.
506  
507 =cut
508  
509 1 ▶sub set_code {
Subroutine set_code: called CC=1 SCAR=0.0
Pod documented
510 1 my ( $self, $code ) = @_;
511 1 $self->{func} = $code;
512 }
513  
514 =head2 run_hook($server, $hook)
515  
516 This method is used internally to execute the specified hooks.
517  
518 =cut
519  
520 136 ▶sub run_hook {
Subroutine run_hook: called CC=7 SCAR=19.7
Pod documented
521 136 my ( $self, $server, $hook, @more_args ) = @_;
522 136 my $old_server;
523  
524 136 for my $code ( @{ $self->{$hook} } ) {
525 24 ▶ if ( $hook eq "after" ) { # special case for after hooks
Branch: 1 branch
BranchTrueFalseTotal
if ($hook eq 'after') { } 6 18 24
526 $code->(
527 $$server,
528 6 ▶ ( $self->{"__was_authenticated"} || 0 ),
Condition50%1/2
$self->{'__was_authenticated'} || 0
l!l
60
MC/DC0%0/1
$self->{'__was_authenticated'} || 0
$self->{'__was_authenticated'}
Truth table50%1/2
A
A= $self->{'__was_authenticated'}
Aresult
11
00
529 { $self->get_opts }, @more_args
530 );
531 }
532 else {
533 18 ▶ $old_server = $$server if $server;
Branch: 1 branch
BranchTrueFalseTotal
if $server 18 0 18
534 18 $code->( $$server, $server, { $self->get_opts }, @more_args );
535 18 ▶ if ( $old_server && $old_server ne $$server ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_server and $old_server ne $$server) 2 16 18
Condition66%2/3
$old_server and $old_server ne $$server
!ll&&!rl&&r
0162
MC/DC50%1/2
$old_server and $old_server ne $$server
$old_server $old_server ne $$server
Truth table66%2/3
A and B
A= $old_serverB= $old_server ne $$server
ABresult
0X0
100
111
536 2 $self->{current_server} = $$server;
537 }
538 }
539 }
540 }
541  
542 =head2 set_auth($key, $value)
543  
544 Set the authentication of the task.
545  
546 $task->set_auth("user", "foo");
547 $task->set_auth("password", "bar");
548  
549 =cut
550  
551 4 ▶sub set_auth {
Subroutine set_auth: called CC=2 SCAR=6.9
Pod documented
552 4 my ( $self, $key, $value ) = @_;
553  
554 4 ▶ if ( scalar(@_) > 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 3) { } 2 2 4
555 2 my $_d = shift;
556 2 $self->{auth} = {@_};
557 }
558 else {
559 2 $self->{auth}->{$key} = $value;
560 }
561 }
562  
563 =head2 merge_auth($server)
564  
565 Merges the authentication information from $server into the task.
566 Tasks authentication information have precedence.
567  
568 =cut
569  
570 88 ▶sub merge_auth {
Subroutine merge_auth: called CC=1 SCAR=0.0
Pod documented
571 88 my ( $self, $server ) = @_;
572  
573 # merge auth hashs
574 # task auth as precedence
575 88 my %auth = $server->merge_auth( $self->{auth} );
576  
577 88 return \%auth;
578 }
579  
580 =head2 get_sudo_password
581  
582 Returns the sudo password.
583  
584 =cut
585  
586 0 ▶sub get_sudo_password {
Subroutine get_sudo_password: not called CC=1 SCAR=6.9
Pod documented
587 0 my ($self) = @_;
588  
589 0 my $server = $self->connection->server;
590 0 my %auth = $server->merge_auth( $self->{auth} );
591  
592 0 return $auth{sudo_password};
593 }
594  
595 =head2 parallelism
596  
597 Get the parallelism count of a task.
598  
599 =cut
600  
601 138 ▶sub parallelism {
Subroutine parallelism: called CC=1 SCAR=0.0
Pod documented
602 138 my ($self) = @_;
603 138 return $self->{parallelism};
604 }
605  
606 =head2 set_parallelism($count)
607  
608 Set the parallelism of the task.
609  
610 =cut
611  
612 0 ▶sub set_parallelism {
Subroutine set_parallelism: not called CC=1 SCAR=6.9
Pod documented
613 0 my ( $self, $para ) = @_;
614 0 $self->{parallelism} = $para;
615 }
616  
617 =head2 connect($server)
618  
619 Initiate the connection to $server.
620  
621 =cut
622  
623 37 ▶sub connect {
Subroutine connect: called CC=19 SCAR=38.1
Pod documented
624 37 my ( $self, $server, %override ) = @_;
625  
626 37 ▶ if ( !ref $server ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $server) 1 36 37
627 1 $server = Rex::Group::Entry::Server->new( name => $server );
628 }
629 37 $self->{current_server} = $server;
630  
631 37 $self->run_hook( \$server, "before" );
632  
633 # need to be called, in case of a run_task task call.
634 # see #788
635 37 $self->rethink_connection;
636  
637 37 my $user = $self->user;
638  
639 #print Dumper($self);
640 37 my $auth = $self->merge_auth($server);
641  
642 37 ▶ if ( exists $override{auth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $override{"auth"}) 0 37 37
643 0 $auth = $override{auth};
644 0 $user = $auth->{user};
645 }
646  
647 37 my $rex_int_conf = Rex::Commands::get("rex_internals");
648 37 Rex::Logger::debug( Dumper($rex_int_conf) );
649 37 Rex::Logger::debug("Auth-Information inside Task:");
650 37 for my $key ( keys %{$auth} ) {
651 296 my $data = $auth->{$key};
652 296 ▶ $data = Rex::Logger::masq( "%s", $data ) if $key eq 'password';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "password" 37 259 296
653 296 ▶ $data = Rex::Logger::masq( "%s", $data ) if $key eq 'sudo_password';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "sudo_password" 37 259 296
654 296 ▶ $data ||= "";
Condition100%2/2
$data ||= ""
l!l
149147
MC/DC100%1/1
$data ||= ""
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
655  
656 296 Rex::Logger::debug("$key => [[$data]]");
657 }
658  
659 $auth->{public_key} = resolv_path( $auth->{public_key}, 1 )
660 37 ▶ if ( $auth->{public_key} );
Branch: 1 branch
BranchTrueFalseTotal
if $auth->{"public_key"} 0 37 37
661 $auth->{private_key} = resolv_path( $auth->{private_key}, 1 )
662 37 ▶ if ( $auth->{private_key} );
Branch: 1 branch
BranchTrueFalseTotal
if $auth->{"private_key"} 0 37 37
663  
664 37 my $profiler = Rex::Profiler->new;
665  
666 # task specific auth rules over all
667 37 my %connect_hash = %{$auth};
668 37 $connect_hash{server} = $server;
669  
670 # need to get rid of this
671 37 Rex::push_connection(
672 {
673 conn => $self->connection,
674 ssh => $self->connection->get_connection_object,
675 server => $server,
676 cache => Rex::Interface::Cache->create(),
677 task => [],
678 profiler => $profiler,
679 reporter => Rex::Report->create( Rex::Config->get_report_type ),
680 notify => Rex::Notify->new(),
681 }
682 );
683  
684 37 push @{ Rex::get_current_connection()->{task} }, $self;
685  
686 37 $profiler->start("connect");
687 eval {
688 37 $self->connection->connect(%connect_hash);
689 37 1;
690 37 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->connection->connect(%connect_hash); 1 } } or do { unless (defined "Rex::Config"->get_fallback_auth) { croak($@); } } 37 0 37
691 0 ▶ if ( !defined Rex::Config->get_fallback_auth ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined "Rex::Config"->get_fallback_auth) 0 0 0
692 0 croak $@;
693 }
694 };
695 37 $profiler->end("connect");
696  
697 37 ▶ if ( !$self->connection->is_connected ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->connection->is_connected) { } 0 37 37
elsif (not $self->connection->is_authenticated) { } 0 37 37
698 0 Rex::pop_connection();
699 0 croak("Couldn't connect to $server.");
700 }
701 elsif ( !$self->connection->is_authenticated ) {
702 0 Rex::pop_connection();
703 0 my $message =
704 "Couldn't authenticate against $server. It may be caused by one or more of:\n";
705 0 $message .= " - wrong username, password, key or passphrase\n";
706 0 $message .= " - changed remote host key\n";
707 $message .= " - root is not permitted to login over SSH\n"
708 0 ▶ if ( $connect_hash{user} eq 'root' );
Branch: 1 branch
BranchTrueFalseTotal
if $connect_hash{"user"} eq "root" 0 0 0
709  
710 0 ▶ if ( !exists $override{auth} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $override{"auth"}) 0 0 0
711 0 my $fallback_auth = Rex::Config->get_fallback_auth;
712 0 ▶ if ( ref $fallback_auth eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fallback_auth eq "ARRAY") 0 0 0
713 0 my $ret_eval;
714 0 for my $fallback_a ( @{$fallback_auth} ) {
715 0 $ret_eval = eval { $self->connect( $server, auth => $fallback_a ); };
716 }
717  
718 0 ▶ return $ret_eval if $ret_eval;
Branch: 1 branch
BranchTrueFalseTotal
if $ret_eval 0 0 0
719 }
720 }
721  
722 0 croak($message);
723 }
724 else {
725 37 ▶ Rex::Logger::debug("Successfully authenticated on $server.")
Branch: 1 branch
BranchTrueFalseTotal
if $self->connection->get_connection_type ne "Local" 0 37 37
726 if ( $self->connection->get_connection_type ne "Local" );
727 37 $self->{"__was_authenticated"} = 1;
728 }
729  
730 37 $self->run_hook( \$server, "around" );
731  
732 37 return 1;
733 }
734  
735 =head2 disconnect
736  
737 Disconnect from the current connection.
738  
739 =cut
740  
741 29 ▶sub disconnect {
Subroutine disconnect: called CC=3 SCAR=11.4
Pod documented
742 29 my ( $self, $server ) = @_;
743  
744 29 $self->run_hook( \$server, "around", 1 );
745 29 $self->connection->disconnect;
746  
747 29 my %args = Rex::Args->getopts;
748  
749 29 ▶ if ( defined $args{'d'} && $args{'d'} > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"d"} and $args{"d"} > 2) 0 29 29
Condition33%1/3
defined $args{"d"} and $args{"d"} > 2
!ll&&!rl&&r
2900
MC/DC0%0/2
defined $args{"d"} and $args{"d"} > 2
defined $args{"d"} $args{"d"} > 2
Truth table33%1/3
A and B
A= defined $args{"d"}B= $args{"d"} > 2
ABresult
0X0
100
111
750 0 Rex::Commands::profiler()->report;
751 }
752  
753 29 delete $self->{connection};
754  
755 29 pop @{ Rex::get_current_connection()->{task} };
756  
757 # need to get rid of this
758 29 Rex::pop_connection();
759  
760 29 $self->run_hook( \$server, "after" );
761 }
762  
763 =head2 get_data
764  
765 Dump task data.
766  
767 =cut
768  
769 33 ▶sub get_data {
Subroutine get_data: called CC=1 SCAR=0.0
Pod documented
770 33 my ($self) = @_;
771  
772 return {
773 func => $self->{func},
774 server => $self->{server},
775 desc => $self->{desc},
776 no_ssh => $self->{no_ssh},
777 hidden => $self->{hidden},
778 auth => $self->{auth},
779 before => $self->{before},
780 after => $self->{after},
781 around => $self->{around},
782 name => $self->{name},
783 executor => $self->{executor},
784 connection_type => $self->{connection_type},
785 opts => $self->{opts},
786 args => $self->{args},
787 33 };
788 }
789  
790 =head2 run($server, %options)
791  
792 Run the task on C<$server>, with C<%options>.
793  
794 =cut
795  
796 54 ▶sub run {
Subroutine run: called CC=21 SCAR=32.3
Pod documented
797 54 ▶ return pre_40_run(@_) unless ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] 0 54 54
798  
799 54 my ( $self, $server, %options ) = @_;
800  
801 54 ▶ $options{opts} ||= { $self->get_opts };
Condition50%1/2
$options{"opts"} ||= {$self->get_opts}
l!l
054
MC/DC0%0/1
$options{"opts"} ||= {$self->get_opts}
$options{"opts"}
Truth table50%1/2
A
A= $options{"opts"}
Aresult
11
00
802 54 ▶ $options{args} ||= [ $self->get_args ];
Condition100%2/2
$options{"args"} ||= [$self->get_args]
l!l
648
MC/DC100%1/1
$options{"args"} ||= [$self->get_args]
$options{"args"}
Truth table100%2/2
A
A= $options{"args"}
Aresult
11
00
803 54 ▶ $options{params} ||= $options{opts};
Condition66%2/3
$options{"params"} ||= $options{"opts"}
l!l&&r!l&&!r
21330
MC/DC0%0/2
$options{"params"} ||= $options{"opts"}
$options{"params"} $options{"opts"}
Truth table66%2/3
A ||= B
A= $options{"params"}B= $options{"opts"}
ABresult
1X1
011
000
804  
805 54 ▶ if ( !ref $server ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $server) 22 32 54
806 22 $server = Rex::Group::Entry::Server->new( name => $server );
807 }
808  
809 54 ▶ if ( !$_[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[1]) 0 54 54
810  
811 # run is called without any server.
812 # so just connect to any servers.
813 0 return Rex::TaskList->create()->run( $self, %options );
814 }
815  
816 # this is a method call
817 # so run the task
818  
819 # TODO: refactor complete task calling
820 # direct call with function and normal task call
821  
822 54 my ( $in_transaction, $start_time );
823  
824 54 $start_time = time;
825  
826 54 ▶ if ( $server ne "<func>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server ne '<func>') { } 36 18 54
827  
828 # this is _not_ a task call via function syntax.
829  
830 36 $in_transaction = $options{in_transaction};
831  
832 36 eval { $self->connect($server) };
833 36 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 36 36
834 0 my $error = $@;
835 0 $self->{"__was_authenticated"} = 0;
836 0 $self->run_hook( \$server, "after" );
837 0 die $error;
838 }
839  
840 36 ▶ if ( Rex::Args->is_opt("c") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Rex::Args"->is_opt("c")) 0 36 36
841  
842 # get and cache all os info
843 0 ▶ if ( !Rex::get_cache()->load() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Rex::get_cache()->load) 0 0 0
844 0 Rex::Logger::debug("No cache found, need to collect new data.");
845 0 $server->gather_information;
846 }
847 }
848  
849 36 ▶ if ( !$server->test_perl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($server->test_perl) 0 36 36
850 0 Rex::Logger::info(
851 "There is no perl interpreter found on this system. "
852 . "Some commands may not work. Sudo won't work.",
853 "warn"
854 );
855 0 sleep 3;
856 }
857  
858 }
859 else {
860 # we need to push the connection information of the last task onto this task object
861 # if we don't do this, the task doesn't have any information of the current connection when called like a function.
862 # See: #1091
863 $self->set_connection(
864 Rex::get_current_connection()->{task}->[-1]->connection )
865 18 ▶ if Rex::get_current_connection()->{task}->[-1];
Branch: 1 branch
BranchTrueFalseTotal
if Rex::get_current_connection()->{"task"}[-1] 7 11 18
866 18 push @{ Rex::get_current_connection()->{task} }, $self;
867 }
868  
869 # execute code
870 54 my @ret;
871 54 my $wantarray = wantarray;
872  
873 eval {
874 40 $self->set_opts( %{ $options{params} } )
875 54 ▶ if ref $options{params} eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $options{"params"} eq "HASH" 40 14 54
876 54 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 1 53 54
877 1 @ret = $self->executor->exec( $options{params}, $options{args} );
878 }
879 else {
880 53 $ret[0] = $self->executor->exec( $options{params}, $options{args} );
881 }
882 47 my $notify = Rex::get_current_connection()->{notify};
883 47 $notify->run_postponed();
884 54 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->set_opts(%{$options{"params"};}) if ref $options{"params"} eq "HASH"; if ($wantarray) { @ret = $self->executor->exec($options{"params"}, $options{"args"}); } else { $ret[0] = $self->executor->exec($options{"params"}, $options{"args"}); } ; my $notify = Rex::get_current_connection()->{"notify"}; $notify->run_postponed } } or do { if ($@) { my $error = $@; Rex::get_current_connection()->{"reporter"}->report_resource_failed("message", $error); Rex::get_current_connection()->{"reporter"}->report_task_execution("failed", 1, "start_time", $start_time, "end_time", &Rex::Task::time(), "message", $error); Rex::get_current_connection()->{"reporter"}->write_report; pop @{Rex::get_current_connection()->{"task"};}; die $error; } } 0 54 54
885 54 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 47 54
886 7 my $error = $@;
887  
888 Rex::get_current_connection()->{reporter}
889 7 ->report_resource_failed( message => $error );
890  
891 Rex::get_current_connection()->{reporter}->report_task_execution(
892 7 failed => 1,
893 start_time => $start_time,
894 end_time => time,
895 message => $error,
896 );
897  
898 7 Rex::get_current_connection()->{reporter}->write_report();
899  
900 7 pop @{ Rex::get_current_connection()->{task} };
901 7 die($error);
902 }
903 };
904  
905 47 ▶ if ( $server ne "<func>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server ne '<func>') { } 29 18 47
906 29 ▶ if ( Rex::Args->is_opt("c") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Rex::Args"->is_opt("c")) 0 29 29
907  
908 # get and cache all os info
909 0 Rex::get_cache()->save();
910 }
911  
912 Rex::get_current_connection()->{reporter}->report_task_execution(
913 29 failed => 0,
914 start_time => $start_time,
915 end_time => time,
916 );
917  
918 29 Rex::get_current_connection()->{reporter}->write_report();
919  
920 29 ▶ if ($in_transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_transaction) { } 1 28 29
921 1 $self->run_hook( \$server, "around", 1 );
922 1 $self->run_hook( \$server, "after" );
923 }
924 else {
925 28 $self->disconnect($server);
926 }
927 }
928 else {
929 18 pop @{ Rex::get_current_connection()->{task} };
930 }
931  
932 47 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 1 46 47
933 1 return @ret;
934 }
935 else {
936 46 return $ret[0];
937 }
938 }
939  
940 0 ▶sub pre_40_run {
Subroutine pre_40_run: not called CC=2 SCAR=17.9
Pod undocumented
941 0 my ( $class, $task_name, $server_overwrite, $params ) = @_;
942  
943 # static calls to this method are deprecated
944 0 Rex::deprecated( "Rex::Task->run()", "0.40" );
945  
946 0 my $tasklist = Rex::TaskList->create;
947 0 my $task = $tasklist->get_task($task_name);
948  
949 0 ▶ $task->set_server($server_overwrite) if $server_overwrite;
Branch: 1 branch
BranchTrueFalseTotal
if $server_overwrite 0 0 0
950 0 $tasklist->run( $task, params => $params );
951 }
952  
953 =head2 modify_task($task, $key => $value)
954  
955 Modify C<$task>, by setting C<$key> to C<$value>.
956  
957 =cut
958  
959 0 ▶sub modify_task {
Subroutine modify_task: not called CC=1 SCAR=6.9
Pod documented
960 0 my $class = shift;
961 0 my $task = shift;
962 0 my $key = shift;
963 0 my $value = shift;
964  
965 0 Rex::TaskList->create()->get_task($task)->modify( $key => $value );
966 }
967  
968 =head2 is_task
969  
970 Returns true(1) if the passed object is a task.
971  
972 =cut
973  
974 0 ▶sub is_task {
Subroutine is_task: not called CC=1 SCAR=6.9
Pod documented
975 0 my ( $class, $task ) = @_;
976 0 return Rex::TaskList->create()->is_task($task);
977 }
978  
979 =head2 get_tasks
980  
981 Returns list of tasks.
982  
983 =cut
984  
985 0 ▶sub get_tasks {
Subroutine get_tasks: not called CC=1 SCAR=6.9
Pod documented
986 0 my ( $class, @tmp ) = @_;
987 0 return Rex::TaskList->create()->get_tasks(@tmp);
988 }
989  
990 =head2 get_desc
991  
992 Returns description of task.
993  
994 =cut
995  
996 0 ▶sub get_desc {
Subroutine get_desc: not called CC=1 SCAR=6.9
Pod documented
997 0 my ( $class, @tmp ) = @_;
998 0 return Rex::TaskList->create()->get_desc(@tmp);
999 }
1000  
1001 =head2 exit_on_connect_fail
1002  
1003 Returns true if rex should exit on connect failure.
1004  
1005 =cut
1006  
1007 0 ▶sub exit_on_connect_fail {
Subroutine exit_on_connect_fail: not called CC=1 SCAR=6.9
Pod documented
1008 0 my ($self) = @_;
1009 0 return $self->{exit_on_connect_fail};
1010 }
1011  
1012 =head2 set_exit_on_connect_fail
1013  
1014 Sets if rex should exit on connect failure.
1015  
1016 =cut
1017  
1018 0 ▶sub set_exit_on_connect_fail {
Subroutine set_exit_on_connect_fail: not called CC=1 SCAR=6.9
Pod documented
1019 0 my ( $self, $exit ) = @_;
1020 0 $self->{exit_on_connect_fail} = $exit;
1021 }
1022  
1023 =head2 get_args
1024  
1025 Returns arguments of task.
1026  
1027 =cut
1028  
1029 65 ▶sub get_args {
Subroutine get_args: called CC=2 SCAR=7.1
Pod documented
1030 65 my ($self) = @_;
1031 65 ▶ @{ $self->{args} || [] };
Condition50%1/2
$self->{'args'} || []
l!l
650
MC/DC0%0/1
$self->{'args'} || []
$self->{'args'}
Truth table50%1/2
A
A= $self->{'args'}
Aresult
11
00
1032 }
1033  
1034 =head2 get_opts
1035  
1036 Returns options of task.
1037  
1038 =cut
1039  
1040 137 ▶sub get_opts {
Subroutine get_opts: called CC=2 SCAR=7.1
Pod documented
1041 137 my ($self) = @_;
1042 137 ▶ %{ $self->{opts} || {} };
Condition50%1/2
$self->{'opts'} || {}
l!l
1370
MC/DC0%0/1
$self->{'opts'} || {}
$self->{'opts'}
Truth table50%1/2
A
A= $self->{'opts'}
Aresult
11
00
1043 }
1044  
1045 =head2 set_args
1046  
1047 Sets arguments for task.
1048  
1049 =cut
1050  
1051 101 ▶sub set_args {
Subroutine set_args: called CC=1 SCAR=0.0
Pod documented
1052 101 my ( $self, @args ) = @_;
1053 101 $self->{args} = \@args;
1054 }
1055  
1056 =head2 set_opt
1057  
1058 Sets an option for task.
1059  
1060 =cut
1061  
1062 6 ▶sub set_opt {
Subroutine set_opt: called CC=1 SCAR=0.0
Pod documented
1063 6 my ( $self, $key, $value ) = @_;
1064 6 $self->{opts}->{$key} = $value;
1065 }
1066  
1067 =head2 set_opts
1068  
1069 Sets options for task.
1070  
1071 =cut
1072  
1073 141 ▶sub set_opts {
Subroutine set_opts: called CC=1 SCAR=0.0
Pod documented
1074 141 my ( $self, %opts ) = @_;
1075 141 $self->{opts} = \%opts;
1076 }
1077  
1078 =head2 clone
1079  
1080 Clones a task.
1081  
1082 =cut
1083  
1084 32 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
1085 32 my $self = shift;
1086 32 return Rex::Task->new( %{ $self->get_data } );
1087 }
1088  
1089 56 1;
« lib/Rex/Box/KVM.pm ↑ Summary lib/Rex/Interface/Connection/HTTPS.pm »