blib/lib/WWW/TWSMS.pm

filter: Statementstmt 23.1% 25 / 108 Branchbran 0.0% 0 / 64 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 37.5% 6 / 16 Podpod 0.0% 0 / 10 totaltotal 14.3% 31 / 216 CC 39 SCAR 35.6
CC
39
Cov
14%
new
90.0
errorCode
42.0
msgReceiver
30.0
CRAP 35.2
↑ Summary
1 package WWW::TWSMS;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTTP::Request::Common qw(GET POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 1 require Exporter;
12  
13 1 our @ISA = qw(Exporter);
14  
15 # Items to export into callers namespace by default. Note: do not export
16 # names by default without a very good reason. Use EXPORT_OK instead.
17 # Do not simply export all your public functions/methods/constants.
18  
19 # This allows declaration use WWW::TWSMS ':all';
20 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
21 # will save memory.
22 1 our %EXPORT_TAGS = ( 'all' => [ qw(
23
24 ) ] );
25  
26 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27  
28 1 our @EXPORT = qw(
29
30 );
31  
32 1 our $VERSION = '0.01';
33  
34  
35 # Preloaded methods go here.
36  
37  
38  
39 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=45.0
Pod undocumented
40
41 0 my $class = shift;
42 0 my $self = {NOTHING => 'nothing'};
43 0 my %args = @_;
44
45 0 bless($self, $class);
46 0 $self->reset();
47  
48 0 ▶ $self->{m_Username} = $args{Username} if (defined $args{Username});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"Username"} 0 0 0
49 0 ▶ $self->{m_Password} = $args{Password} if (defined $args{Password});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"Password"} 0 0 0
50 0 ▶ $self->{m_SmsType} = $args{SmsType} if (defined $args{SmsType});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"SmsType"} 0 0 0
51 0 ▶ $self->{m_SmsPopup} = $args{SmsPopup} if (defined $args{SmsPopup});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"SmsPopup"} 0 0 0
52 0 ▶ $self->{m_SmsMo} = $args{SmsMo} if (defined $args{SmsMo});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"SmsMo"} 0 0 0
53 0 ▶ $self->{m_SmsEncoding} = $args{SmsEncoding} if (defined $args{SmsEncoding});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"SmsEncoding"} 0 0 0
54 0 ▶ $self->{m_SmsVldtime} = $args{SmsVldtime} if (defined $args{SmsVldtime});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"SmsVldtime"} 0 0 0
55 0 ▶ $self->{m_SmsDlvtime} = $args{Dlvtime} if (defined $args{Dlvtime});
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"Dlvtime"} 0 0 0
56  
57 0 return $self;
58 }
59  
60  
61 0 ▶sub reset {
Subroutine reset: not called CC=2 SCAR=17.9
Pod undocumented
62  
63 # pop value
64 0 my $self = shift();
65  
66 # check to make sure that this function is being called on an object
67 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
68  
69 #-----------------------------------------------------------------
70 # Define default package vars
71 #-----------------------------------------------------------------
72
73 0 $self->{m_SoftwareWebsite} = "www.twsms.com";
74 0 $self->{m_SoftwareTitle} = "Perl TWSMS API";
75  
76
77 0 $self->{m_ErrorCode} = 0;
78 0 $self->{m_ErrorDescription} = undef;
79 0 $self->{m_ErrorResolution} = undef;
80
81 0 $self->{m_StatusCode} = undef;
82 0 $self->{m_StatusDescription} = undef;
83  
84
85 0 $self->{m_SmsType} = 'now'; # now => ¥ß§Y¶Ç°e , dlv => ¹w¬ùµo°e
86 0 $self->{m_SmsPopup} = ''; # 1 => Åý²°T¥ýÅã¥Ü¦b¤â¾÷µe­±¡A¦ý¤£·|¦s¨ì¤â¾÷
87 0 $self->{m_SmsMo} = ''; # Y => Âù¦V²°T
88 0 $self->{m_SmsEncoding} = 'big5'; # big5 => ¤¤­^¤åªº¤º®e¡Aªø«×¬°70­Ó¦r¤¸
89 # ascii => ¯Â­^¤åªº¤º®e¡Aªø«×¬°160­Ó¦r¤¸
90 0 $self->{m_SmsReceiver} = undef; # ±µ¦¬Â²°Tªº¤â¾÷¸¹½X
91 0 $self->{m_SmsVldtime} = undef; # ¦³®Ä´Á­­¡A¥H¬í¬°³æ¦ì
92 0 $self->{m_SmsDlvtime} = undef; # ¹w¬ù®É¶¡¡A®æ¦¡¬°YYYYMMDDHHII¡A¦p200405121830
93 # ·ím_SmsType TAG¬°dlv¤~¦³®Ä
94  
95 0 $self->{m_Secure} = 0;
96 0 $self->{m_ConnectionTimeout} = 30;
97 0 $self->{m_RemoteHost} = 'api.twsms.com';
98 0 $self->{m_RemotePort} = 80;
99
100 0 $self->{m_Username} = undef;
101 0 $self->{m_Password} = undef;
102  
103  
104
105 }
106  
107 0 ▶sub msgReceiver {
Subroutine msgReceiver: not called CC=5 SCAR=34.0
Pod undocumented
108  
109 0 my $self = shift;
110 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
111 0 ▶ $self->{m_SmsReceiver} = shift() if ($_[0] =~ m/^\d{10}$/);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^\d{10}$/ 0 0 0
112 }
113  
114 0 ▶ return $self->{m_SmsReceiver} if defined($self->{m_SmsReceiver}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_SmsReceiver"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_SmsReceiver"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_SmsReceiver"} or return undef
defined $self->{"m_SmsReceiver"}
Truth table0%0/2
A
A= defined $self->{"m_SmsReceiver"}
Aresult
11
00
115 }
116  
117 0 ▶sub msgData {
Subroutine msgData: not called CC=5 SCAR=34.0
Pod undocumented
118  
119 0 my $self = shift;
120
121 # check to make sure that this function is being called on an object
122 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
123  
124 0 ▶ if (@_ == 1) { $self->{m_SmsMsgData} = shift(); }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
125  
126 0 ▶ return $self->{m_SmsMsgData} if defined($self->{m_SmsMsgData}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_SmsMsgData"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_SmsMsgData"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_SmsMsgData"} or return undef
defined $self->{"m_SmsMsgData"}
Truth table0%0/2
A
A= defined $self->{"m_SmsMsgData"}
Aresult
11
00
127 }
128  
129 0 ▶sub msgSend {
Subroutine msgSend: not called CC=3 SCAR=24.8
Pod undocumented
130
131 0 my $self = shift;
132  
133 0 my $ua = LWP::UserAgent->new;
134 0 $ua->agent('Mozilla/5.0');
135  
136 my $req = POST "http://$self->{m_RemoteHost}/send.php",
137 [
138 'username' => $self->{m_Username},
139 'password' => $self->{m_Password},
140 'type' => $self->{m_SmsType},
141 'encoding' => $self->{m_SmsEncoding},
142 'mobile' => $self->{m_SmsReceiver},
143 'message' => $self->{m_SmsMsgData},
144 'popup' => $self->{m_SmsPopup},
145 'mo' => $self->{m_SmsMo},
146 'vldtime' => $self->{m_SmsVldtime},
147 'dlvtime' => $self->{m_SmsDlvtime}
148 0 ];
149  
150 0 my $file = $ua->request($req)->as_string;
151 0 ▶ my $CheckRes = $1 if ($file =~ m/msgid=(.*)/);
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /msgid=(.*)/ 0 0 0
152 0 ▶ if ($CheckRes <= 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($CheckRes <= 0) { } 0 0 0
153 0 $self->errorCode($CheckRes);
154 0 $self->statusDescription('¶Ç°e¥¢±Ñ');
155 } else {
156 0 $self->statusCode($CheckRes);
157 0 $self->statusDescription('¶Ç°e§¹¦¨');
158 }
159
160 }
161  
162 0 ▶sub statusCode {
Subroutine statusCode: not called CC=5 SCAR=34.0
Pod undocumented
163 # pop value
164 0 my $self = shift();
165
166 # check to make sure that this function is being called on an object
167 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
168  
169 0 ▶ if (@_ == 1) { $self->{m_StatusCode} = shift(); }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
170  
171 0 ▶ return $self->{m_StatusCode} if defined($self->{m_StatusCode}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_StatusCode"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_StatusCode"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_StatusCode"} or return undef
defined $self->{"m_StatusCode"}
Truth table0%0/2
A
A= defined $self->{"m_StatusCode"}
Aresult
11
00
172 }
173  
174 0 ▶sub statusDescription {
Subroutine statusDescription: not called CC=5 SCAR=34.0
Pod undocumented
175 # pop value
176 0 my $self = shift();
177
178 # check to make sure that this function is being called on an object
179 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
180  
181 0 ▶ if (@_ == 1) { $self->{m_StatusDescription} = shift(); }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
182  
183 0 ▶ return $self->{m_StatusDescription} if defined($self->{m_StatusDescription}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_StatusDescription"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_StatusDescription"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_StatusDescription"} or return undef
defined $self->{"m_StatusDescription"}
Truth table0%0/2
A
A= defined $self->{"m_StatusDescription"}
Aresult
11
00
184 }
185  
186 0 ▶sub errorCode {
Subroutine errorCode: not called CC=6 SCAR=37.4
Pod undocumented
187 # pop value
188 0 my $self = shift();
189 0 my %ERR_DESCRIPTION = ( '-1' => 'µo°e¥¢±Ñ',
190 '-2' => '±b¸¹©Î±K½X¿ù»~',
191 '-3' => 'popup TAG ³]©w¿ù»~',
192 '-4' => 'mo TAG ³]©w¿ù»~',
193 '-5' => 'encoding TAG ³]©w¿ù»~',
194 '-6' => 'mobile TAG ³]©w¿ù»~',
195 '-7' => 'message TAG ³]©w¿ù»~',
196 '-8' => 'vldtime TAG ³]©w¿ù»~',
197 '-9' => 'dlvtime TAG ³]©w¿ù»~',
198 '-10' => '²°T³q¼Æ¤£¨¬',
199 '-11' => '±b¸¹°±¥Î',
200 '-12' => 'type TAG ³]©w¿ù»~',
201 '-13' => '·í¨Ï¥Îwap push¥\¯à®É,¤£¥i±Ä¥Î¹w¬ù¤è¦¡µo°e',
202 '-14' => '¨Ó·½IP¨S¦³¨Ï¥ÎÅv­­',
203 '-99' => '¨t²Î¿ù»~¡]¦p¥X²{¦¹¿ù»~,½Ð³qª¾«ÈªA¤¤¤ß¡^'
204 );
205 # check to make sure that this function is being called on an object
206 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
207  
208  
209  
210 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
211 0 $self->{m_ErrorCode} = shift();
212 0 ▶ $ERR_DESCRIPTION{$self->{m_ErrorCode}} ? $self->errorDescription($ERR_DESCRIPTION{$self->{m_ErrorCode}}) : $self->errorDescription($self->{m_ErrorCode});
Branch: 1 branch
BranchTrueFalseTotal
$ERR_DESCRIPTION{$self->{'m_ErrorCode'}} ? : 0 0 0
213 }
214  
215 0 ▶ return $self->{m_ErrorCode} if defined($self->{m_ErrorCode}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_ErrorCode"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_ErrorCode"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_ErrorCode"} or return undef
defined $self->{"m_ErrorCode"}
Truth table0%0/2
A
A= defined $self->{"m_ErrorCode"}
Aresult
11
00
216 }
217  
218 0 ▶sub errorDescription {
Subroutine errorDescription: not called CC=5 SCAR=34.0
Pod undocumented
219 # pop value
220 0 my $self = shift();
221  
222 # check to make sure that this function is being called on an object
223 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
224  
225 0 ▶ if (@_ == 1) { $self->{m_ErrorDescription} = shift(); }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) 0 0 0
226  
227 0 ▶ return $self->{m_ErrorDescription} if defined($self->{m_ErrorDescription}) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"m_ErrorDescription"} or return undef 0 0 0
Condition0%0/2
defined $self->{"m_ErrorDescription"} or return undef
l!l
00
MC/DC0%0/1
defined $self->{"m_ErrorDescription"} or return undef
defined $self->{"m_ErrorDescription"}
Truth table0%0/2
A
A= defined $self->{"m_ErrorDescription"}
Aresult
11
00
228 }
229  
230 0 ▶sub success {
Subroutine success: not called CC=3 SCAR=24.8
Pod undocumented
231 # pop value
232 0 my $self = shift();
233
234 # check to make sure that this function is being called on an object
235 0 ▶ die "You must instantiate an object to use this function" if !(ref($self));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
236  
237 # if the error_code is between 0 and 10 then its an okay response.
238 0 ▶ if ($self->errorCode > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->errorCode > 0) 0 0 0
239 0 return 1;
240 }
241
242 0 return 0;
243 }
244  
245  
246  
247 1 1;
248 __END__
↑ Summary