File Coverage

blib/lib/WWW/SMS/Clarence.pm
Criterion Covered Total %
statement 12 61 19.6
branch 0 22 0.0
condition n/a
subroutine 4 6 66.6
pod 0 1 0.0
total 16 90 17.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             #Copyright (c) 2001 Giulio Motta. All rights reserved.
4             #http://www-sms.sourceforge.net/
5             #This program is free software; you can redistribute it and/or
6             #modify it under the same terms as Perl itself.
7              
8             package WWW::SMS::Clarence;
9 1     1   544 use Telephone::Number;
  1         3  
  1         148  
10             require Exporter;
11             @ISA = qw(Exporter);
12             @EXPORT = qw();
13             @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
14              
15             @PREFIXES = (Telephone::Number->new('39', [
16             qw(333 335 338 339 340 347 348 349 328 329 380 388 389)
17             ], undef)
18             );
19              
20             $VERSION = '1.01';
21              
22             sub MAXLENGTH () {120} # maximum message length
23              
24             sub hnd_error {
25 0     0 0   $_ = shift;
26 0           $WWW::SMS::Error = "Failed at step $_ of module Clarence.pm\n";
27 0           return 0;
28             }
29              
30             sub _send {
31 0     0     my $self = shift;
32              
33 1     1   4 use HTTP::Request::Common qw(GET POST);
  1         2  
  1         66  
34 1     1   4 use HTTP::Cookies;
  1         2  
  1         19  
35 1     1   4 use LWP::UserAgent;
  1         1  
  1         726  
36            
37 0 0         $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1) if (length($self->{smstext})>MAXLENGTH);
38              
39 0           SWITCH: for ($self->{prefix}) {
40 0 0         /^33/ && do {$wholeprefix = "$self->{prefix}+22201"; last;};
  0            
  0            
41 0 0         /^34/ && do {$wholeprefix = "$self->{prefix}+22210"; last;};
  0            
  0            
42 0 0         /^32/ && do {$wholeprefix = "$self->{prefix}+22288"; last;};
  0            
  0            
43 0 0         /^38/ && do {$wholeprefix = "$self->{prefix}+22298"; last;};
  0            
  0            
44 0           die "Prefix not supported...\n";
45             }
46              
47 0           my $ua = LWP::UserAgent->new;
48 0           $ua->agent('Mozilla/5.0');
49 0 0         $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
50 0           $ua->cookie_jar(HTTP::Cookies->new(
51             file => $self->{cookie_jar},
52             autosave => 1
53             )
54             );
55              
56             #STEP 1
57 0           my $step = 1;
58 0           my $req = POST 'http://sms.clarence.com/sms2.php3',
59             [
60             testosms => $self->{smstext}, smartype => "1tx1",
61             chiave => "", shortid => "",
62             submit => "Invia il tuo messaggio"
63             ];
64              
65 0           my $res = $ua->request($req);
66 0 0         $res->is_success() || (return &hnd_error($step));
67             #STEP 1
68              
69             #STEP 2
70 0           $step++;
71 0           $req = POST 'http://sms.clarence.com/sms3.php3',
72             [
73             testosms => $self->{smstext}, prefix => $wholeprefix,
74             nrotel => $self->{telnum}, binvio => "Invia"
75             ];
76              
77 0           $file = $ua->simple_request($req)->as_string;
78 0 0         ($file =~ /Location: (.+?)\n/) || (return &hnd_error($step));
79             #STEP 2
80              
81             #STEP 3
82 0           $step++;
83 0           $req = GET "http://sms.clarence.com/$1";
84 0           $file = $ua->simple_request($req)->as_string;
85 0 0         ($file =~ /Location: (.+?)\n/) || (return &hnd_error($step));
86             #STEP 3
87            
88             #STEP 4
89 0           $step++;
90 0           $temp = $1;
91 0           $temp =~ s/\ /\%20/g;
92 0           $req = GET $temp;
93 0           $file = $ua->simple_request($req)->as_string;
94 0 0         return &hnd_error($step) unless
95             ($file =~ /.*/s);
96             #STEP 4
97            
98             #STEP 5
99 0           $step++;
100 0           my $sessionid = $1;
101 0           my $ip = $2;
102 0           $req = POST 'http://freesms.supereva.it/cgi-bin/clarence/sendsms.chm',
103             [
104             sessionid => $sessionid, mittente => $ip,
105             prefix => $self->{prefix}, numtel => $self->{telnum},
106             messagetext => $self->{smstext}, flash => "0",
107             Submit => " Invia "
108             ];
109 0           $req->headers->referer($temp);
110 0           $file = $ua->request($req)->as_string;
111 0 0         return &hnd_error($step) if ($file =~ /spiacente/i);
112             #STEP 5
113 0           1;
114             }
115              
116             1;