| 1 | package Nexmo::SMS::BinaryMessage; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Nexmo::SMS::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Module that respresents a binary message for the Nexmo SMS API! | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | my %attrs = ( | |||||||||||||||||||||||||||
| 16 | body => 'required', | ||||||||||||||||||||||||||||
| 17 | udh => 'required', | ||||||||||||||||||||||||||||
| 18 | type => 'required', | ||||||||||||||||||||||||||||
| 19 | from => 'required', | ||||||||||||||||||||||||||||
| 20 | to => 'required', | ||||||||||||||||||||||||||||
| 21 | server => 'required', | ||||||||||||||||||||||||||||
| 22 | username => 'required', | ||||||||||||||||||||||||||||
| 23 | password => 'required', | ||||||||||||||||||||||||||||
| 24 | status_report_req => 'optional', | ||||||||||||||||||||||||||||
| 25 | client_ref => 'optional', | ||||||||||||||||||||||||||||
| 26 | network_code => 'optional', | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 9 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 30 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 99 | ▶ | *{ __PACKAGE__ . '::' . $attr } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 19 | my ($self,$value) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 19 | my $key = '__' . $attr . '__'; | |||||||||||||||||||||||||||
| 35 | 19 | ▶ | $self->{$key} = $value if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 19 | return $self->{$key}; | |||||||||||||||||||||||||||
| 37 | 99 | }; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 1 | my ($class,%param) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 47 | 11 | ▶ | if ( exists $param{$attr} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 8 | $self->$attr( $param{$attr} ); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | $self->user_agent( | ||||||||||||||||||||||||||||
| 53 | 1 | LWP::UserAgent->new( | |||||||||||||||||||||||||||
| 54 | agent => 'Perl module ' . __PACKAGE__ . ' ' . $VERSION, | ||||||||||||||||||||||||||||
| 55 | ), | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | return $self; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub user_agent { | ||||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 2 | my ($self,$ua) = @_; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | $self->{__ua__} = $ua if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 2 | return $self->{__ua__}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub errstr { | ||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my ($self,$message) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $self->{__errstr__} = $message if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | return $self->{__errstr__}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: called CC=8 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1 | my ($self) = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1 | my %optional; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | $optional{'client-ref'} = $self->client_ref if $self->client_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 1 | ▶ | $optional{'status-report-req'} = $self->status_report_req if $self->status_report_req; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | $optional{'network-code'} = $self->network_code if $self->network_code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | my $response = $self->user_agent->post( | |||||||||||||||||||||||||||
| 87 | $self->server, | ||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | %optional, | ||||||||||||||||||||||||||||
| 90 | username => $self->username, | ||||||||||||||||||||||||||||
| 91 | password => $self->password, | ||||||||||||||||||||||||||||
| 92 | from => $self->from, | ||||||||||||||||||||||||||||
| 93 | to => $self->to, | ||||||||||||||||||||||||||||
| 94 | body => $self->body, | ||||||||||||||||||||||||||||
| 95 | udh => $self->udh, | ||||||||||||||||||||||||||||
| 96 | type => $self->type, | ||||||||||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | ▶ | if ( !$response || !$response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$response and $response->is_success
MC/DC0%0/2
$response and $response->is_success
$response
$response->is_success
Truth table33%1/3
A and B
A= $responseB= $response->is_success
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->errstr("Request was not successful: " . $response->status_line); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | warn $response->content if $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | return; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | my $json = $response->content; | |||||||||||||||||||||||||||
| 107 | 1 | my $response_object = Nexmo::SMS::Response->new( json => $json ); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | if ( $response_object->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $self->errstr( $response_object->errstr ); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | return $response_object; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub check_needed_params { | ||||||||||||||||||||||||||
|
Subroutine
check_needed_params: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 2 | my ($class,%params) = @_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | my @params_not_ok; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 123 | 22 | ▶ | if ( $attrs{$attr} eq 'required' and !$params{$attr} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attrs{$attr} eq "required" and not $params{$attr}
MC/DC100%2/2
$attrs{$attr} eq "required" and not $params{$attr}
$attrs{$attr} eq "required"
not $params{$attr}
Truth table100%3/3
A and not(B)
A= $attrs{$attr} eq "required"B= not $params{$attr}
| |||||||||||||||||||||||||||||
| 124 | 4 | push @params_not_ok, $attr; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 2 | return join ", ", @params_not_ok; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 9 | 1; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||