lib/Rex/Group/Lookup/Command.pm

filter: Statementstmt 52.9% 18 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 38.9% 23 / 59 CC 7 SCAR 35.0
CC
7
Cov
38%
lookup_command
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 33.1
« blib/lib/Rex/Commands/DB.pm ↑ Summary lib/Rex/Virtualization/LibVirt/list.pm »
1 #
2 # (c) xiahou feng <fanyeren@gmail.com>
3 #
4  
5 =head1 NAME
6  
7 Rex::Group::Lookup::Command - read hostnames from a command.
8  
9 =head1 DESCRIPTION
10  
11 With this module you can define hostgroups out of a command.
12  
13 =head1 SYNOPSIS
14  
15 use Rex::Group::Lookup::Command;
16  
17 group "dbserver" => lookup_command("cat ip.list | grep -v -E '^#'");
18  
19 rex xxxx # dbserver
20  
21 =head1 EXPORTED FUNCTIONS
22  
23 =cut
24  
25 package Rex::Group::Lookup::Command;
26  
27 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 our $VERSION = '1.16.1'; # VERSION
31  
32 1 require Rex::Exporter;
33 1 ▶use Rex -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 @EXPORT = qw(lookup_command);
39  
40 0 ▶sub lookup_command {
Subroutine lookup_command: not called CC=7 SCAR=40.3
Pod undocumented
41 0 my $command = shift;
42  
43 0 my $command_to_exec;
44 my @content;
45  
46 0 ▶ if ( defined $command && $command ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $command and $command) 0 0 0
Condition0%0/3
defined $command and $command
!ll&&!rl&&r
000
MC/DC0%0/2
defined $command and $command
defined $command $command
Truth table0%0/3
A and B
A= defined $commandB= $command
ABresult
0X0
100
111
47 0 $command_to_exec = $command;
48 0 Rex::Logger::info("Command: $command");
49 }
50  
51 0 ▶ unless ( defined $command_to_exec && $command_to_exec ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $command_to_exec and $command_to_exec) 0 0 0
Condition0%0/3
defined $command_to_exec and $command_to_exec
!ll&&!rl&&r
000
MC/DC0%0/2
defined $command_to_exec and $command_to_exec
defined $command_to_exec $command_to_exec
Truth table0%0/3
A and B
A= defined $command_to_execB= $command_to_exec
ABresult
0X0
100
111
52 0 Rex::Logger::info("You must give a valid command.");
53 0 return @content;
54 }
55  
56 0 eval {
57 0 ▶ open( my $command_rt, "-|", "$command_to_exec" ) or die($!);
Branch: 1 branch
BranchTrueFalseTotal
open my $command_rt, "-|", "$command_to_exec" or die $! 0 0 0
58 0 @content = grep { !/^\s*$|^#/ } <$command_rt>;
59 0 close($command_rt);
60  
61 0 chomp @content;
62 };
63 0 ▶ Rex::Logger::info("You must give a valid command.") unless $#content;
Branch: 1 branch
BranchTrueFalseTotal
unless $#content 0 0 0
64 0 return @content;
65 }
66  
67 1 1;
« blib/lib/Rex/Commands/DB.pm ↑ Summary lib/Rex/Virtualization/LibVirt/list.pm »