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