Pluggable/Plugin/DefaultEventHandler.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 62.5% 10 / 16 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 85.9% 61 / 71 CC 12 SCAR 22.4
CC
12
Cov
85%
__ANON__
13.6
BEGIN
1.0
BEGIN
1.0
CRAP 9.4
« Pluggable/Run.pm ↑ Summary Pluggable/Plugin/JobsFromXML.pm »
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
BranchTrueFalseTotal
if exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i 3 6 9
Condition100%3/3
exists $params{"JobName"} and $params{"JobName"} =~ /^MonitorJobs$/i
!ll&&!rl&&r
243
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
ABresult
0X0
100
111
32 6 ▶ return if $self->EventsToReport =~ m/^none$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $self->EventsToReport =~ /^none$/i 0 6 6
33 6 my $event = $params{Event};
34 6 ▶ return if $self->EventsToReport !~ m!^all$!i and
Branch: 1 branch
BranchTrueFalseTotal
unless $self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/ 4 2 6
Condition66%2/3
$self->EventsToReport =~ /^all$/i or $self->EventsToReport =~ /\b$event\b/
l!l&&r!l&&!r
024
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/
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless exists $whattoreport{$params{"Event"}} 0 2 2
49 2 my @mess = ();
50 2 ▶ push(@mess, strftime('%d/%m/%Y %H:%M:%S', localtime(time()))) if $self->ShowTimeStamp;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ShowTimeStamp 2 0 2
51 2 foreach my $field (@{ $whattoreport{$params{Event}} }) {
52 0 ▶ push(@mess, ref($params{$field}) eq 'ARRAY' ? @{ $params{$field} } : $params{$field});
Branch: 1 branch
BranchTrueFalseTotal
ref $params{$field} eq 'ARRAY' ? : 0 6 6
53 }
54 2 ▶ my $handle = $params{Event} =~ m/(JobStderr|JobFailed)/ ? $self->ErrorsTo
Branch: 1 branch
BranchTrueFalseTotal
$params{'Event'} =~ /(JobStderr|JobFailed)/ ? : 0 2 2
55 : $self->MessagesTo;
56
57 2 ▶ if (ref($handle) eq 'FileHandle') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handle eq 'FileHandle') { } 2 0 2
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__
« Pluggable/Run.pm ↑ Summary Pluggable/Plugin/JobsFromXML.pm »