| 1 | |||||||||||||||||||||||||||||
| 2 | package Schedule::Pluggable::Plugin::DefaultEventHandler; | ||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use FileHandle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use POSIX qw/ strftime /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | has EventsToReport => ( is => 'rw', | |||||||||||||||||||||||||||
| 8 | isa => 'Str', | ||||||||||||||||||||||||||||
| 9 | required => 1, | ||||||||||||||||||||||||||||
| 10 | default => qq/JobStarted,JobFailed,JobSucceeded,JobStderr/, | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | 2 | has ShowTimeStamp => ( is => 'rw', | |||||||||||||||||||||||||||
| 13 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 14 | required => 1, | ||||||||||||||||||||||||||||
| 15 | default => 1 ); | ||||||||||||||||||||||||||||
| 16 | has MessagesTo => ( is => 'rw', | ||||||||||||||||||||||||||||
| 17 | isa => 'Any', | ||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||
| 19 | 1 | ▶ | default => sub { FileHandle->new('>&1') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 2 | ); | |||||||||||||||||||||||||||
| 21 | has ErrorsTo => ( is => 'rw', | ||||||||||||||||||||||||||||
| 22 | isa => 'Any', | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | 1 | ▶ | default => sub { FileHandle->new('>&1') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 9 | ▶ | after event_handler => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=26.1
| |||||||||||||||||||||||||||||
| 29 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 9 | my %params = @_; | |||||||||||||||||||||||||||
| 31 | 9 | ▶ | return if exists $params{JobName} and $params{JobName} =~ m/^MonitorJobs$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i
MC/DC100%2/2
exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i
exists $params{"JobName"}
$params{"JobName"} =~ /^MonitorJobs$/i
Truth table100%3/3
A and B
A= exists $params{"JobName"}B= $params{"JobName"} =~ /^MonitorJobs$/i
| |||||||||||||||||||||||||||||
| 32 | 6 | ▶ | return if $self->EventsToReport =~ m/^none$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 6 | my $event = $params{Event}; | |||||||||||||||||||||||||||
| 34 | 6 | ▶ | return if $self->EventsToReport !~ m!^all$!i and | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/
MC/DC50%1/2
$self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/
$self->EventsToReport =~ /^all$/i
$self->EventsToReport =~ /\b$event\b/
Truth table66%2/3
A or B
A= $self->EventsToReport =~ /^all$/iB= $self->EventsToReport =~ /\b$event\b/
| |||||||||||||||||||||||||||||
| 35 | $self->EventsToReport !~ m!\b$event\b!; | ||||||||||||||||||||||||||||
| 36 | 2 | my %whattoreport = ( | |||||||||||||||||||||||||||
| 37 | JobQueued => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 38 | JobStarted => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 39 | JobDone => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 40 | JobStderr => [qw/ Event JobName Stderr /], | ||||||||||||||||||||||||||||
| 41 | JobStdout => [qw/ Event JobName Stdout /], | ||||||||||||||||||||||||||||
| 42 | JobFailed => [qw/ Event JobName Command ReturnValue Stderr /], | ||||||||||||||||||||||||||||
| 43 | JobSucceeded => [qw/ Event JobName Command /], | ||||||||||||||||||||||||||||
| 44 | MaxJobsReached => [qw/ Event /], | ||||||||||||||||||||||||||||
| 45 | ManagerStart => [qw/ Event /], | ||||||||||||||||||||||||||||
| 46 | ManagerStart => [qw/ Event /], | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | 2 | ▶ | return unless exists $whattoreport{ $params{Event} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | my @mess = (); | |||||||||||||||||||||||||||
| 50 | 2 | ▶ | push(@mess, strftime('%d/%m/%Y %H:%M:%S', localtime(time()))) if $self->ShowTimeStamp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 2 | foreach my $field (@{ $whattoreport{$params{Event}} }) { | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | push(@mess, ref($params{$field}) eq 'ARRAY' ? @{ $params{$field} } : $params{$field}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my $handle = $params{Event} =~ m/(JobStderr|JobFailed)/ ? $self->ErrorsTo | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | : $self->MessagesTo; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if (ref($handle) eq 'FileHandle') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 2 | $handle->print(join(' ',@mess)."\n"); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 0 | $handle->(join(' ',@mess)."\n"); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 2 | }; | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||