blib/lib/SMS/Send/TW/Qma.pm

filter: Statementstmt 33.3% 14 / 42 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 34.4% 21 / 61 CC 6 SCAR 18.7
CC
6
Cov
28%
new
12.0
_MESSAGE
12.0
_TO
6.0
CRAP 6.5
↑ Summary
1 package SMS::Send::TW::Qma;
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 WWW::Mechanize;
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.01';
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/) {
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=1 SCAR=6.9
Pod documented
25 0 my $self = shift;
26 0 my %params = @_;
27  
28 0 my $baseurl = 'http://www.qma.com/cdp/jsp/websms';
29 0 my $posturl = 'http://www.qma.com/cdp/jsp/websms/SMS_Action.jsp';
30  
31 # Get the message and destination
32 0 my $message = $self->_MESSAGE( $params{text} );
33 0 my $recipient = $self->_TO( delete $params{to} );
34  
35 0 my $ua = WWW::Mechanize->new(
36 agent => __PACKAGE__." v. $VERSION",
37 );
38  
39 0 $ua->agent_alias('Windows IE 6');
40 0 $ua->get("$baseurl/SMS_send.jsp");
41 $ua->submit_form(
42 form_name => 'form1',
43 fields => {
44 'j_username' => $self->{"_username"},
45 0 'j_password' => $self->{"_password"},
46 },
47 );
48  
49 # Should be ok now, right? Let's send it!
50 # Input SMS_Message, Recipients
51  
52 0 $ua->post($posturl,
53 [
54 'receivers' => $recipient,
55 'sendContent' => $message,
56 'iscurrentsend' => 'Y',
57 'func' => 'addSmsMessageInfo',
58 'targetURL' => 'SMS_send_result.jsp',
59 # 'sender' => "0953858839",
60 # 'contractid' => 'sf093',
61 ]);
62  
63  
64 0 $ua->content() =~ /document.location="(.+)"/i;
65 0 $ua->get("$baseurl/$1&iscurrentsend=Y");
66  
67 0 return $ua->content();
68  
69 }
70  
71 0 ▶sub _MESSAGE {
Subroutine _MESSAGE: not called CC=3 SCAR=24.8
72  
73 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
74 0 my $message = shift;
75 0 ▶ unless ( length($message) <= 160 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $message <= 160) 0 0 0
76 0 Carp::croak("Message length limit is 160 characters");
77 }
78
79 0 return $message;
80 }
81  
82 0 ▶sub _TO {
Subroutine _TO: not called CC=2 SCAR=17.9
83 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
84 0 my $to = shift;
85  
86 # International numbers need their + removed
87 0 $to =~ y/0123456789//cd;
88  
89 0 return $to;
90 }
91
92  
93 1 1;
94 __END__
↑ Summary