SES.pm

filter: Statementstmt 21.2% 30 / 141 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 31.0% 9 / 29 Podpod 66.6% 10 / 15 totaltotal 18.6% 49 / 263 CC 31 SCAR 38.4
CC
31
Cov
14%
send
182.0
send_mime
30.0
new
12.0
CRAP 46.5
↑ Summary SES/Response.pm »
1 package Net::AWS::SES;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp ('croak');
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Digest::HMAC_SHA1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Net::AWS::SES::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 our $VERSION = '0.04';
12
13 0 ▶sub __timestamp {
Subroutine __timestamp: not called CC=1 SCAR=6.9
14 0 return localtime->datetime;
15 }
16
17 0 ▶sub __signature {
Subroutine __signature: not called CC=2 SCAR=17.9
18 0 my $self = shift;
19 0 my ($date) = @_;
20 0 ▶ unless ($date) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($date) 0 0 0
21 0 croak "signature(): usage error";
22 }
23 0 my $hmac = Digest::HMAC_SHA1->new( $self->secret_key );
24 0 $hmac->add($date);
25 0 return encode_base64( $hmac->digest );
26 }
27 0 ▶sub __user_agent {
Subroutine __user_agent: not called CC=1 SCAR=6.9
28 0 my $self = shift;
29 0 my $ua = LWP::UserAgent->new(
30 agent => sprintf( "%s/%s", __PACKAGE__, $VERSION ),
31 default_headers => $self->__header
32 );
33 0 return $ua;
34 }
35
36 0 ▶sub __header {
Subroutine __header: not called CC=1 SCAR=6.9
37 0 my $self = shift;
38 0 my $h = HTTP::Headers->new;
39 0 $h->date(time);
40 0 $h->header(
41 'Content-type' => 'application/x-www-form-urlencoded',
42 'X-Amzn-Authorization' => sprintf(
43 "AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA1,Signature=%s",
44 $self->access_key, $self->__signature( $h->header('Date') )
45 )
46 );
47 0 return $h;
48 }
49
50 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
51 0 my $class = shift;
52 0 my %data = (
53 access_key => '',
54 secret_key => '',
55 region => 'us-east-1',
56 from => '',
57 __user_agent => undef,
58 __response => undef,
59 @_
60 );
61 0 ▶ unless ( $data{access_key} && $data{secret_key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data{"access_key"} and $data{"secret_key"}) 0 0 0
Condition0%0/3
$data{"access_key"} and $data{"secret_key"}
!ll&&!rl&&r
000
MC/DC0%0/2
$data{"access_key"} and $data{"secret_key"}
$data{"access_key"} $data{"secret_key"}
Truth table0%0/3
A and B
A= $data{"access_key"}B= $data{"secret_key"}
ABresult
0X0
100
111
62 0 croak "new(): usage error";
63 }
64 0 return bless \%data, $class;
65 }
66
67 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=6.9
68 0 my $self = shift;
69 0 $self->{__response} = undef;
70 }
71
72 0 ▶sub response {
Subroutine response: not called CC=1 SCAR=6.9
Pod undocumented
73 0 my $self = shift;
74 0 return $self->{__response};
75 }
76
77 0 ▶sub access_key {
Subroutine access_key: not called CC=2 SCAR=17.9
Pod undocumented
78 0 my $self = shift;
79 0 my ($key) = @_;
80 0 ▶ return $self->{access_key} unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
81 0 return $self->{access_key} = $key;
82 }
83
84 0 ▶sub secret_key {
Subroutine secret_key: not called CC=2 SCAR=17.9
Pod documented
85 0 my $self = shift;
86 0 my ($key) = @_;
87 0 ▶ return $self->{secret_key} unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
88 0 return $self->{secret_key} = $key;
89 }
90
91 0 ▶sub region {
Subroutine region: not called CC=2 SCAR=17.9
Pod documented
92 0 my $self = shift;
93 0 my ($key) = @_;
94 0 ▶ return $self->{region} unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
95 0 return $self->{region} = $key;
96 }
97
98 0 ▶sub call {
Subroutine call: not called CC=2 SCAR=17.9
Pod undocumented
99 0 my $self = shift;
100 0 my ( $action, $args, $responseClass ) = @_;
101 0 ▶ unless ($action) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action) 0 0 0
102 0 croak "call(): usage error";
103 }
104 0 $args->{AWSAccessKeyId} = $self->access_key;
105 0 $args->{Action} = $action;
106 0 $args->{Timestamp} = $self->__timestamp;
107 0 my $ua = $self->__user_agent;
108 0 my $response =
109 $ua->post( "https://email." . $self->region . ".amazonaws.com",
110 $args );
111 0 return Net::AWS::SES::Response->new( $response, $action );
112 }
113
114 0 ▶sub send {
Subroutine send: not called CC=13 SCAR=52.0
Pod documented
115 0 my $self = shift;
116 0 ▶ return $self->send_mime(@_) if ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
117 0 my (%args) = @_;
118 0 ▶ unless ( ref( $args{To} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"To"}) 0 0 0
119 0 $args{To} = [ $args{To} ];
120 }
121 0 ▶ my $from = $args{From} || $self->{from};
Condition0%0/3
$args{'From'} || $self->{'from'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'From'} || $self->{'from'}
$args{'From'} $self->{'from'}
Truth table0%0/3
A || B
A= $args{'From'}B= $self->{'from'}
ABresult
1X1
011
000
122 0 ▶ unless ($from) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from) 0 0 0
123 0 croak "send(): usage error";
124 }
125 0 ▶ unless ( $from && ( $args{Body} || $args{Body_html} ) && $args{To} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from and $args{"Body"} || $args{"Body_html"} and $args{"To"}) 0 0 0
Condition0%0/9
$from and $args{"Body"} || $args{"Body_html"} and $args{"To"}
!ll&&!rl&&r
000
$from and $args{"Body"} || $args{"Body_html"}
!ll&&!rl&&r
000
$args{"Body"} or $args{"Body_html"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$from and $args{"Body"} || $args{"Body_html"} and $args{"To"}
$from $args{"Body"} $args{"Body_html"} $args{"To"}
Truth table0%0/6
A and B or C and D
A= $fromB= $args{"Body"}C= $args{"Body_html"}D= $args{"To"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
126 0 croak "Usage Error";
127 }
128 my %call_args = (
129 'Message.Subject.Data' => $args{Subject},
130 0 'Message.Subject.Charset' => 'UTF-8',
131 'Source' => $from
132 );
133 0 ▶ if ( $args{Body} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Body"}) 0 0 0
134 0 $call_args{'Message.Body.Text.Data'} = $args{Body};
135 0 $call_args{'Message.Body.Text.Charset'} = 'UTF-8',;
136 }
137 0 ▶ if ( $args{Body_html} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"Body_html"}) 0 0 0
138 0 $call_args{'Message.Body.Html.Data'} = $args{Body_html};
139 0 $call_args{'Message.Body.Html.Charset'} = 'UTF-8';
140 }
141 0 ▶ if ( $args{ReturnPath} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"ReturnPath"}) 0 0 0
142 0 $call_args{'ReturnPath'} = $args{ReturnPath};
143 }
144 0 ▶ for ( my $i = 0 ; $i < @{ $args{To} } ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$args{"To"};}) 0 0 0
145 0 my $email = $args{To}->[$i];
146 0 $call_args{ sprintf( 'Destination.ToAddresses.member.%d', $i + 1 ) } =
147 $email;
148 }
149 0 my $r = $self->call( 'SendEmail', \%call_args );
150 } ## end sub send
151
152 0 ▶sub verify_email {
Subroutine verify_email: not called CC=2 SCAR=17.9
Pod documented
153 0 my ( $self, $email ) = @_;
154 0 ▶ unless ($email) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email) 0 0 0
155 0 croak "verify_email(): usage error";
156 }
157 0 return $self->call( 'VerifyEmailIdentity', { EmailAddress => $email } );
158 }
159 1 *delete_domain = \&delete_identity;
160 1 *delete_email = \&delete_identity;
161
162 0 ▶sub delete_identity {
Subroutine delete_identity: not called CC=2 SCAR=17.9
Pod undocumented
163 0 my ( $self, $identity ) = @_;
164 0 ▶ unless ($identity) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($identity) 0 0 0
165 0 croak "delete_identity(): usage error";
166 }
167 0 return $self->call( 'DeleteIdentity', { Identity => $identity } );
168 }
169
170 0 ▶sub list_emails {
Subroutine list_emails: not called CC=3 SCAR=24.8
Pod documented
171 0 my $self = shift;
172 0 my %args = @_;
173 0 my %call_args = ( IdentityType => 'EmailAddress' );
174 0 ▶ if ( $args{limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"limit"}) 0 0 0
175 0 $call_args{MaxItems} = $args{limit};
176 }
177 0 ▶ if ( $args{offset} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"offset"}) 0 0 0
178 0 $call_args{NextToken} = $args{offset};
179 }
180 0 my $r = $self->call( 'ListIdentities', \%call_args );
181 }
182
183 0 ▶sub list_domains {
Subroutine list_domains: not called CC=3 SCAR=24.8
Pod documented
184 0 my $self = shift;
185 0 my %args = @_;
186 0 my %call_args = ( IdentityType => 'Domain' );
187 0 ▶ if ( $args{limit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"limit"}) 0 0 0
188 0 $call_args{MaxItems} = $args{limit};
189 }
190 0 ▶ if ( $args{offset} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"offset"}) 0 0 0
191 0 $call_args{NextToken} = $args{offset};
192 }
193 0 my $r = $self->call( 'ListIdentities', \%call_args );
194 }
195
196 0 ▶sub get_quota {
Subroutine get_quota: not called CC=1 SCAR=6.9
Pod documented
197 0 my $self = shift;
198 0 return $self->call('GetSendQuota');
199 }
200
201 0 ▶sub get_statistics {
Subroutine get_statistics: not called CC=1 SCAR=6.9
Pod documented
202 0 my $self = shift;
203 0 return $self->call('GetSendStatistics');
204 }
205
206 0 ▶sub send_mime {
Subroutine send_mime: not called CC=5 SCAR=34.0
Pod undocumented
207 0 my $self = shift;
208 0 ▶ my $msg = $_[0] if ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
209 0 ▶ if ( $msg && ref($msg) && $msg->isa("MIME::Entity") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg and ref $msg and $msg->isa("MIME::Entity")) 0 0 0
Condition0%0/6
$msg and ref $msg and $msg->isa("MIME::Entity")
!ll&&!rl&&r
000
$msg and ref $msg
!ll&&!rl&&r
000
MC/DC0%0/3
$msg and ref $msg and $msg->isa("MIME::Entity")
$msg ref $msg $msg->isa("MIME::Entity")
Truth table0%0/4
A and B and C
A= $msgB= ref $msgC= $msg->isa("MIME::Entity")
ABCresult
0XX0
10X0
1100
1111
210 0 my $r = $self->call( 'SendRawEmail',
211 { 'RawMessage.Data' => encode_base64( $msg->stringify ) } );
212 0 return $r;
213 }
214 }
215
216 0 ▶sub get_dkim_attributes {
Subroutine get_dkim_attributes: not called CC=2 SCAR=17.9
Pod documented
217 0 my $self = shift;
218 0 my @identities = @_;
219 0 my %call_args = ();
220 0 ▶ for ( my $i = 0 ; $i < @identities ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @identities) 0 0 0
221 0 my $id = $identities[$i];
222 0 $call_args{ 'Identities.member.' . ( $i + 1 ) } = $id;
223 }
224 0 return $self->call( 'GetIdentityDkimAttributes', \%call_args );
225 }
226 __END__
↑ Summary SES/Response.pm »