Amazon/SES.pm

filter: Statementstmt 51.0% 257 / 503 Branchbran 0.0% 0 / 232 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 84.4% 76 / 90 Podpod n/a totaltotal 39.1% 333 / 850 CC 126 SCAR 54.9
CC
126
Cov
34%
send
1064.4
list_emails
124.0
list_domains
124.0
CRAP 241.5
↑ Summary Amazon/SES/Response.pm »
1 2 ▶use Moops;
Subroutine __ANON__: called CC=1 SCAR=0.0
2
3 # ABSTRACT: Interfaces with AWS's SES service.
4 2
5 2 ▶class Amazon::SES {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=2.5
Subroutine BEGIN: called CC=1 SCAR=2.5
6 2 ▶ use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
7 2 ▶ use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
8 2 ▶ use Carp ('croak');
Subroutine __ANON__: called CC=1 SCAR=0.0
9 2 ▶ use MIME::Base64;
Subroutine __ANON__: called CC=1 SCAR=0.0
10 2 ▶ use Time::Piece;
Subroutine __ANON__: called CC=1 SCAR=0.0
11 2 ▶ use HTTP::Headers;
Subroutine __ANON__: called CC=1 SCAR=0.0
12 2 ▶ use LWP::UserAgent;
Subroutine __ANON__: called CC=1 SCAR=0.0
13 2 ▶ use AWS::Signature4;
Subroutine __ANON__: called CC=1 SCAR=0.0
14 2 ▶ use Amazon::SES::Response;
Subroutine __ANON__: called CC=1 SCAR=0.0
15 2 ▶ use VM::EC2::Security::CredentialCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶ use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use Kavorka qw( multi method );
Subroutine BEGIN: called CC=1 SCAR=0.0
18
19
20
21 0 ▶ has 'ua' => (is => 'ro', default => sub { return LWP::UserAgent->new() } );
Subroutine __ANON__: not called CC=1 SCAR=0.4
22 1 has 'use_iam_role' => ( is => 'ro', default => 0 );
23 1 has 'access_key' => ( is => 'ro' );
24 1 has 'secret_key' => ( is => 'ro' );
25 1 has 'region' => ( is => 'ro', default => 'us-east-1' );
26 1 has 'response' => ( is => 'rw' );
27
28
29 0 ▶ method call(Str $action, HashRef $args? = {}) {
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine call: not called CC=11 SCAR=43.1
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 1 0 0 0
if @_ > 2 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($action) or _failed_check(9, "Str", $action, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 0 0 0
Ref::Util::XS::is_plain_hashref($args) or _failed_check(22, "HashRef", $args, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
30 0 $args->{AWSAccessKeyId} = $self->access_key;
31 0 $args->{Action} = $action;
32
33 0 my $request = POST("https://email." . $self->region . ".amazonaws.com", $args);
34
35 0 ▶ if ($self->{use_iam_role}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"use_iam_role"}) 0 0 0
36 0 my $creds = VM::EC2::Security::CredentialCache->get();
37 0 ▶ defined($creds) || die("Unable to retrieve IAM role credentials");
Branch: 1 branch
BranchTrueFalseTotal
defined $creds or die "Unable to retrieve IAM role credentials" 0 0 0
38 0 $self->{access_key} = $creds->accessKeyId;
39 0 $self->{secret_key} = $creds->secretAccessKey;
40 0 $request->header('x-amz-security-token' => $creds->sessionToken);
41 }
42
43
44 # Add the signature.
45 0 my $signer = AWS::Signature4->new(-access_key => $self->access_key,
46 -secret_key => $self->secret_key);
47 0 $signer->sign($request);
48
49 0 my $response = $self->ua->request($request);
50 0 return Amazon::SES::Response->new(response => $response,
51 action => $action );
52 }
53
54 0 ▶ multi method send(MIME::Entity $message) {
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine send: not called CC=9 SCAR=38.7
Branch: 8 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC2($message) or _failed_check(81, "InstanceOf[\"MIME::Entity\"]", $message, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
55 0 $self->send_mime($message);
56 }
57
58 multi method send(Str :$from,
59 Str :$body?,
60 Str :$body_html?,
61 Str :$to,
62 Str :$subject?,
63 Str :$charset = "UTF-8",
64 Str :$return_path?,
65 0 ▶ ) {
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine BEGIN: called CC=1 SCAR=4.0
Subroutine send: not called CC=43 SCAR=69.7
Branch: 34 branches
BranchTrueFalseTotal
ref $_[0] eq 'Kavorka::Signature::NOBBLE' ? : 0 0 0
@_ ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'from'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"from"}) 0 0 0
Type::Tiny::XS::Str($from) or _failed_check(9, "Str", $from, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'body'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"body"}) 0 0 0
Type::Tiny::XS::Str($body) or _failed_check(9, "Str", $body, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'body_html'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"body_html"}) 0 0 0
Type::Tiny::XS::Str($body_html) or _failed_check(9, "Str", $body_html, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'to'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"to"}) 0 0 0
Type::Tiny::XS::Str($to) or _failed_check(9, "Str", $to, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'subject'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"subject"}) 0 0 0
Type::Tiny::XS::Str($subject) or _failed_check(9, "Str", $subject, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'charset'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
Type::Tiny::XS::Str($charset) or _failed_check(9, "Str", $charset, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'return_path'} ? : 0 0 0
unless ($____nobble_checks) 0 0 0
if (exists $_{"return_path"}) 0 0 0
Type::Tiny::XS::Str($return_path) or _failed_check(9, "Str", $return_path, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
66 0 ▶ $to = [$to] unless ref($to);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $to 0 0 0
67 0 ▶ defined($body) || defined($body_html) || die("No body specified");
Branch: 1 branch
BranchTrueFalseTotal
defined $body or defined $body_html or die "No body specified" 0 0 0
Condition0%0/3
defined $body or defined $body_html
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $body or defined $body_html
defined $body defined $body_html
Truth table0%0/3
A or B
A= defined $bodyB= defined $body_html
ABresult
1X1
011
000
68 0 my %call_args = (
69 'Message.Subject.Data' => $subject,
70 'Message.Subject.Charset' => $charset,
71 'Source' => $from
72 );
73
74 0 ▶ if (defined($body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) 0 0 0
75 0 $call_args{'Message.Body.Text.Data'} = $body;
76 0 $call_args{'Message.Body.Text.Charset'} = $charset;
77 }
78
79
80 0 ▶ if (defined($body_html)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body_html) 0 0 0
81 0 $call_args{'Message.Body.Html.Data'} = $body_html;
82 0 $call_args{'Message.Body.Html.Charset'} = $charset;
83 }
84
85 0 ▶ if (defined($return_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $return_path) 0 0 0
86 0 $call_args{'ReturnPath'} = $return_path;
87 }
88 0 my $i = 1;
89 map {
90 0 $call_args{'Destination.ToAddresses.member.' . $i++} = $_;
91 } @$to;
92
93 0 $self->call( 'SendEmail', \%call_args );
94 }
95
96
97 0 ▶ method verify_email(Str $email) {
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine verify_email: not called CC=6 SCAR=29.2
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($email) or _failed_check(9, "Str", $email, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
98 0 return $self->call( 'VerifyEmailIdentity', { EmailAddress => $email } );
99 }
100
101 0 ▶ method delete_domain(Str $identity) {
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine delete_domain: not called CC=6 SCAR=29.2
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($identity) or _failed_check(9, "Str", $identity, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
102 0 return $self->call( 'DeleteIdentity', { Identity => $identity } );
103 }
104
105 0 ▶ method delete_email(Str $identity) {
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine delete_email: not called CC=6 SCAR=29.2
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($identity) or _failed_check(9, "Str", $identity, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
106 0 return $self->call( 'DeleteIdentity', { Identity => $identity } );
107 }
108
109 0 ▶ method delete_identity(Str $identity) {
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine delete_identity: not called CC=6 SCAR=29.2
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($identity) or _failed_check(9, "Str", $identity, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
110 0 return $self->call( 'DeleteIdentity', { Identity => $identity } );
111 }
112
113
114 method list_emails(Int :$limit?,
115 0 ▶ Int :$offset?) {
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine list_emails: not called CC=16 SCAR=48.2
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'limit'} ? : 0 0 0
if (exists $_{"limit"}) 0 0 0
Type::Tiny::XS::Int($limit) or _failed_check(13, "Int", $limit, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'offset'} ? : 0 0 0
if (exists $_{"offset"}) 0 0 0
Type::Tiny::XS::Int($offset) or _failed_check(13, "Int", $offset, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
116 0 my %call_args = ( IdentityType => 'EmailAddress' );
117
118 0 ▶ defined($limit) && ($call_args{MaxItems} = $limit);
Branch: 1 branch
BranchTrueFalseTotal
defined $limit and $call_args{"MaxItems"} = $limit 0 0 0
119 0 ▶ defined($offset) && ($call_args{NextToken} = $offset);
Branch: 1 branch
BranchTrueFalseTotal
defined $offset and $call_args{"NextToken"} = $offset 0 0 0
120 0 my $r = $self->call( 'ListIdentities', \%call_args );
121 }
122
123
124 method list_domains(Int :$limit?,
125 0 ▶ Int :$offset?) {
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine BEGIN: called CC=1 SCAR=3.2
Subroutine list_domains: not called CC=16 SCAR=48.2
Branch: 11 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if ($#_ == 0 and ref $_[0] eq 'HASH') { } 0 0 0
if ($slice_length % 2 != 0) 0 0 0
if ($i <= $#_) 0 0 0
$OK{$_} or Carp::croak("Unknown named parameter: $_") 0 0 0
exists $_{'limit'} ? : 0 0 0
if (exists $_{"limit"}) 0 0 0
Type::Tiny::XS::Int($limit) or _failed_check(13, "Int", $limit, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
exists $_{'offset'} ? : 0 0 0
if (exists $_{"offset"}) 0 0 0
Type::Tiny::XS::Int($offset) or _failed_check(13, "Int", $offset, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/3
$#_ == 0 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$#_ == 0 and ref $_[0] eq "HASH"
$#_ == 0 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= $#_ == 0B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
126 0 my %call_args = ( IdentityType => 'Domain' );
127
128 0 ▶ defined($limit) && ($call_args{MaxItems} = $limit);
Branch: 1 branch
BranchTrueFalseTotal
defined $limit and $call_args{"MaxItems"} = $limit 0 0 0
129 0 ▶ defined($offset) && ($call_args{NextToken} = $offset);
Branch: 1 branch
BranchTrueFalseTotal
defined $offset and $call_args{"NextToken"} = $offset 0 0 0
130 0 my $r = $self->call( 'ListIdentities', \%call_args );
131 }
132
133 0 ▶ method get_quota() {
Subroutine BEGIN: called CC=1 SCAR=1.8
Subroutine get_quota: not called CC=3 SCAR=16.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
134 0 return $self->call('GetSendQuota');
135 }
136
137 0 ▶ method get_statistics() {
Subroutine BEGIN: called CC=1 SCAR=1.8
Subroutine get_statistics: not called CC=3 SCAR=16.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
138 0 return $self->call('GetSendStatistics');
139 }
140
141 0 ▶ method send_mime(Str|MIME::Entity $message) {
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine BEGIN: called CC=1 SCAR=2.9
Subroutine send_mime: not called CC=8 SCAR=36.2
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC4($message) or _failed_check(83, "Str|InstanceOf[\"MIME::Entity\"]", $message, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
142 0 my $src = $message;
143 0 ▶ if (ref($message) && $message->isa("MIME::Entity") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $message and $message->isa("MIME::Entity")) 0 0 0
Condition0%0/3
ref $message and $message->isa("MIME::Entity")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $message and $message->isa("MIME::Entity")
ref $message $message->isa("MIME::Entity")
Truth table0%0/3
A and B
A= ref $messageB= $message->isa("MIME::Entity")
ABresult
0X0
100
111
144 0 $src = $message->stringify;
145 }
146
147 0 return $self->call( 'SendRawEmail',
148 { 'RawMessage.Data' => MIME::Base64::encode_base64($src) } );
149 }
150
151 0 ▶ method get_dkim_attributes(Str @identities) {
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine get_dkim_attributes: not called CC=5 SCAR=25.9
Branch: 3 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
$#_ >= 0 ? : 0 0 0
Type::Tiny::XS::Str($_) or _failed_check(9, "Str", $_, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
152 0 my %call_args = ();
153 0 my $i =1 ;
154 map {
155 0 $call_args{'Identities.member.' . $i++} = $_;
156 } @identities;
157 0 return $self->call( 'GetIdentityDkimAttributes', \%call_args );
158 }
159
160 }
161
162 2 1;
163
164 __END__
↑ Summary Amazon/SES/Response.pm »