| 1 | package Log::Log4perl::Appender::AmazonSES; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use parent qw(Log::Log4perl::Appender); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use List::Util qw(any pairs); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Net::Domain 'hostfqdn'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Net::SMTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | Readonly::Scalar our $TRUE => 1; | |||||||||||||||||||||||||||
| 18 | 1 | Readonly::Scalar our $FALSE => 0; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | Readonly::Scalar our $DEFAULT_HOST => 'email-smtp.us-east-1.amazonaws.com'; | |||||||||||||||||||||||||||
| 21 | 1 | Readonly::Scalar our $DEFAULT_PORT => '465'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = '1.0.1'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ######################################################################## | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | ######################################################################## | ||||||||||||||||||||||||||||
| 28 | 0 | my ( $class, %options ) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $host = delete $options{Host}; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | $host //= delete $options{host}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$host //= delete $options{"host"}
MC/DC0%0/2
$host //= delete $options{"host"}
$host
delete $options{"host"}
Truth table0%0/3
A //= B
A= $hostB= delete $options{"host"}
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $host //= $DEFAULT_HOST; | ||||||||||||||||||||||||||
|
Condition0%0/3
$host //= $Log::Log4perl::Appender::AmazonSES::DEFAULT_HOST
MC/DC0%0/2
$host //= $Log::Log4perl::Appender::AmazonSES::DEFAULT_HOST
$host
$Log::Log4perl::Appender::AmazonSES::DEFAULT_HOST
Truth table0%0/3
A //= B
A= $hostB= $Log::Log4perl::Appender::AmazonSES::DEFAULT_HOST
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $options{Port} //= delete $options{port}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options{"Port"} //= delete $options{"port"}
MC/DC0%0/2
$options{"Port"} //= delete $options{"port"}
$options{"Port"}
delete $options{"port"}
Truth table0%0/3
A //= B
A= $options{"Port"}B= delete $options{"port"}
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $options{Port} //= $DEFAULT_PORT; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options{"Port"} //= $Log::Log4perl::Appender::AmazonSES::DEFAULT_PORT
MC/DC0%0/2
$options{"Port"} //= $Log::Log4perl::Appender::AmazonSES::DEFAULT_PORT
$options{"Port"}
$Log::Log4perl::Appender::AmazonSES::DEFAULT_PORT
Truth table0%0/3
A //= B
A= $options{"Port"}B= $Log::Log4perl::Appender::AmazonSES::DEFAULT_PORT
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $options{Hello} //= delete $options{domain}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options{"Hello"} //= delete $options{"domain"}
MC/DC0%0/2
$options{"Hello"} //= delete $options{"domain"}
$options{"Hello"}
delete $options{"domain"}
Truth table0%0/3
A //= B
A= $options{"Hello"}B= delete $options{"domain"}
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $options{Hello} //= hostfqdn; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options{"Hello"} //= hostfqdn()
MC/DC0%0/2
$options{"Hello"} //= hostfqdn()
$options{"Hello"}
hostfqdn()
Truth table0%0/3
A //= B
A= $options{"Hello"}B= hostfqdn()
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my $from = delete $options{from}; | |||||||||||||||||||||||||||
| 42 | 0 | my $to = delete $options{to}; | |||||||||||||||||||||||||||
| 43 | 0 | my $subject = delete $options{subject}; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | foreach my $p ( pairs( from => $from, to => $to, subject => $subject ) ) { | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | croak $p->[0] . ' is a required parameter' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if !$p->[1]; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $auth = eval { init_auth( delete $options{auth} ); }; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | $options{SSL} = $TRUE; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | $options{Debug} //= delete $options{debug}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$options{"Debug"} //= delete $options{"debug"}
MC/DC0%0/2
$options{"Debug"} //= delete $options{"debug"}
$options{"Debug"}
delete $options{"debug"}
Truth table0%0/3
A //= B
A= $options{"Debug"}B= delete $options{"debug"}
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $self = bless { | |||||||||||||||||||||||||||
| 56 | host => $host, | ||||||||||||||||||||||||||||
| 57 | auth => $auth, | ||||||||||||||||||||||||||||
| 58 | to => $to, | ||||||||||||||||||||||||||||
| 59 | from => $from, | ||||||||||||||||||||||||||||
| 60 | subject => $subject, | ||||||||||||||||||||||||||||
| 61 | options => \%options | ||||||||||||||||||||||||||||
| 62 | }, $class; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $self; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ######################################################################## | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub init_auth { | ||||||||||||||||||||||||||
|
Subroutine
init_auth: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | ######################################################################## | ||||||||||||||||||||||||||||
| 70 | 0 | my ($auth) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( !$auth || !ref $auth ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$auth and ref $auth
MC/DC0%0/2
$auth and ref $auth
$auth
ref $auth
Truth table0%0/3
A and B
A= $authB= ref $auth
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ( $ENV{SES_SMTP_USER} && $ENV{SES_SMTP_PASS} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"SES_SMTP_USER"} and $ENV{"SES_SMTP_PASS"}
MC/DC0%0/2
$ENV{"SES_SMTP_USER"} and $ENV{"SES_SMTP_PASS"}
$ENV{"SES_SMTP_USER"}
$ENV{"SES_SMTP_PASS"}
Truth table0%0/3
A and B
A= $ENV{"SES_SMTP_USER"}B= $ENV{"SES_SMTP_PASS"}
| |||||||||||||||||||||||||||||
| 74 | $auth = { | ||||||||||||||||||||||||||||
| 75 | user => $ENV{SES_SMTP_USER}, | ||||||||||||||||||||||||||||
| 76 | password => $ENV{SES_SMTP_PASS}, | ||||||||||||||||||||||||||||
| 77 | 0 | }; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | croak sprintf 'auth.user and auth.password are required parameters' | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if !$auth->{user} || !$auth->{password}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$auth->{"user"} and $auth->{"password"}
MC/DC0%0/2
$auth->{"user"} and $auth->{"password"}
$auth->{"user"}
$auth->{"password"}
Truth table0%0/3
A and B
A= $auth->{"user"}B= $auth->{"password"}
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | return $auth; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | ######################################################################## | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub log { ## no critic | ||||||||||||||||||||||||||
|
Subroutine
log: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 89 | ######################################################################## | ||||||||||||||||||||||||||||
| 90 | 0 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $smtp = Net::SMTP->new( $self->{host}, %{ $self->{options} }, ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | or croak 'ERROR: unable to create a Net::SMTP instance'; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( any { $self->{options}->{Port} eq $_ } qw(25 587) ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | $smtp->starttls() | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | or croak sprintf 'TLS negotiation with %s failed', $self->{host}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | my $auth = $self->{auth}; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | $smtp->auth( $auth->{user}, $auth->{password} ); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | $smtp->mail( $self->{from} ); | |||||||||||||||||||||||||||
| 105 | 0 | $smtp->to( split /\s*,\s*/xsm, $self->{to} ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | $smtp->data; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | $smtp->datasend( sprintf "From: %s\n", $self->{from} ); | |||||||||||||||||||||||||||
| 110 | 0 | $smtp->datasend( sprintf "To: %s\n", $self->{to} ); | |||||||||||||||||||||||||||
| 111 | 0 | $smtp->datasend( sprintf "Subject: %s\n", $self->{subject} ); | |||||||||||||||||||||||||||
| 112 | 0 | $smtp->datasend( sprintf "\n%s\n", $params{message} ); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $smtp->dataend | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | or carp 'ERROR: could not send message'; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | $smtp->quit; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||