SMS.pm

filter: Statementstmt 91.6% 66 / 72 Branchbran 85.7% 12 / 14 Conditioncond 60.0% 15 / 25 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 92.3% 12 / 13 Podpod 100% 5 / 5 totaltotal 77.2% 112 / 145 CC 18 SCAR 17.0
CC
18
Cov
84%
sms
11.1
get_balance
5.0
new
4.0
CRAP 5.5
« SMS/TextMessage.pm ↑ Summary SMS/GetBalance.pm »
1 package Nexmo::SMS;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Nexmo::SMS::BinaryMessage;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Nexmo::SMS::TextMessage;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Nexmo::SMS::WAPPushMessage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use Nexmo::SMS::GetBalance;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Module for the Nexmo SMS API!
13  
14 9 our $VERSION = '0.10';
15  
16  
17  
18 9 my @attrs = qw(server username password);;
19  
20 9 for my $attr ( @attrs ) {
21 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 27 ▶ *{ __PACKAGE__ . '::' . $attr } = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
23 43 my ($self,$value) = @_;
24
25 43 my $key = '__' . $attr . '__';
26 43 ▶ $self->{$key} = $value if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 19 24 43
27 43 return $self->{$key};
28 27 };
29 }
30  
31 7 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
32 7 my ($class,%param) = @_;
33
34 7 my $self = bless {}, $class;
35  
36 7 ▶ $param{server} ||= 'https://rest.nexmo.com/sms/json';
Condition100%2/2
$param{"server"} ||= "https://rest.nexmo.com/sms/json"
l!l
61
MC/DC100%1/1
$param{"server"} ||= "https://rest.nexmo.com/sms/json"
$param{"server"}
Truth table100%2/2
A
A= $param{"server"}
Aresult
11
00
37
38 7 for my $attr ( @attrs ) {
39 21 ▶ if ( exists $param{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{$attr}) 19 2 21
40 19 $self->$attr( $param{$attr} );
41 }
42 }
43
44 7 return $self;
45 }
46  
47  
48 8 ▶sub sms {
Subroutine sms: called CC=10 SCAR=24.1
Pod documented
49 8 my ($self,%param) = @_;
50
51 8 my %types = (
52 text => 'Nexmo::SMS::TextMessage',
53 unicode => 'Nexmo::SMS::TextMessage',
54 binary => 'Nexmo::SMS::BinaryMessage',
55 wappush => 'Nexmo::SMS::WAPPushMessage',
56 );
57
58 8 my $requested_type = $param{type};
59 8 ▶ if ( exists $param{type} and !$types{$requested_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{"type"} and not $types{$requested_type}) 0 8 8
Condition66%2/3
exists $param{"type"} and not $types{$requested_type}
!ll&&!rl&&r
440
MC/DC0%0/2
exists $param{"type"} and not $types{$requested_type}
exists $param{"type"} not $types{$requested_type}
Truth table66%2/3
A and not(B)
A= exists $param{"type"}B= not $types{$requested_type}
ABresult
0X0
100
111
60 0 $self->errstr("Type $requested_type not supported (yet)!");
61 0 return;
62 }
63
64 8 ▶ my $type = $requested_type || 'text';
Condition100%2/2
$requested_type || 'text'
l!l
44
MC/DC100%1/1
$requested_type || 'text'
$requested_type
Truth table100%2/2
A
A= $requested_type
Aresult
11
00
65 8 my $module = $types{$type};
66  
67 8 ▶ $param{type} = $type if $type ne 'text';
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "text" 4 4 8
68
69 # check for needed params
70 8 my $sub_name = 'check_needed_params';
71 8 my $check_sub = $module->can( $sub_name );
72 8 ▶ if ( !$check_sub ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($check_sub) 0 8 8
73 0 $self->errstr("$module does not know about sub $sub_name");
74 0 return;
75 }
76
77 8 ▶ $param{server} ||= $self->server;
Condition66%2/3
$param{"server"} ||= $self->server
l!l&&r!l&&!r
170
MC/DC0%0/2
$param{"server"} ||= $self->server
$param{"server"} $self->server
Truth table66%2/3
A ||= B
A= $param{"server"}B= $self->server
ABresult
1X1
011
000
78 8 ▶ $param{username} ||= $self->username;
Condition66%2/3
$param{"username"} ||= $self->username
l!l&&r!l&&!r
170
MC/DC0%0/2
$param{"username"} ||= $self->username
$param{"username"} $self->username
Truth table66%2/3
A ||= B
A= $param{"username"}B= $self->username
ABresult
1X1
011
000
79 8 ▶ $param{password} ||= $self->password;
Condition66%2/3
$param{"password"} ||= $self->password
l!l&&r!l&&!r
170
MC/DC0%0/2
$param{"password"} ||= $self->password
$param{"password"} $self->password
Truth table66%2/3
A ||= B
A= $param{"password"}B= $self->password
ABresult
1X1
011
000
80
81 8 my $params_not_ok = $module->$sub_name( %param );
82 8 ▶ if ( $params_not_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params_not_ok) 3 5 8
83 3 $self->errstr("Check params $params_not_ok");
84 3 return;
85 }
86
87 # create new message
88 5 my $message = $module->new( %param );
89
90 # return message
91 5 return $message;
92 }
93  
94  
95 6 ▶sub errstr {
Subroutine errstr: called CC=2 SCAR=6.9
Pod documented
96 6 my ($self,$message) = @_;
97
98 6 ▶ $self->{__errstr__} = $message if @_ == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 2 3 3 6
99 6 return $self->{__errstr__};
100 }
101  
102  
103 1 ▶sub get_balance {
Subroutine get_balance: called CC=4 SCAR=16.1
Pod documented
104 1 my ($self,%param) = @_;
105  
106 1 ▶ $param{server} ||= $self->server;
Condition33%1/3
$param{"server"} ||= $self->server
l!l&&r!l&&!r
010
MC/DC0%0/2
$param{"server"} ||= $self->server
$param{"server"} $self->server
Truth table33%1/3
A ||= B
A= $param{"server"}B= $self->server
ABresult
1X1
011
000
107 1 ▶ $param{username} ||= $self->username;
Condition33%1/3
$param{"username"} ||= $self->username
l!l&&r!l&&!r
010
MC/DC0%0/2
$param{"username"} ||= $self->username
$param{"username"} $self->username
Truth table33%1/3
A ||= B
A= $param{"username"}B= $self->username
ABresult
1X1
011
000
108 1 ▶ $param{password} ||= $self->password;
Condition33%1/3
$param{"password"} ||= $self->password
l!l&&r!l&&!r
010
MC/DC0%0/2
$param{"password"} ||= $self->password
$param{"password"} $self->password
Truth table33%1/3
A ||= B
A= $param{"password"}B= $self->password
ABresult
1X1
011
000
109  
110 1 my $balance = Nexmo::SMS::GetBalance->new(
111 %param,
112 );
113
114 1 return $balance->get_balance;
115 }
116  
117  
118 0 ▶sub get_pricing {
Subroutine get_pricing: not called CC=1 SCAR=6.9
Pod documented
119 0 warn "not implemented yet\n";
120 0 return;
121 }
122  
123  
124 9 1; # End of Nexmo::SMS
125  
126 __END__
« SMS/TextMessage.pm ↑ Summary SMS/GetBalance.pm »