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

filter: Statementstmt 36.1% 17 / 47 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 2 / 2 totaltotal 37.3% 25 / 67 CC 6 SCAR 18.1
CC
6
Cov
31%
new
12.0
_MESSAGE
12.0
_TO
6.0
CRAP 6.1
↑ Summary
1 package SMS::Send::TW::PChome;
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 1 ▶use Text::Iconv;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 $VERSION = '0.03';
11 }
12  
13 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
14 0 my ($class, %params) = @_;
15  
16 0 foreach(qw/username password authcode/) {
17 0 ▶ Carp::croak("No $_ specified") unless(defined $params{"_$_"});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"_$_"} 0 0 0
18 }
19  
20 0 my $self = bless { %params }, $class;
21  
22 0 return $self;
23 }
24  
25 0 ▶sub send_sms {
Subroutine send_sms: not called CC=1 SCAR=6.9
Pod documented
26 0 my $self = shift;
27 0 my %params = @_;
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 0 my $ua = WWW::Mechanize->new(
34 agent => __PACKAGE__." v. $VERSION",
35 );
36  
37 0 $ua->agent_alias('Windows IE 6');
38
39 # Should be ok now, right? Let's send it!
40 # Login
41 $ua->post('https://login.pchome.com.tw/adm/person_sell.htm',
42 [ 'mbrid' => $self->{"_username"},
43 0 'mbrpass' => $self->{"_password"},
44 'chan' => 'sms',
45 'record_ipw' => 'false',
46 'ltype' => 'checklogin',
47 'buyflag' => '', ]);
48
49
50 # Input SMS_Message, Recipients
51 0 $ua->get('http://sms.pchome.com.tw/quick_index.htm');
52 0 $ua->post('http://sms.pchome.com.tw/check_msg.htm',
53 [ 'encoding_type' => 'BIG5',
54 'msg_body' => $message,
55 'mobile_list' => $recipient,
56 'send_type' => 1, ]);
57  
58  
59 # Input Authcode
60 0 $ua->field('ezpay_key', $ua->value('ezpay_key')); # Forward Hidden field: ezpay_key
61 0 $ua->field('exh_no', $ua->value('exh_no')); # Forward Hidden field: exh_no
62 0 $ua->field('auth_code', $self->{"_authcode"}); # put Auth Code
63 0 $ua->current_form()->action('https://ezpay.pchome.com.tw/auth_access.htm');
64 0 $ua->submit();
65
66 0 return $ua->content;
67 }
68  
69 0 ▶sub _MESSAGE {
Subroutine _MESSAGE: not called CC=3 SCAR=24.8
70  
71 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
72 0 my $message = shift;
73 0 my $converter = Text::Iconv->new("big5", "utf-8");
74 0 ▶ unless ( length($message) <= 160 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $message <= 160) 0 0 0
75 0 Carp::croak("Message length limit is 160 characters");
76 }
77
78 0 return $converter->convert($message);
79 }
80  
81 0 ▶sub _TO {
Subroutine _TO: not called CC=2 SCAR=17.9
82 0 ▶ my $class = ref $_[0] ? ref shift : shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
83 0 my $to = shift;
84  
85 # International numbers need their + removed
86 0 $to =~ y/0123456789//cd;
87  
88 0 return $to;
89 }
90
91  
92 1 1;
93 __END__
↑ Summary