blib/lib/SMS/Send/NexmoUnicode.pm

filter: Statementstmt 35.9% 14 / 39 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 33.8% 21 / 62 CC 8 SCAR 20.6
CC
8
Cov
27%
new
12.0
send_sms
12.0
_MESSAGE
12.0
CRAP 7.8
↑ Summary
1 package SMS::Send::NexmoUnicode;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base 'SMS::Send::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Nexmo::SMS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $VERSION = '0.02';
10 }
11  
12 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
13 0 my ($class, %params) = @_;
14  
15 0 foreach(qw/username password type from/) {
16 0 ▶ Carp::croak("No $_ specified") unless(defined $params{"_$_"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"_$_"} 0 0 0
17 }
18  
19 0 my $self = bless { %params }, $class;
20  
21 0 return $self;
22 }
23  
24 0 ▶sub send_sms {
Subroutine send_sms: not called CC=3 SCAR=24.8
Pod documented
25 0 my $self = shift;
26 0 my %params = @_;
27 0 my %options;
28  
29 # Get the message and destination
30 0 my $message = $self->_MESSAGE( $params{text} );
31 0 my $recipient = $self->_TO( delete $params{to} );
32  
33 my $nexmo = Nexmo::SMS->new(
34 server => 'https://rest.nexmo.com/sms/json',
35 username => $self->{"_username"},
36 0 password => $self->{"_password"},
37 );
38  
39 my $sms = $nexmo->sms(
40 text => $message,
41 to => $recipient,
42 type => $self->{"_type"},
43 0 ▶ from => $self->{"_from"},
Branch: 1 branch
BranchTrueFalseTotal
my $sms = $nexmo->sms("text", $message, "to", $recipient, "type", $self->{"_type"}, "from", $self->{"_from"}) or die $nexmo->errstr 0 0 0
44 ) or die $nexmo->errstr;
45  
46 0 ▶ if ('http' eq $self->{'_proxy_type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ("http" eq $self->{"_proxy_type"}) 0 0 0
47 0 $sms->user_agent->proxy(['http'], 'http://' . $self->{'_proxy_host'} . ':' . $self->{'_proxy_port'});
48 }
49
50 0 my $res = $sms->send;
51  
52 0 return $res->is_success;
53 }
54  
55 0 ▶sub _MESSAGE {
Subroutine _MESSAGE: not called CC=3 SCAR=24.8
56  
57 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
58 0 my $message = shift;
59 0 ▶ unless ( length($message) <= 160 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $message <= 160) 0 0 0
60 0 Carp::croak("Message length limit is 160 characters");
61 }
62
63 0 return $message;
64 }
65  
66 0 ▶sub _TO {
Subroutine _TO: not called CC=2 SCAR=17.9
67 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
68 0 my $to = shift;
69  
70 # International numbers need their + removed
71 0 $to =~ y/0123456789//cd;
72  
73 0 return $to;
74 }
75
76  
77 1 1;
78 __END__
↑ Summary