File Coverage

blib/lib/WWW/SMS/Enel.pm
Criterion Covered Total %
statement 9 27 33.3
branch 0 8 0.0
condition n/a
subroutine 3 5 60.0
pod 0 1 0.0
total 12 41 29.2


line stmt bran cond sub pod time code
1             #Copyright (c) 2002 Giulio Motta. All rights reserved.
2             #http://www-sms.sourceforge.net/
3             #This program is free software; you can redistribute it and/or
4             #modify it under the same terms as Perl itself.
5            
6             package WWW::SMS::Enel;
7 1     1   643 use Telephone::Number;
  1         2  
  1         184  
8             require Exporter;
9             @ISA = qw(Exporter);
10             @EXPORT = qw(MAXLENGTH);
11             @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
12            
13             @PREFIXES = (Telephone::Number->new('39', [
14             qw(320 328 329 340 347 348 349 333 335 338 339 330 336 337 368 360 380 388 389)
15             ], undef)
16             );
17            
18             $VERSION = '1.01';
19            
20             sub MAXLENGTH () {320}
21            
22             sub hnd_error {
23 0     0 0   $WWW::SMS::Error = sprintf "Failed at step %d of module %s", shift, __PACKAGE__;
24 0           return;
25             }
26            
27             sub _send {
28 0     0     my $self = shift;
29            
30 1     1   6 use HTTP::Request::Common qw(GET POST);
  1         1  
  1         56  
31 1     1   5 use LWP::UserAgent;
  1         1  
  1         254  
32            
33 0           my $ua = LWP::UserAgent->new;
34 0           $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3328)');
35 0 0         $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
36            
37 0 0         $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1)
38             if (length($self->{smstext})>MAXLENGTH);
39            
40 0           my $step = 1;
41 0           my $req = GET 'http://www.enel.it/';
42 0           my $file = $ua->simple_request($req)->as_string;
43 0           my (@cookies) = $file =~ /Set-Cookie:\s(.+?);/g;
44 0 0         return &hnd_error($step) if (@cookies < 2);
45            
46 0           my $cookie = join "; ", @cookies;
47 0           $step++;
48 0           $req = POST 'http://www.enel.it/scrivisms.asp',
49             Cookie => $cookie,
50             Referer => 'http://www.enel.it/scrivisms.asp',
51             Content => [
52             message => $self->{smstext},
53             prefix => $self->{prefix},
54             gsm => $self->{telnum},
55             accetta => 'yes',
56             x => int rand 7,
57             y => int rand 12,
58             ];
59            
60 0           $file = $ua->simple_request($req)->as_string;
61 0 0         return &hnd_error($step) unless ($file =~ /Messaggio\+SMS\+accodato/s);
62            
63 0           1;
64             }
65            
66             1;