| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::SMS::Mtnsms; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.003'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6735
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
67
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Standard pragmas |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Net::SMS::Web; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# POD |
|
18
|
|
|
|
|
|
|
# |
|
19
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Net::SMS::Mtnsms - a module to send SMS messages using the Mtnsms web2sms |
|
24
|
|
|
|
|
|
|
gateway (L). |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $sms = Net::SMS::Mtnsms->new( |
|
29
|
|
|
|
|
|
|
autotruncate => 1, |
|
30
|
|
|
|
|
|
|
username => 'yourname', |
|
31
|
|
|
|
|
|
|
password => 'yourpassword', |
|
32
|
|
|
|
|
|
|
recipient => 07713123456, |
|
33
|
|
|
|
|
|
|
signature => 'a test', |
|
34
|
|
|
|
|
|
|
message => 'a test message', |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$sms->verbose( 1 ); |
|
38
|
|
|
|
|
|
|
$sms->message( 'a different message' ); |
|
39
|
|
|
|
|
|
|
print "sending message to mobile number ", $sms->recipient(); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$sms->send_sms(); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
A perl module to send SMS messages, using the Mtnsms web2sms gateway. This |
|
46
|
|
|
|
|
|
|
module will only work with mobile phone numbers that have been registered with |
|
47
|
|
|
|
|
|
|
Mtnsms (L) and uses form submission to a URL that may be |
|
48
|
|
|
|
|
|
|
subject to change. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
There is a maximum length for SMS signature + message (160 for Mtnsms). If the |
|
51
|
|
|
|
|
|
|
sum of signature and message lengths exceed this, the behaviour of the |
|
52
|
|
|
|
|
|
|
Net::SMS::Mtnsms objects depends on the value of the 'autotruncate' argument to |
|
53
|
|
|
|
|
|
|
the constructor. If this is a true value, then the signature / message will be |
|
54
|
|
|
|
|
|
|
truncated to 123 characters. If false, the object will throw an exception |
|
55
|
|
|
|
|
|
|
(croak). |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# Package globals |
|
62
|
|
|
|
|
|
|
# |
|
63
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
64
|
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
269
|
use vars qw( |
|
66
|
|
|
|
|
|
|
@ISA |
|
67
|
|
|
|
|
|
|
$BASE_URL |
|
68
|
|
|
|
|
|
|
$LOGIN_URL |
|
69
|
|
|
|
|
|
|
$SEND_URL |
|
70
|
|
|
|
|
|
|
$LOGOUT_URL |
|
71
|
|
|
|
|
|
|
%REQUIRED_KEYS |
|
72
|
|
|
|
|
|
|
%LEGAL_KEYS |
|
73
|
|
|
|
|
|
|
$MAX_CHARS |
|
74
|
1
|
|
|
1
|
|
5
|
); |
|
|
1
|
|
|
|
|
2
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
@ISA = qw( Net::SMS::Web ); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$BASE_URL = 'http://www.mtnsms.com'; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$LOGIN_URL = "/session.asp"; |
|
81
|
|
|
|
|
|
|
$SEND_URL = "/sms/xsms.asp"; |
|
82
|
|
|
|
|
|
|
$LOGOUT_URL = "/logout.asp"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
%REQUIRED_KEYS = ( |
|
85
|
|
|
|
|
|
|
username => 1, |
|
86
|
|
|
|
|
|
|
password => 1, |
|
87
|
|
|
|
|
|
|
recipient => 1, |
|
88
|
|
|
|
|
|
|
message => 1, |
|
89
|
|
|
|
|
|
|
); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
%LEGAL_KEYS = ( |
|
92
|
|
|
|
|
|
|
username => 1, |
|
93
|
|
|
|
|
|
|
password => 1, |
|
94
|
|
|
|
|
|
|
recipient => 1, |
|
95
|
|
|
|
|
|
|
signature => 1, |
|
96
|
|
|
|
|
|
|
message => 1, |
|
97
|
|
|
|
|
|
|
verbose => 1, |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$MAX_CHARS = 123; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
103
|
|
|
|
|
|
|
# |
|
104
|
|
|
|
|
|
|
# Constructor |
|
105
|
|
|
|
|
|
|
# |
|
106
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The constructor for Net::SMS::Mtnsms takes the following arguments as hash |
|
111
|
|
|
|
|
|
|
values (see L<"SYNOPSIS">): |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 autotruncate (OPTIONAL) |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Mtnsms has a upper limit on the length of the subject + message (123). If |
|
116
|
|
|
|
|
|
|
autotruncate is true, subject and message are truncated to 123 if the sum of |
|
117
|
|
|
|
|
|
|
their lengths exceeds 160. The heuristic for this is simply to treat subject |
|
118
|
|
|
|
|
|
|
and message as a string and truncate it (i.e. if length(subject) >= 123 then |
|
119
|
|
|
|
|
|
|
message is truncated to 0. Thanks to Mark Zealey for this |
|
120
|
|
|
|
|
|
|
suggestion. The default for this is false. |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 username (REQUIRED) |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The Mtnsms username for the user (assuming that the user is already registered |
|
125
|
|
|
|
|
|
|
at L. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 password (REQUIRED) |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The Mtnsms password for the user (assuming that the user is already registered |
|
130
|
|
|
|
|
|
|
at L. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 recipient (REQUIRED) |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Mobile number for the intended SMS recipient. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 subject (REQUIRED) |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
SMS message subject. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 message (REQUIRED) |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
SMS message body. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 verbose (OPTIONAL) |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
If true, various soothing messages are sent to STDERR. Defaults to false. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub new |
|
151
|
|
|
|
|
|
|
{ |
|
152
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
153
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( @_ ); |
|
154
|
0
|
|
|
|
|
|
$self->_init( @_ ); |
|
155
|
0
|
|
|
|
|
|
return $self; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
159
|
|
|
|
|
|
|
# |
|
160
|
|
|
|
|
|
|
# AUTOLOAD - to set / get object attributes |
|
161
|
|
|
|
|
|
|
# |
|
162
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTOLOAD |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
All of the constructor arguments can be got / set using accessor methods. E.g.: |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
$old_message = $self->message; |
|
169
|
|
|
|
|
|
|
$self->message( $new_message ); |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub AUTOLOAD |
|
174
|
|
|
|
|
|
|
{ |
|
175
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
176
|
0
|
|
|
|
|
|
my $value = shift; |
|
177
|
|
|
|
|
|
|
|
|
178
|
1
|
|
|
1
|
|
6
|
use vars qw( $AUTOLOAD ); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
600
|
|
|
179
|
0
|
|
|
|
|
|
my $key = $AUTOLOAD; |
|
180
|
0
|
|
|
|
|
|
$key =~ s/.*:://; |
|
181
|
0
|
0
|
|
|
|
|
return if $key eq 'DESTROY'; |
|
182
|
0
|
0
|
|
|
|
|
die ref($self), ": unknown method $AUTOLOAD\n" |
|
183
|
|
|
|
|
|
|
unless $LEGAL_KEYS{ $key } |
|
184
|
|
|
|
|
|
|
; |
|
185
|
0
|
0
|
|
|
|
|
if ( defined( $value ) ) |
|
186
|
|
|
|
|
|
|
{ |
|
187
|
0
|
|
|
|
|
|
$self->{$key} = $value; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
0
|
|
|
|
|
|
return $self->{$key}; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 METHODS |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 send_sms |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This method is invoked to actually send the SMS message that corresponds to the |
|
197
|
|
|
|
|
|
|
constructor arguments. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub send_sms |
|
202
|
|
|
|
|
|
|
{ |
|
203
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
204
|
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$self->action( Net::SMS::Web::Action->new( |
|
206
|
|
|
|
|
|
|
url => $BASE_URL . $LOGIN_URL, |
|
207
|
|
|
|
|
|
|
params => { |
|
208
|
|
|
|
|
|
|
username => $self->{username}, |
|
209
|
|
|
|
|
|
|
password => $self->{password}, |
|
210
|
|
|
|
|
|
|
}, |
|
211
|
|
|
|
|
|
|
method => 'POST', |
|
212
|
|
|
|
|
|
|
) ); |
|
213
|
0
|
|
|
|
|
|
$self->action( Net::SMS::Web::Action->new( |
|
214
|
|
|
|
|
|
|
url => $BASE_URL . $SEND_URL, |
|
215
|
|
|
|
|
|
|
params => { |
|
216
|
|
|
|
|
|
|
smsToNumbers => $self->{recipient}, |
|
217
|
|
|
|
|
|
|
smsMessage => $self->{message}, |
|
218
|
|
|
|
|
|
|
smsSig => defined $self->{signature}, |
|
219
|
|
|
|
|
|
|
smsSigDyna => $self->{signature}, |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
) ); |
|
222
|
0
|
|
|
|
|
|
$self->action( Net::SMS::Web::Action->new( |
|
223
|
|
|
|
|
|
|
url => $BASE_URL . $LOGOUT_URL, |
|
224
|
|
|
|
|
|
|
) ); |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub _check_length |
|
228
|
|
|
|
|
|
|
{ |
|
229
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
230
|
0
|
|
|
|
|
|
$self->{message_length} = 0; |
|
231
|
0
|
0
|
|
|
|
|
if ( $self->{autotruncate} ) |
|
232
|
|
|
|
|
|
|
{ |
|
233
|
|
|
|
|
|
|
# Chop the message down the the correct length. Also supports subjects |
|
234
|
|
|
|
|
|
|
# > $MAX_CHARS, but I think it's a bit stupid to send one, anyway ... |
|
235
|
|
|
|
|
|
|
# - Mark Zealey |
|
236
|
0
|
|
|
|
|
|
$self->{subject} = substr $self->{subject}, 0, $MAX_CHARS; |
|
237
|
0
|
|
|
|
|
|
$self->{message} = |
|
238
|
|
|
|
|
|
|
substr $self->{message}, 0, $MAX_CHARS - length $self->{subject} |
|
239
|
|
|
|
|
|
|
; |
|
240
|
0
|
|
|
|
|
|
$self->{message_length} += length $self->{$_} for qw/subject message/; |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
else |
|
243
|
|
|
|
|
|
|
{ |
|
244
|
0
|
|
|
|
|
|
$self->{message_length} = |
|
245
|
|
|
|
|
|
|
length( $self->{subject} ) + length( $self->{message} ) |
|
246
|
|
|
|
|
|
|
; |
|
247
|
0
|
0
|
|
|
|
|
if ( $self->{message_length} > $MAX_CHARS ) |
|
248
|
|
|
|
|
|
|
{ |
|
249
|
0
|
|
|
|
|
|
die ref($self), |
|
250
|
|
|
|
|
|
|
": total message length (subject + message) is too long ", |
|
251
|
|
|
|
|
|
|
"(> $MAX_CHARS)\n" |
|
252
|
|
|
|
|
|
|
; |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub _init |
|
258
|
|
|
|
|
|
|
{ |
|
259
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
260
|
0
|
|
|
|
|
|
my %keys = @_; |
|
261
|
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
for ( keys %REQUIRED_KEYS ) |
|
263
|
|
|
|
|
|
|
{ |
|
264
|
0
|
0
|
|
|
|
|
die ref($self), ": $_ field is required\n" unless $keys{$_}; |
|
265
|
|
|
|
|
|
|
} |
|
266
|
0
|
|
|
|
|
|
for ( keys %keys ) |
|
267
|
|
|
|
|
|
|
{ |
|
268
|
0
|
|
|
|
|
|
$self->{$_} = $keys{$_}; |
|
269
|
|
|
|
|
|
|
} |
|
270
|
0
|
|
|
|
|
|
$self->_check_length(); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
274
|
|
|
|
|
|
|
# |
|
275
|
|
|
|
|
|
|
# More POD ... |
|
276
|
|
|
|
|
|
|
# |
|
277
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 ACKNOWLEGEMENTS |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Many thanks to P-A-N-D-O-R [pandor@compclub.sk] for access to a script he wrote |
|
282
|
|
|
|
|
|
|
for submitting SMS messages via mtnsms. |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 AUTHOR |
|
285
|
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Ave Wrigley |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
289
|
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
Copyright (c) 2001 Ave Wrigley. All rights reserved. This program is free |
|
291
|
|
|
|
|
|
|
software; you can redistribute it and/or modify it under the same terms as Perl |
|
292
|
|
|
|
|
|
|
itself. |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
1; |