| 1 | package Nexmo::SMS::MockLWP; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Module for the Nexmo SMS API! | ||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use HTTP::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use JSON::PP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 8 | ▶ | no warnings 'redefine'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 8 | our $VERSION = 0.01; | |||||||||
| 16 | |||||||||||
| 17 | 5 | ▶ | *LWP::UserAgent::post = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 18 | 5 | my ($object,$url,$params) = @_; | |||||||||
| 19 | |||||||||||
| 20 | 5 | my $json = do{ undef $/; <DATA> }; | |||||||||
| 21 | |||||||||||
| 22 | 5 | my $coder = JSON::PP->new->ascii->pretty->allow_nonref; | |||||||||
| 23 | 5 | my $perl = $coder->decode( $json ); | |||||||||
| 24 | 5 | my $from = $params->{from}; | |||||||||
| 25 | |||||||||||
| 26 | 5 | ▶ | if ( $url =~ /get-balance/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 0 | $from = 'get-balance'; | |||||||||
| 28 | 0 | $url = 'get-balance'; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 5 | my $subhash = $perl->{$url}->{$from}; | |||||||||
| 32 | 5 | my $response = $coder->encode( $subhash ); | |||||||||
| 33 | |||||||||||
| 34 | 5 | my $http_response = HTTP::Response->new( 200 ); | |||||||||
| 35 | 5 | $http_response->content( $response ); | |||||||||
| 36 | |||||||||||
| 37 | 5 | return $http_response; | |||||||||
| 38 | 8 | }; | |||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | *LWP::UserAgent::get = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 41 | 1 | my ($object,$url,$params) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 1 | my $json = do{ undef $/; <DATA> }; | |||||||||
| 44 | |||||||||||
| 45 | 1 | my $coder = JSON::PP->new->ascii->pretty->allow_nonref; | |||||||||
| 46 | 1 | my $perl = $coder->decode( $json ); | |||||||||
| 47 | 1 | my $from = $params->{from}; | |||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | if ( $url =~ /get-balance/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 1 | $from = 'get-balance'; | |||||||||
| 51 | 1 | $url = 'get-balance'; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 1 | my $subhash = $perl->{$url}->{$from}; | |||||||||
| 55 | 1 | my $response = $coder->encode( $subhash ); | |||||||||
| 56 | |||||||||||
| 57 | 1 | my $http_response = HTTP::Response->new( 200 ); | |||||||||
| 58 | 1 | $http_response->content( $response ); | |||||||||
| 59 | |||||||||||
| 60 | 1 | return $http_response; | |||||||||
| 61 | 8 | }; | |||||||||
| 62 | |||||||||||
| 63 | 8 | 1; | |||||||||
| 64 | |||||||||||
| 65 | =pod | ||||||||||
| 66 | |||||||||||
| 67 | =encoding UTF-8 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 NAME | ||||||||||
| 70 | |||||||||||
| 71 | Nexmo::SMS::MockLWP - Module for the Nexmo SMS API! | ||||||||||
| 72 | |||||||||||
| 73 | =head1 VERSION | ||||||||||
| 74 | |||||||||||
| 75 | version 0.10 | ||||||||||
| 76 | |||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||
| 78 | |||||||||||
| 79 | This module mocks POST requests. It exists only for the unit tests! | ||||||||||
| 80 | |||||||||||
| 81 | =head1 AUTHOR | ||||||||||
| 82 | |||||||||||
| 83 | Renee Baecker <reneeb@cpan.org> | ||||||||||
| 84 | |||||||||||
| 85 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 86 | |||||||||||
| 87 | This software is Copyright (c) 2016 by Renee Baecker. | ||||||||||
| 88 | |||||||||||
| 89 | This is free software, licensed under: | ||||||||||
| 90 | |||||||||||
| 91 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 92 | |||||||||||
| 93 | =cut | ||||||||||
| 94 | |||||||||||
| 95 | __DATA__ | ||||||||||