line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Mailboxlayer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
46282
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$Net::Mailboxlayer::VERSION = '0.003'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
266
|
use URI::URL; |
|
1
|
|
|
|
|
7606
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
449
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
33551
|
|
|
1
|
|
|
|
|
37
|
|
10
|
1
|
|
|
1
|
|
7
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
11
|
1
|
|
|
1
|
|
281
|
use JSON::MaybeXS qw(JSON); |
|
1
|
|
|
|
|
4157
|
|
|
1
|
|
|
|
|
46
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
283
|
use Net::Mailboxlayer::Error; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
62
|
|
14
|
1
|
|
|
1
|
|
258
|
use Net::Mailboxlayer::Response; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
737
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
3
|
|
|
3
|
1
|
7141
|
my ($class, %props) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# set defaults |
21
|
3
|
|
|
|
|
14
|
my $self = bless { |
22
|
|
|
|
|
|
|
_endpoint => 'https://apilayer.net/api/check', |
23
|
|
|
|
|
|
|
_smtp => 1, |
24
|
|
|
|
|
|
|
_format => 0, |
25
|
|
|
|
|
|
|
_catch_all => 0, |
26
|
|
|
|
|
|
|
_user_agent_opts => {}, |
27
|
|
|
|
|
|
|
_user_agent => undef, |
28
|
|
|
|
|
|
|
_optional_querystring_parts => [qw(smtp format callback catch_all)], |
29
|
|
|
|
|
|
|
_json => JSON->new, |
30
|
|
|
|
|
|
|
}, $class; |
31
|
|
|
|
|
|
|
|
32
|
3
|
|
|
|
|
28
|
foreach my $prop (qw (endpoint access_key email_address smtp format callback catch_all user_agent_opts user_agent json_decoder)) |
33
|
|
|
|
|
|
|
{ |
34
|
30
|
100
|
|
|
|
47
|
next if not exists $props{$prop}; |
35
|
2
|
|
|
|
|
7
|
$self->$prop($props{$prop}); |
36
|
|
|
|
|
|
|
} |
37
|
3
|
|
|
|
|
8
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub endpoint |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
1
|
0
|
my ($self, $val) = @_; |
43
|
0
|
0
|
|
|
|
0
|
$self->{_endpoint} = $val if defined $val; |
44
|
0
|
|
|
|
|
0
|
return $self->{_endpoint}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub access_key |
48
|
|
|
|
|
|
|
{ |
49
|
3
|
|
|
3
|
1
|
7
|
my ($self, $val) = @_; |
50
|
3
|
100
|
|
|
|
8
|
$self->{_access_key} = $val if defined $val; |
51
|
3
|
|
|
|
|
9
|
return $self->{_access_key}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub email_address |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
1
|
0
|
my ($self, $val) = @_; |
57
|
0
|
0
|
|
|
|
0
|
$self->{_email_address} = $val if defined $val; |
58
|
0
|
|
|
|
|
0
|
return $self->{_email_address}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub smtp |
62
|
|
|
|
|
|
|
{ |
63
|
2
|
|
|
2
|
1
|
7
|
my ($self, $val) = @_; |
64
|
2
|
100
|
|
|
|
5
|
$self->{_smtp} = $val if defined $val; |
65
|
2
|
|
|
|
|
5
|
return $self->{_smtp}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub format |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
71
|
0
|
0
|
|
|
|
|
$self->{_format} = $val if defined $val; |
72
|
0
|
|
|
|
|
|
return $self->{_format}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
sub callback |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
77
|
0
|
0
|
|
|
|
|
$self->{_callback} = $val if defined $val; |
78
|
0
|
|
|
|
|
|
return $self->{_callback}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub catch_all |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
84
|
0
|
0
|
|
|
|
|
$self->{_catch_all} = $val if defined $val; |
85
|
0
|
|
|
|
|
|
return $self->{_catch_all}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub user_agent_opts |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
91
|
0
|
0
|
|
|
|
|
$self->{_user_agent_opts} = $val if defined $val; |
92
|
0
|
|
|
|
|
|
return $self->{_user_agent_opts}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub user_agent |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
0
|
|
|
|
if ($val and blessed $val and $val->can('get')) |
|
|
|
0
|
|
|
|
|
100
|
|
|
|
|
|
|
{ |
101
|
0
|
|
|
|
|
|
$self->{_user_agent} = $val; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
0
|
|
|
|
|
if (not $self->{_user_agent}) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
$self->{_user_agent} = LWP::UserAgent->new(%{$self->{_user_agent_opts}}); |
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
|
return $self->{_user_agent}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub json_decoder |
111
|
|
|
|
|
|
|
{ |
112
|
0
|
|
|
0
|
1
|
|
my ($self, $val) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
0
|
|
|
|
if ($val and blessed $val and $val->can('decode')) |
|
|
|
0
|
|
|
|
|
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
|
|
|
$self->{_json} = $val; |
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return $self->{_json}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _build_url |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $url = URI::URL->new($self->endpoint); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my @parts = ( |
128
|
|
|
|
|
|
|
access_key => $self->access_key, |
129
|
|
|
|
|
|
|
email => $self->email_address, |
130
|
|
|
|
|
|
|
); |
131
|
0
|
|
|
|
|
|
foreach my $part (@{$self->{_optional_querystring_parts}}) |
|
0
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
{ |
133
|
0
|
0
|
|
|
|
|
if ($self->$part) |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
push @parts, $part => $self->$part; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$url->query_form(@parts); |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return $url; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub check |
145
|
|
|
|
|
|
|
{ |
146
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
my $url = $self->_build_url; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
my $response = $self->user_agent->get($url); |
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
if ($response->is_error) |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
|
|
|
return Net::Mailboxlayer::Error->new( |
155
|
|
|
|
|
|
|
success => 0, |
156
|
|
|
|
|
|
|
error => { |
157
|
|
|
|
|
|
|
code => $response->code, |
158
|
|
|
|
|
|
|
type => $response->status_line, |
159
|
|
|
|
|
|
|
info => $response->message, |
160
|
|
|
|
|
|
|
}, |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# todo: try catch here in case we have invalid json |
165
|
0
|
|
|
|
|
|
my $data = $self->json_decoder->decode($response->decoded_content); |
166
|
0
|
|
|
|
|
|
$data->{_response} = $response; |
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
0
|
|
|
|
if (exists $data->{success} and not $data->{success}) |
169
|
|
|
|
|
|
|
{ |
170
|
0
|
|
|
|
|
|
return Net::Mailboxlayer::Error->new(%{$data}); |
|
0
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
return Net::Mailboxlayer::Response->new(%{$data}); |
|
0
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |