line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nexmo::SMS::MockLWP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Module for the Nexmo SMS API! |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This module mocks POST requests. It exists only for the unit tests! |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
7
|
|
|
7
|
|
128532
|
use LWP::UserAgent; |
|
7
|
|
|
|
|
259763
|
|
|
7
|
|
|
|
|
268
|
|
12
|
7
|
|
|
7
|
|
65
|
use HTTP::Response; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
112
|
|
13
|
7
|
|
|
7
|
|
5481
|
use JSON::PP; |
|
7
|
|
|
|
|
87141
|
|
|
7
|
|
|
|
|
640
|
|
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
7
|
|
60
|
use strict; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
184
|
|
16
|
7
|
|
|
7
|
|
31
|
use warnings; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
234
|
|
17
|
|
|
|
|
|
|
|
18
|
7
|
|
|
7
|
|
29
|
no warnings 'redefine'; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
2189
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = 0.01; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
*LWP::UserAgent::post = sub { |
23
|
5
|
|
|
5
|
|
11
|
my ($object,$url,$params) = @_; |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
6
|
my $json = do{ undef $/; }; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
104
|
|
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
46
|
my $coder = JSON::PP->new->ascii->pretty->allow_nonref; |
28
|
5
|
|
|
|
|
969
|
my $perl = $coder->decode( $json ); |
29
|
5
|
|
|
|
|
167442
|
my $from = $params->{from}; |
30
|
|
|
|
|
|
|
|
31
|
5
|
50
|
|
|
|
44
|
if ( $url =~ /get-balance/ ) { |
32
|
0
|
|
|
|
|
0
|
$from = 'get-balance'; |
33
|
0
|
|
|
|
|
0
|
$url = 'get-balance'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
17
|
my $subhash = $perl->{$url}->{$from}; |
37
|
5
|
|
|
|
|
37
|
my $response = $coder->encode( $subhash ); |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
4365
|
my $http_response = HTTP::Response->new( 200 ); |
40
|
5
|
|
|
|
|
411
|
$http_response->content( $response ); |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
322
|
return $http_response; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
*LWP::UserAgent::get = sub { |
46
|
1
|
|
|
1
|
|
2
|
my ($object,$url,$params) = @_; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
2
|
my $json = do{ undef $/; }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
17
|
|
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
8
|
my $coder = JSON::PP->new->ascii->pretty->allow_nonref; |
51
|
1
|
|
|
|
|
137
|
my $perl = $coder->decode( $json ); |
52
|
1
|
|
|
|
|
31282
|
my $from = $params->{from}; |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
9
|
if ( $url =~ /get-balance/ ) { |
55
|
1
|
|
|
|
|
2
|
$from = 'get-balance'; |
56
|
1
|
|
|
|
|
2
|
$url = 'get-balance'; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
3
|
my $subhash = $perl->{$url}->{$from}; |
60
|
1
|
|
|
|
|
6
|
my $response = $coder->encode( $subhash ); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
163
|
my $http_response = HTTP::Response->new( 200 ); |
63
|
1
|
|
|
|
|
71
|
$http_response->content( $response ); |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
54
|
return $http_response; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__DATA__ |