line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nexmo::SMS::Response; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
57
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
342
|
|
4
|
8
|
|
|
8
|
|
46
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
213
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
5493
|
use Nexmo::SMS::Response::Message; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
417
|
|
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
1761
|
use JSON::PP; |
|
8
|
|
|
|
|
23098
|
|
|
8
|
|
|
|
|
943
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Module that represents a response from Nexmo SMS API! |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# create getter/setter |
16
|
|
|
|
|
|
|
my @attrs = qw(json message_count status); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
for my $attr ( @attrs ) { |
19
|
8
|
|
|
8
|
|
52
|
no strict 'refs'; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
4805
|
|
20
|
|
|
|
|
|
|
*{ __PACKAGE__ . '::' . $attr } = sub { |
21
|
28
|
|
|
28
|
|
58
|
my ($self,$value) = @_; |
22
|
|
|
|
|
|
|
|
23
|
28
|
|
|
|
|
80
|
my $key = '__' . $attr . '__'; |
24
|
28
|
100
|
|
|
|
229
|
$self->{$key} = $value if @_ == 2; |
25
|
28
|
|
|
|
|
165
|
return $self->{$key}; |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
5
|
|
|
5
|
1
|
25
|
my ($class,%param) = @_; |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
20
|
my $self = bless {}, $class; |
34
|
|
|
|
|
|
|
|
35
|
5
|
50
|
|
|
|
27
|
return $self if !$param{json}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# decode json |
38
|
5
|
|
|
|
|
30
|
my $coder = JSON::PP->new->utf8->pretty->allow_nonref; |
39
|
5
|
|
|
|
|
1199
|
my $perl = $coder->decode( $param{json} ); |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
14843
|
$self->message_count( $perl->{'message-count'} ); |
42
|
5
|
|
|
|
|
24
|
$self->status( 0 ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# for each message create a new message object |
45
|
5
|
50
|
|
|
|
14
|
for my $message ( @{ $perl->{messages} || [] } ) { |
|
5
|
|
|
|
|
39
|
|
46
|
6
|
50
|
|
|
|
175
|
$self->_add_message( |
47
|
6
|
|
|
|
|
18
|
Nexmo::SMS::Response::Message->new( %{$message || {}} ) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
67
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub messages { |
56
|
4
|
|
|
4
|
1
|
14
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
|
58
|
4
|
50
|
|
|
|
10
|
return @{ $self->{__messages__} || [] }; |
|
4
|
|
|
|
|
34
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _add_message { |
62
|
6
|
|
|
6
|
|
17
|
my ($self,$message) = @_; |
63
|
|
|
|
|
|
|
|
64
|
6
|
50
|
33
|
|
|
113
|
if ( @_ == 2 and $message->isa( 'Nexmo::SMS::Response::Message' ) ) { |
65
|
6
|
|
|
|
|
13
|
push @{$self->{__messages__}}, $message; |
|
6
|
|
|
|
|
21
|
|
66
|
6
|
100
|
|
|
|
28
|
if ( $message->status != 0 ) { |
67
|
1
|
|
|
|
|
4
|
$self->status(1); |
68
|
1
|
|
|
|
|
4
|
$self->errstr( $message->status_text . ' (' . $message->status_desc . ')' ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub errstr { |
76
|
2
|
|
|
2
|
1
|
10
|
my ($self,$message) = @_; |
77
|
|
|
|
|
|
|
|
78
|
2
|
100
|
|
|
|
8
|
$self->{__errstr__} = $message if @_ == 2; |
79
|
2
|
|
|
|
|
11
|
return $self->{__errstr__}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub is_success { |
84
|
4
|
|
|
4
|
1
|
5137
|
my ($self) = @_; |
85
|
4
|
|
|
|
|
98
|
return !$self->status; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub is_error { |
90
|
9
|
|
|
9
|
1
|
21
|
my ($self) = @_; |
91
|
9
|
|
|
|
|
29
|
return $self->status; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |