SMS/BinaryMessage.pm

filter: Statementstmt 88.7% 55 / 62 Branchbran 59.0% 13 / 22 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 81.0% 90 / 111 CC 16 SCAR 17.6
CC
16
Cov
80%
send
13.2
errstr
6.0
check_needed_params
4.0
CRAP 5.8
« SMS/WAPPushMessage.pm ↑ Summary SMS/TextMessage.pm »
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
BranchTrueFalseTotal
if @_ == 2 8 11 19
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
BranchTrueFalseTotal
if (exists $param{$attr}) 8 3 11
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
BranchTrueFalseTotal
if @_ == 2 1 1 2
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
BranchTrueFalseTotal
if @_ == 2 0 0 0
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
BranchTrueFalseTotal
if $self->client_ref 0 1 1
83 1 ▶ $optional{'status-report-req'} = $self->status_report_req if $self->status_report_req;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status_report_req 0 1 1
84 1 ▶ $optional{'network-code'} = $self->network_code if $self->network_code;
Branch: 1 branch
BranchTrueFalseTotal
if $self->network_code 0 1 1
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
BranchTrueFalseTotal
unless ($response and $response->is_success) 0 1 1
Condition33%1/3
$response and $response->is_success
!ll&&!rl&&r
001
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
ABresult
0X0
100
111
101 0 $self->errstr("Request was not successful: " . $response->status_line);
102 0 ▶ warn $response->content if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
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
BranchTrueFalseTotal
if ($response_object->is_error) 0 1 1
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
BranchTrueFalseTotal
if ($attrs{$attr} eq "required" and not $params{$attr}) 4 18 22
Condition100%3/3
$attrs{$attr} eq "required" and not $params{$attr}
!ll&&!rl&&r
6124
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}
ABresult
0X0
100
111
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__
« SMS/WAPPushMessage.pm ↑ Summary SMS/TextMessage.pm »