| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Rex::Report::Base; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 69 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 69 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 69 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 69 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 69 | ▶ | use Rex::Logger; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 69 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 69 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 105 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 18 | 105 | my $that = shift; | |||||||||||||||||||||||||||||||
| 19 | 105 | ▶ | 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
| |||||||||||||||||||||||||||||||||
| 20 | 105 | my $self = {@_}; | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 105 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 105 | $self->{__reports__} = {}; | |||||||||||||||||||||||||||||||
| 25 | 105 | $self->{__current_resource__} = []; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 105 | return $self; | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 146 | ▶ | sub report { | ||||||||||||||||||||||||||||||
|
Subroutine
report: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 31 | 146 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 146 | ▶ | confess "not inside a resource." if ( !$self->{__current_resource__}->[-1] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 146 | ▶ | if ( $option{changed} && !exists $option{message} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$option{"changed"} and not exists $option{"message"}
MC/DC0%0/2
$option{"changed"} and not exists $option{"message"}
$option{"changed"}
not exists $option{"message"}
Truth table66%2/3
A and not(B)
A= $option{"changed"}B= not exists $option{"message"}
| |||||||||||||||||||||||||||||||||
| 36 | 0 | $option{message} = "Resource updated."; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | ▶ | elsif ( $option{changed} == 0 && !exists $option{message} ) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
$option{"changed"} == 0 and not exists $option{"message"}
MC/DC100%2/2
$option{"changed"} == 0 and not exists $option{"message"}
$option{"changed"} == 0
not exists $option{"message"}
Truth table100%3/3
A and not(B)
A= $option{"changed"} == 0B= not exists $option{"message"}
| |||||||||||||||||||||||||||||||||
| 39 | 27 | $option{message} = "Resource already up-to-date."; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | # update all stacked resources | ||||||||||||||||||||||||||||||||
| 43 | 146 | for my $res ( @{ $self->{__current_resource__} } ) { | |||||||||||||||||||||||||||||||
| 44 | 191 | ▶ | $self->{__reports__}->{$res}->{changed} ||= $option{changed} || 0; | ||||||||||||||||||||||||||||||
|
Condition100%5/5
$self->{"__reports__"}{$res}{"changed"} ||= $option{"changed"} || 0
$option{'changed'} || 0
MC/DC100%2/2
$self->{"__reports__"}{$res}{"changed"} ||= $option{"changed"} || 0
$self->{"__reports__"}{$res}{"changed"}
$option{'changed'}
Truth table100%3/3
A ||= B
A= $self->{"__reports__"}{$res}{"changed"}B= $option{'changed'}
| |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | push | ||||||||||||||||||||||||||||||||
| 48 | @{ $self->{__reports__}->{ $self->{__current_resource__}->[-1] }->{messages} | ||||||||||||||||||||||||||||||||
| 49 | 146 | }, | |||||||||||||||||||||||||||||||
| 50 | 146 | $option{message}; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 36 | ▶ | sub report_task_execution { | ||||||||||||||||||||||||||||||
|
Subroutine
report_task_execution: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 54 | 36 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||
| 55 | 36 | $self->{__reports__}->{task} = \%option; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 138 | ▶ | sub report_resource_start { | ||||||||||||||||||||||||||||||
|
Subroutine
report_resource_start: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 59 | 138 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 138 | push @{ $self->{__current_resource__} }, $self->_gen_res_name(%option); | |||||||||||||||||||||||||||||||
| 62 | 138 | $self->{__reports__}->{ $self->{__current_resource__}->[-1] } = { | |||||||||||||||||||||||||||||||
| 63 | changed => 0, | ||||||||||||||||||||||||||||||||
| 64 | messages => [], | ||||||||||||||||||||||||||||||||
| 65 | start_time => time, | ||||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 138 | ▶ | sub report_resource_end { | ||||||||||||||||||||||||||||||
|
Subroutine
report_resource_end: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 70 | 138 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 138 | ▶ | confess "not inside a resource." if ( !$self->{__current_resource__}->[-1] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | $self->{__reports__}->{ $self->{__current_resource__}->[-1] }->{end_time} = | ||||||||||||||||||||||||||||||||
| 75 | 138 | time; | |||||||||||||||||||||||||||||||
| 76 | 138 | pop @{ $self->{__current_resource__} }; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 7 | ▶ | sub report_resource_failed { | ||||||||||||||||||||||||||||||
|
Subroutine
report_resource_failed: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 80 | 7 | my ( $self, %opt ) = @_; | |||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 7 | ▶ | return if ( !$self->{__current_resource__}->[-1] ); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | # update all stacked resources | ||||||||||||||||||||||||||||||||
| 85 | 0 | for my $res ( @{ $self->{__current_resource__} } ) { | |||||||||||||||||||||||||||||||
| 86 | 0 | $self->{__reports__}->{$res}->{failed} = 1; | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | push @{ $self->{__reports__}->{ $self->{__current_resource__} > [-1] } | ||||||||||||||||||||||||||||||||
| 90 | 0 | ->{messages} }, | |||||||||||||||||||||||||||||||
| 91 | 0 | $opt{message}; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 34 | ▶ | sub write_report { | ||||||||||||||||||||||||||||||
|
Subroutine
write_report: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 95 | 34 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 138 | ▶ | sub _gen_res_name { | ||||||||||||||||||||||||||||||
|
Subroutine
_gen_res_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 99 | 138 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||
| 100 | 138 | return $option{type} . "[" . $option{name} . "]"; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | 69 | 1; | |||||||||||||||||||||||||||||||