SMS/WAPPushMessage.pm

filter: Statementstmt 88.8% 56 / 63 Branchbran 58.3% 14 / 24 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 80.7% 92 / 114 CC 17 SCAR 19.0
CC
17
Cov
80%
send
15.2
errstr
6.0
check_needed_params
4.0
CRAP 6.7
↑ Summary SMS/BinaryMessage.pm »
1 package Nexmo::SMS::WAPPushMessage;
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 WAPPush message for the Nexmo SMS API!
12  
13 9 our $VERSION = '0.02';
14  
15 9 my %attrs = (
16 title => 'required',
17 url => '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 validity => 'optional',
28 );
29  
30 9 for my $attr ( keys %attrs ) {
31 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 108 ▶ *{ __PACKAGE__ . '::' . $attr } = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
33 20 my ($self,$value) = @_;
34
35 20 my $key = '__' . $attr . '__';
36 20 ▶ $self->{$key} = $value if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 8 12 20
37 20 return $self->{$key};
38 108 };
39 }
40  
41  
42 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
43 1 my ($class,%param) = @_;
44
45 1 my $self = bless {}, $class;
46
47 1 for my $attr ( keys %attrs ) {
48 12 ▶ if ( exists $param{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{$attr}) 8 4 12
49 8 $self->$attr( $param{$attr} );
50 }
51 }
52
53 $self->user_agent(
54 1 LWP::UserAgent->new(
55 agent => 'Perl module ' . __PACKAGE__ . ' ' . $VERSION,
56 ),
57 );
58
59 1 return $self;
60 }
61  
62  
63 2 ▶sub user_agent {
Subroutine user_agent: called CC=2 SCAR=6.9
Pod documented
64 2 my ($self,$ua) = @_;
65
66 2 ▶ $self->{__ua__} = $ua if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 1 1 2
67 2 return $self->{__ua__};
68 }
69  
70  
71 0 ▶sub errstr {
Subroutine errstr: not called CC=2 SCAR=17.9
Pod documented
72 0 my ($self,$message) = @_;
73
74 0 ▶ $self->{__errstr__} = $message if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 0 0 0
75 0 return $self->{__errstr__};
76 }
77  
78  
79 1 ▶sub send {
Subroutine send: called CC=9 SCAR=27.2
Pod documented
80 1 my ($self) = shift;
81
82 1 my %optional;
83 1 ▶ $optional{'client-ref'} = $self->client_ref if $self->client_ref;
Branch: 1 branch
BranchTrueFalseTotal
if $self->client_ref 0 1 1
84 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
85 1 ▶ $optional{'network-code'} = $self->network_code if $self->network_code;
Branch: 1 branch
BranchTrueFalseTotal
if $self->network_code 0 1 1
86 1 ▶ $optional{'validity'} = $self->validity if $self->validity;
Branch: 1 branch
BranchTrueFalseTotal
if $self->validity 0 1 1
87
88 1 my $response = $self->user_agent->post(
89 $self->server,
90 {
91 %optional,
92 username => $self->username,
93 password => $self->password,
94 from => $self->from,
95 to => $self->to,
96 title => $self->title,
97 url => $self->url,
98 type => $self->type,
99 },
100 );
101
102 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
103 0 $self->errstr("Request was not successful: " . $response->status_line);
104 0 ▶ warn $response->content if $response;
Branch: 1 branch
BranchTrueFalseTotal
if $response 0 0 0
105 0 return;
106 }
107
108 1 my $json = $response->content;
109 1 my $response_object = Nexmo::SMS::Response->new( json => $json );
110
111 1 ▶ if ( $response_object->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response_object->is_error) 0 1 1
112 0 $self->errstr( $response_object->errstr );
113 }
114
115 1 return $response_object;
116 }
117  
118  
119 2 ▶sub check_needed_params {
Subroutine check_needed_params: called CC=4 SCAR=13.9
Pod documented
120 2 my ($class,%params) = @_;
121
122 2 my @params_not_ok;
123
124 2 for my $attr ( keys %attrs ) {
125 24 ▶ if ( $attrs{$attr} eq 'required' and !$params{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs{$attr} eq "required" and not $params{$attr}) 2 22 24
Condition100%3/3
$attrs{$attr} eq "required" and not $params{$attr}
!ll&&!rl&&r
8142
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
126 2 push @params_not_ok, $attr;
127 }
128 }
129
130 2 return join ", ", @params_not_ok;
131 }
132  
133  
134 9 1;
135  
136 __END__
↑ Summary SMS/BinaryMessage.pm »