Automation/Alarming.pm

filter: Statementstmt 38.1% 16 / 42 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 24.4% 22 / 90 CC 11 SCAR 34.6
CC
11
Cov
24%
mail
42.0
page
42.0
BEGIN
1.0
CRAP 31.8
« Automation/Purging.pm ↑ Summary Automation.pm »
1 package App::Validation::Automation::Alarming;
2
3 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Mail::Sendmail;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 =head1 NAME
9
10 App::Validation::Automation::Alarming - Role App::Validation::Automation
11
12 Notifies of a potential issue via email and/or text page
13
14 =head1 Attributes
15
16 =cut
17
18 6 requires qw( config log_file_handle );
19
20 6 has 'mail_msg' => (
21 is => 'rw',
22 isa => 'Str',
23 clearer => 'clear_mail_msg',
24 );
25
26 6 has 'page_msg' => (
27 is => 'rw',
28 isa => 'Str',
29 clearer => 'clear_page_msg',
30 );
31
32 =head1 METHODS
33
34 =head2 mail
35
36 Notifies recipients mentioned in config file via email.All parameters can be passed arguments except a few which can be a part of config as they don't change.
37
38 =cut
39
40 0 ▶sub mail {
Subroutine mail: not called CC=6 SCAR=37.4
Pod documented
41 0 my ( %mail, $msg ,$ret);
42 0 my $self = shift;
43 0 $mail{Subject} = shift;
44 0 $mail{Message} = shift;
45 0 ▶ $mail{To} = shift || $self->config->{'COMMON.MAIL_TO'};
Condition0%0/3
shift() || $self->config->{'COMMON.MAIL_TO'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.MAIL_TO'}
shift() $self->config->{'COMMON.MAIL_TO'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.MAIL_TO'}
ABresult
1X1
011
000
46 0 ▶ $mail{From} = shift || $self->config->{'COMMON.FROM'};
Condition0%0/3
shift() || $self->config->{'COMMON.FROM'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.FROM'}
shift() $self->config->{'COMMON.FROM'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.FROM'}
ABresult
1X1
011
000
47 0 ▶ $mail{smtp} = shift || $self->config->{'COMMON.SMTP'};
Condition0%0/3
shift() || $self->config->{'COMMON.SMTP'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.SMTP'}
shift() $self->config->{'COMMON.SMTP'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.SMTP'}
ABresult
1X1
011
000
48
49 0 ▶ $ret = sendmail %mail
Condition0%0/2
%mail || confess("couldn't mail : $Mail::Sendmail::error\n" . Dumper(\%mail))
l!l
00
MC/DC0%0/1
%mail || confess("couldn't mail : $Mail::Sendmail::error\n" . Dumper(\%mail))
%mail
Truth table0%0/2
A
A= %mail
Aresult
11
00
50 || confess "couldn't mail : $Mail::Sendmail::error\n".Dumper(\%mail);
51 0 ▶ if( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
52 0 $msg = "Mail sent with following details:\n".Dumper( \%mail );
53 0 $self->mail_msg( $msg );
54 0 return 1;
55 }
56
57 0 return 0;
58
59 }
60
61 =head2 page
62
63 Notifies recipients mentioned in config file via text page.page is a separate method as text messages should be short and crisp as we get charged for the service.This method can be over-ridden or tweaked to shorten the message.
64
65 =cut
66
67 0 ▶sub page {
Subroutine page: not called CC=6 SCAR=37.4
Pod documented
68 0 my ( %mail, $msg ,$ret);
69 0 my $self = shift;
70 0 $mail{Subject} = shift;
71 0 $mail{Message} = shift;
72 0 ▶ $mail{To} = shift || $self->config->{'COMMON.PAGE_TO'};
Condition0%0/3
shift() || $self->config->{'COMMON.PAGE_TO'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.PAGE_TO'}
shift() $self->config->{'COMMON.PAGE_TO'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.PAGE_TO'}
ABresult
1X1
011
000
73 0 ▶ $mail{From} = shift || $self->config->{'COMMON.FROM'};
Condition0%0/3
shift() || $self->config->{'COMMON.FROM'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.FROM'}
shift() $self->config->{'COMMON.FROM'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.FROM'}
ABresult
1X1
011
000
74 0 ▶ $mail{smtp} = shift || $self->config->{'COMMON.SMTP'};
Condition0%0/3
shift() || $self->config->{'COMMON.SMTP'}
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->config->{'COMMON.SMTP'}
shift() $self->config->{'COMMON.SMTP'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.SMTP'}
ABresult
1X1
011
000
75
76 0 ▶ $ret = sendmail %mail
Condition0%0/2
%mail || confess("couldn't page : $Mail::Sendmail::error\n" . Dumper(\%mail))
l!l
00
MC/DC0%0/1
%mail || confess("couldn't page : $Mail::Sendmail::error\n" . Dumper(\%mail))
%mail
Truth table0%0/2
A
A= %mail
Aresult
11
00
77 || confess "couldn't page : $Mail::Sendmail::error\n".Dumper(\%mail);
78 0 ▶ if( $ret ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret) 0 0 0
79 0 $msg = "Page sent with following details:\n".Dumper( \%mail );
80 0 $self->page_msg( $msg );
81 0 return 1;
82 }
83
84 0 return 0;
85
86 }
87
88
89 6 1;
« Automation/Purging.pm ↑ Summary Automation.pm »