| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::Resource; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 32 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 32 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 32 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 32 | ▶ | use Rex::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 32 | our @CURRENT_RES; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 55 | ▶ | sub is_inside_resource { ref $CURRENT_RES[-1] ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_inside_resource: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 18 | ▶ | sub get_current_resource { $CURRENT_RES[-1] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_current_resource: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 36 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 36 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 36 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 36 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 36 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 36 | $self->{__status__} = "unchanged"; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 36 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub name { (shift)->{name}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 14 | ▶ | sub display_name { (shift)->{display_name}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub type { (shift)->{type}; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=8 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | my ( $self, $name, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | if ( ref $name eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # multiple resource call | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | for my $n ( keys %{$name} ) { | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->call( $n, %{ $name->{$n} } ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | push @CURRENT_RES, $self; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | $self->set_all_parameters(%params); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | $self->{res_name} = $name; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | $self->{res_ensure} = $params{ensure} ||= present; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$params{"ensure"} ||= present()
MC/DC0%0/2
$params{"ensure"} ||= present()
$params{"ensure"}
present()
Truth table33%1/3
A ||= B
A= $params{"ensure"}B= present()
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | Rex::get_current_connection()->{reporter} | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 4 | ->report_resource_start( type => $self->display_name, name => $name ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | my $failed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 59 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | $self->{cb}->( \%params ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | Rex::Logger::info( $@, "error" ); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | Rex::Logger::info( "Resource execution failed: $name", "error" ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $failed = 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ( $self->was_updated ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | Rex::get_current_connection()->{reporter}->report( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | changed => 1, | |||||||||||||||||||||||||||||||||||||||||
| 71 | failed => $failed, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | message => $self->message, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | Rex::get_current_connection()->{reporter}->report( | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | changed => 0, | |||||||||||||||||||||||||||||||||||||||||
| 78 | failed => $failed, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | message => $self->display_name . " not changed.", | ||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ( exists $params{on_change} && $self->was_updated ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params{"on_change"} and $self->was_updated
MC/DC0%0/2
exists $params{"on_change"} and $self->was_updated
exists $params{"on_change"}
$self->was_updated
Truth table33%1/3
A and B
A= exists $params{"on_change"}B= $self->was_updated
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $params{on_change}->( $self->{__status__} ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Rex::get_current_connection()->{reporter} | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ->report_resource_end( type => $self->display_name, name => $name ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | pop @CURRENT_RES; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | sub was_updated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
was_updated: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | if ( $self->changed || $self->created || $self->removed ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->changed or $self->created or $self->removed
$self->changed or $self->created
MC/DC33%1/3
$self->changed or $self->created or $self->removed
$self->changed
$self->created
$self->removed
Truth table50%2/4
A or B or C
A= $self->changedB= $self->createdC= $self->removed
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | sub changed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changed: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my ( $self, $changed ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | if ( defined $changed ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $self->{__status__} = "changed"; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | return ( $self->{__status__} eq "changed" ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | sub created { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
created: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | my ( $self, $created ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | if ( defined $created ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->{__status__} = "created"; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | return ( $self->{__status__} eq "created" ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | ▶ | sub removed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removed: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my ( $self, $removed ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | ▶ | if ( defined $removed ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $self->{__status__} = "removed"; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | ▶ | return ( $self->{__status__} eq "removed" ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | sub message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my ( $self, $message ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | if ( defined $message ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->{message} = $message; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | return ( $self->{message} || ( $self->display_name . " changed." ) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'message'} || $self->display_name . ' changed.'
MC/DC0%0/1
$self->{'message'} || $self->display_name . ' changed.'
$self->{'message'}
Truth table50%1/2
A
A= $self->{'message'}
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | ▶ | sub set_parameter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_parameter: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | my ( $self, $key, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | $self->{__res_parameters__}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | sub set_all_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_all_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | $self->{__res_parameters__} = \%params; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 12 | ▶ | sub get_all_parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 12 | return $self->{__res_parameters__}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 32 | 1; | |||||||||||||||||||||||||||||||||||||||||