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