lib/Rex/Report/YAML.pm

filter: Statementstmt 92.1% 47 / 51 Branchbran 64.2% 9 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 3 totaltotal 78.1% 68 / 87 CC 10 SCAR 13.1
CC
10
Cov
83%
write_report
7.2
set_report_name
3.6
new
2.1
CRAP 3.7
« lib/Rex/Test/Base/has_cron.pm ↑ Summary lib/Rex/Group.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Report::YAML;
6  
7 2 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.16.1'; # VERSION
11  
12 2 ▶use Rex;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Rex::Report::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 require Rex::Commands;
16 2 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use base qw(Rex::Report::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 our $REPORT_PATH = "./reports";
20  
21 0 ▶my $report_name_generator = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my $str = time();
23 0 return $str;
24 2 };
25  
26 1 ▶sub set_report_name {
Subroutine set_report_name: called CC=3 SCAR=12.7
Pod undocumented
27 1 my ( $class, $code ) = @_;
28  
29 1 ▶ if ( ref $class eq "CODE" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class eq "CODE") 0 1 1
30 0 $code = $class;
31 }
32  
33 1 ▶ if ( ref $code ne "CODE" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code ne "CODE") 0 1 1
34 0 die "Rex::Report::YAML->set_report_name(\$code_ref) wrong arguments.";
35 }
36  
37 1 $report_name_generator = $code;
38 }
39  
40 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
41 1 my $that = shift;
42 1 ▶ my $proto = ref($that) || $that;
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
43 1 my $self = $proto->SUPER::new(@_);
44  
45 1 bless( $self, $proto );
46  
47 1 return $self;
48 }
49  
50 2 ▶sub write_report {
Subroutine write_report: called CC=7 SCAR=19.7
Pod undocumented
51 2 my ($self) = @_;
52  
53 2 ▶ $REPORT_PATH = Rex::Commands::get('report_path') || "reports";
Condition50%1/2
Rex::Commands::get('report_path') || 'reports'
l!l
20
MC/DC0%0/1
Rex::Commands::get('report_path') || 'reports'
Rex::Commands::get('report_path')
Truth table50%1/2
A
A= Rex::Commands::get('report_path')
Aresult
11
00
54  
55 2 ▶ if ( !-d $REPORT_PATH ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $Rex::Report::YAML::REPORT_PATH) 1 1 2
56 1 ▶ mkdir $REPORT_PATH or die( $! . ": $REPORT_PATH" );
Branch: 1 branch
BranchTrueFalseTotal
mkdir $Rex::Report::YAML::REPORT_PATH or die $! . ": $Rex::Report::YAML::REPORT_PATH" 1 0 1
57 }
58  
59 2 my $server_name = Rex::Commands::connection()->server;
60 2 ▶ if ( $server_name eq "<local>" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($server_name eq "<local>") 2 0 2
61 2 $server_name = "_local_";
62 }
63 2 ▶ if ( !-d $REPORT_PATH . "/" . $server_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $Rex::Report::YAML::REPORT_PATH . '/' . $server_name) 1 1 2
64 1 mkdir "$REPORT_PATH/$server_name";
65 }
66 open(
67 2 ▶ my $fh,
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$Rex::Report::YAML::REPORT_PATH/$server_name/" . &$report_name_generator($server_name) . '.yml' or die $! 2 0 2
68 ">",
69 "$REPORT_PATH/$server_name/"
70 . $report_name_generator->($server_name) . ".yml"
71 ) or die($!);
72 2 print $fh Dump( $self->{__reports__} );
73 2 close($fh);
74  
75 2 $self->{__reports__} = {};
76 }
77  
78 # $self->report({
79 # command => $export,
80 # module => "Rex::Commands::$mod",
81 # start_time => $start_time,
82 # end_time => time,
83 # data => [ @_ ],
84 # success => 1,
85 # changed => 1,
86 # message => "",
87  
88 2 1;
« lib/Rex/Test/Base/has_cron.pm ↑ Summary lib/Rex/Group.pm »