File Coverage

blib/lib/SMS/Send/CSoft.pm
Criterion Covered Total %
statement 44 44 100.0
branch 14 14 100.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 69 69 100.0


line stmt bran cond sub pod time code
1 1     1   969 use strict;
  1         2  
  1         38  
2 1     1   6 use warnings;
  1         2  
  1         69  
3             package SMS::Send::CSoft;
4             BEGIN {
5 1     1   26 $SMS::Send::CSoft::VERSION = '1.111490';
6             }
7              
8             # ABSTRACT: SMS::Send driver to send via the Connection Software service
9              
10              
11 1     1   29 use 5.006;
  1         3  
  1         47  
12 1     1   6 use SMS::Send::Driver;
  1         1  
  1         32  
13 1     1   5 use LWP::UserAgent;
  1         1  
  1         25  
14 1     1   901 use HTTP::Request::Common qw(POST);
  1         2230  
  1         551  
15              
16             our @ISA = qw/SMS::Send::Driver/;
17             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
18             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
19             our @EXPORT = qw();
20              
21             our $URL = 'https://www.csoft.co.uk/sendsms';
22              
23              
24             sub new {
25 4     4 1 4027 my $pkg = shift;
26 4         24 my %p = @_;
27 4 100       28 exists $p{_login} or die $pkg."->new requires _login parameter\n";
28 3 100       17 exists $p{_password} or die $pkg."->new requires _password parameter\n";
29 2 100       12 exists $p{_verbose} or $p{_verbose} = 1;
30 2         6 my $self = \%p;
31 2         8 bless $self, $pkg;
32 2         23 $self->{_ua} = LWP::UserAgent->new();
33 2         6030 return $self;
34             }
35              
36             sub send_sms {
37 5     5 1 3441 my $self = shift;
38 5         14 my %p = @_;
39 5         22 $p{to} =~ s/^\+//;
40 5         9 $p{to} =~ s/[- ]//g;
41              
42 5         45 my $response = $self->{_ua}->post($URL,
43             {
44             Username => $self->{_login},
45             PIN => $self->{_password},
46             Message => $p{text},
47             SendTo => $p{to},
48             });
49 5 100       28751 unless ($response->is_success) {
50 2         22 my $s = $response->as_string;
51 2 100       162 warn "HTTP failure: $s\n" if ($self->{_verbose});
52 2         22 return 0;
53             }
54 3         32 my $s = $response->as_string;
55 3         241 $s =~ s/\r?\n$//;
56 3         14 $s =~ s/^.*\r?\n//s;
57 3 100       12 unless ($s =~ /Message Sent OK/i) {
58 2 100       14 warn "Failed: $s\n" if ($self->{_verbose});
59 2         22 return 0;
60             }
61 1         29 return 1;
62             }
63              
64             1;
65              
66              
67             __END__