| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::Notify; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 105 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 105 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 105 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 105 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 105 | my $that = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 105 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 105 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 105 | $self->{__types__} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 105 | $self->{__postponed__} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 105 | $self->{__running_postponed__} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 105 | $self->{__in_notify__} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 105 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | return if ( $self->{__in_notify__} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( exists $self->{__types__}->{ $option{type} }->{ $option{name} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | Rex::Logger::debug( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | "A resource of the type $option{type} and name $option{name}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | . "already exists.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | "warn" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | $self->{__types__}->{ $option{type} }->{ $option{name} } = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | postpone => $option{postpone} || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | options => $option{options}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | cb => $option{cb}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$option{'postpone'} || 0
MC/DC0%0/1
$option{'postpone'} || 0
$option{'postpone'}
Truth table0%0/2
A
A= $option{'postpone'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | Rex::Logger::debug("Try to notify $option{type} -> $option{name}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( exists $self->{__types__}->{ $option{type} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
exists $self->{"__types__"}{$option{"type"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"cb"} and $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"postpone"} == 0
exists $self->{"__types__"}{$option{"type"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"cb"}
exists $self->{"__types__"}{$option{"type"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}
MC/DC0%0/4
exists $self->{"__types__"}{$option{"type"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}} and exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"cb"} and $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"postpone"} == 0
exists $self->{"__types__"}{$option{"type"}}
exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}
exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"cb"}
$self->{"__types__"}{$option{"type"}}{$option{"name"}}{"postpone"} == 0
Truth table0%0/5
A and B and C and D
A= exists $self->{"__types__"}{$option{"type"}}B= exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}C= exists $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"cb"}D= $self->{"__types__"}{$option{"type"}}{$option{"name"}}{"postpone"} == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | && exists $self->{__types__}->{ $option{type} }->{ $option{name} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | && exists $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | && $self->{__types__}->{ $option{type} }->{ $option{name} }->{postpone} == | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | Rex::Logger::debug("Running notify $option{type} -> $option{name}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $cb = $self->{__types__}->{ $option{type} }->{ $option{name} }->{cb}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->{__in_notify__} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $cb->( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{__types__}->{ $option{type} }->{ $option{name} }->{options} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{__in_notify__} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( !$self->{__running_postponed__} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | Rex::Logger::debug( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | "Can't notify $option{type} -> $option{name}. Postponing..."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->_postpone(%option); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | Rex::Logger::info( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | "Can't run postponed notification. " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | . "Resource not found ($option{type} -> $option{name})", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | "warn" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 47 | ▶ | sub run_postponed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_postponed: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 47 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 47 | $self->{__running_postponed__} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 47 | Rex::Logger::debug("Running postponed notifications."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 47 | for my $p ( @{ $self->{__postponed__} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->run( %{$p} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub _postpone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_postpone: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my ( $self, %option ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | push @{ $self->{__postponed__} }, \%option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 105 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||