| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # (c) Jan Gehring | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package Rex::Report::Base; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 67 |  |  | 67 |  | 992 | use v5.12.5; | 
|  | 67 |  |  |  |  | 285 |  | 
| 8 | 67 |  |  | 67 |  | 544 | use warnings; | 
|  | 67 |  |  |  |  | 222 |  | 
|  | 67 |  |  |  |  | 3610 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our $VERSION = '1.14.2.3'; # TRIAL VERSION | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 67 |  |  | 67 |  | 613 | use Data::Dumper; | 
|  | 67 |  |  |  |  | 237 |  | 
|  | 67 |  |  |  |  | 5518 |  | 
| 13 | 67 |  |  | 67 |  | 630 | use Rex::Logger; | 
|  | 67 |  |  |  |  | 230 |  | 
|  | 67 |  |  |  |  | 707 |  | 
| 14 | 67 |  |  | 67 |  | 2851 | use Time::HiRes qw(time); | 
|  | 67 |  |  |  |  | 1773 |  | 
|  | 67 |  |  |  |  | 1438 |  | 
| 15 | 67 |  |  | 67 |  | 12096 | use Carp; | 
|  | 67 |  |  |  |  | 220 |  | 
|  | 67 |  |  |  |  | 52931 |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub new { | 
| 18 | 103 |  |  | 103 | 0 | 311 | my $that  = shift; | 
| 19 | 103 |  | 33 |  |  | 763 | my $proto = ref($that) || $that; | 
| 20 | 103 |  |  |  |  | 351 | my $self  = {@_}; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 103 |  |  |  |  | 299 | bless( $self, $proto ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 103 |  |  |  |  | 731 | $self->{__reports__}          = {}; | 
| 25 | 103 |  |  |  |  | 447 | $self->{__current_resource__} = []; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 103 |  |  |  |  | 466 | return $self; | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | sub report { | 
| 31 | 138 |  |  | 138 | 0 | 2887 | my ( $self, %option ) = @_; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 138 | 50 |  |  |  | 910 | confess "not inside a resource." if ( !$self->{__current_resource__}->[-1] ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 138 | 50 | 66 |  |  | 2799 | if ( $option{changed} && !exists $option{message} ) { | 
|  |  | 100 | 100 |  |  |  |  | 
| 36 | 0 |  |  |  |  | 0 | $option{message} = "Resource updated."; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | elsif ( $option{changed} == 0 && !exists $option{message} ) { | 
| 39 | 27 |  |  |  |  | 329 | $option{message} = "Resource already up-to-date."; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | # update all stacked resources | 
| 43 | 138 |  |  |  |  | 466 | for my $res ( @{ $self->{__current_resource__} } ) { | 
|  | 138 |  |  |  |  | 1238 |  | 
| 44 | 183 |  | 100 |  |  | 2527 | $self->{__reports__}->{$res}->{changed} ||= $option{changed} || 0; | 
|  |  |  | 100 |  |  |  |  | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | push | 
| 48 |  |  |  |  |  |  | @{ $self->{__reports__}->{ $self->{__current_resource__}->[-1] }->{messages} | 
| 49 | 138 |  |  |  |  | 1913 | }, | 
| 50 | 138 |  |  |  |  | 436 | $option{message}; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub report_task_execution { | 
| 54 | 36 |  |  | 36 | 0 | 560 | my ( $self, %option ) = @_; | 
| 55 | 36 |  |  |  |  | 429 | $self->{__reports__}->{task} = \%option; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub report_resource_start { | 
| 59 | 130 |  |  | 130 | 0 | 1891 | my ( $self, %option ) = @_; | 
| 60 |  |  |  |  |  |  |  | 
| 61 | 130 |  |  |  |  | 362 | push @{ $self->{__current_resource__} }, $self->_gen_res_name(%option); | 
|  | 130 |  |  |  |  | 1052 |  | 
| 62 | 130 |  |  |  |  | 4420 | $self->{__reports__}->{ $self->{__current_resource__}->[-1] } = { | 
| 63 |  |  |  |  |  |  | changed    => 0, | 
| 64 |  |  |  |  |  |  | messages   => [], | 
| 65 |  |  |  |  |  |  | start_time => time, | 
| 66 |  |  |  |  |  |  | }; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub report_resource_end { | 
| 70 | 130 |  |  | 130 | 0 | 2253 | my ( $self, %option ) = @_; | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 130 | 50 |  |  |  | 727 | confess "not inside a resource." if ( !$self->{__current_resource__}->[-1] ); | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | $self->{__reports__}->{ $self->{__current_resource__}->[-1] }->{end_time} = | 
| 75 | 130 |  |  |  |  | 1727 | time; | 
| 76 | 130 |  |  |  |  | 466 | pop @{ $self->{__current_resource__} }; | 
|  | 130 |  |  |  |  | 2993 |  | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub report_resource_failed { | 
| 80 | 7 |  |  | 7 | 0 | 89 | my ( $self, %opt ) = @_; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 7 | 50 |  |  |  | 60 | return if ( !$self->{__current_resource__}->[-1] ); | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | # update all stacked resources | 
| 85 | 0 |  |  |  |  | 0 | for my $res ( @{ $self->{__current_resource__} } ) { | 
|  | 0 |  |  |  |  | 0 |  | 
| 86 | 0 |  |  |  |  | 0 | $self->{__reports__}->{$res}->{failed} = 1; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | push @{ $self->{__reports__}->{ $self->{__current_resource__} > [-1] } | 
| 90 | 0 |  |  |  |  | 0 | ->{messages} }, | 
| 91 | 0 |  |  |  |  | 0 | $opt{message}; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub write_report { | 
| 95 | 34 |  |  | 34 | 0 | 189 | my ($self) = @_; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | sub _gen_res_name { | 
| 99 | 130 |  |  | 130 |  | 694 | my ( $self, %option ) = @_; | 
| 100 | 130 |  |  |  |  | 1396 | return $option{type} . "[" . $option{name} . "]"; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | 1; |