Alert/Output/Email.pm

filter: Statementstmt 56.2% 27 / 48 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 7 / 14 Podpod 0.0% 0 / 4 totaltotal 47.2% 34 / 72 CC 4 SCAR 13.4
CC
4
Cov
50%
__ANON__
12.0
send
6.0
__ANON__
2.0
CRAP 3.8
« Alert/Output/SNMP.pm ↑ Summary Alert/Input/Dummy.pm »
1 package Transform::Alert::Output::Email;
2  
3 2 our $VERSION = '1.00'; # VERSION
4 # ABSTRACT: Transform alerts to emails
5  
6 2 ▶use sanity;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooX::Types::MooseLike::Base qw(Str ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Email::Sender::Simple 'sendmail';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Email::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Class::Load 'load_class';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 with 'Transform::Alert::Output';
17  
18 has transport_class => (
19 is => 'ro',
20 isa => Str,
21 0 ▶ default => sub { 'SMTP::Persistent' }
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 2 );
23  
24 has _transport => (
25 is => 'rw',
26 isa => ConsumerOf['Email::Sender::Transport'],
27 lazy => 1,
28 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 my $self = shift;
30
31 # load the transport class
32 0 my $class = 'Email::Sender::Transport::'.$self->transport_class;
33 0 load_class $class;
34 0 return $class->new( %{$self->connopts} );
35 },
36 2 predicate => 1,
37 );
38  
39 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
40 0 my ($orig, $self) = (shift, shift);
41 0 my $hash = shift;
42 0 ▶ $hash = { $hash, @_ } unless ref $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash 0 0 0
43  
44 0 ▶ $hash->{transport_class} = delete $hash->{connopts}{transportclass} if exists $hash->{connopts}{transportclass};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$hash{"connopts"}{"transportclass"} 0 0 0
45
46 0 $orig->($self, $hash);
47 2 };
48  
49 0 ▶sub open { shift->_transport; }
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
50 0 ▶sub opened { shift->_has_transport; }
Subroutine opened: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 0 ▶sub send {
Subroutine send: not called CC=2 SCAR=17.9
Pod undocumented
53 0 my ($self, $msg) = @_;
54 0 my $email = Email::Abstract->new($msg); # string ref
55
56 0 ▶ unless (eval { sendmail($email, { transport => $self->_transport }) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { sendmail($email, {"transport", $self->_transport}) } }) 0 0 0
57 0 $self->log->error('Error sending Email message: '.$@);
58 0 return;
59 }
60 0 return 1;
61 }
62  
63 0 ▶sub close { 1; }
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
64  
65 2 42;
66  
67 __END__
« Alert/Output/SNMP.pm ↑ Summary Alert/Input/Dummy.pm »