| 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
| |||||||||||||||||||||
| 30 | 0 | $code = $class; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | ▶ | if ( ref $code ne "CODE" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||
| 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'
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')
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | ▶ | if ( !-d $REPORT_PATH ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 1 | ▶ | mkdir $REPORT_PATH or die( $! . ": $REPORT_PATH" ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 2 | my $server_name = Rex::Commands::connection()->server; | |||||||||||||||||||
| 60 | 2 | ▶ | if ( $server_name eq "<local>" ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 2 | $server_name = "_local_"; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 2 | ▶ | if ( !-d $REPORT_PATH . "/" . $server_name ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 1 | mkdir "$REPORT_PATH/$server_name"; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | open( | ||||||||||||||||||||
| 67 | 2 | ▶ | my $fh, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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; | |||||||||||||||||||