blib/lib/SMS/Send/AT/TMobile.pm

filter: Statementstmt 65.7% 23 / 35 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 64.8% 35 / 54 CC 7 SCAR 22.2
CC
7
Cov
58%
send_sms
21.1
new
3.0
BEGIN
1.0
CRAP 9.2
↑ Summary
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::AT::TMobile;
4 1 $SMS::Send::AT::TMobile::VERSION = '0.002';
5 # ABSTRACT: SMS::Send driver for the T-Mobile Austria SMSC service
6  
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base 'SMS::Send::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 4 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
14 4 my $class = shift;
15 4 my $self = { @_ };
16  
17 $self->{$_}
18 or croak "$_ missing"
19 4 ▶ for qw( _login _password );
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} or croak("$_ missing") 3 3 6
20  
21 1 return bless $self, $class;
22 }
23  
24 1 ▶sub send_sms {
Subroutine send_sms: called CC=5 SCAR=30.5
Pod documented
25 1 my ($self, %args) = @_;
26  
27 defined $args{_from}
28 1 ▶ or croak "_from missing";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{"_from"} or croak("_from missing") 0 1 1
29  
30 0 my $http = HTTP::Tiny->new( timeout => 3 );
31  
32 # default to numeric sender id
33 0 my $oa_ton = 1;
34 0 my $oa_npi = 1;
35 # alphanumerical sender id
36 0 ▶ if ( $args{_from} !~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"_from"} =~ /^\d+$/) 0 0 0
37 0 $oa_ton = 5;
38 0 $oa_npi = 0;
39 }
40 # the API expects the recipient without a leading +
41 0 ( my $to = $args{to} ) =~ s/^\+//;
42  
43 my $response = $http->post_form(
44 'http://213.162.67.5/cgi-bin/sendsms.fcgi',
45 [
46 id => $self->{_login},
47 passwd => $self->{_password},
48 rcpt_req => 0,
49 # sender
50 oa => $args{_from},
51 oa_ton => $oa_ton,
52 oa_npi => $oa_npi,
53 # recipient
54 da => $to,
55 da_ton => 1,
56 da_npi => 1,
57 text => $args{text},
58 0 ]
59 );
60  
61 # for example a timeout error
62 die $response->{content}
63 0 ▶ unless $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 0 0
64  
65 # known response messages:
66 # +OK 01 message(s) successfully sent to 43676012345678:msgid=0::
67 # -ERR 04 Currently unavailable ::
68 # -ERR 20 Unknown error ::
69 return 1
70 0 ▶ if $response->{content} =~ /^\+OK 01/;
Branch: 1 branch
BranchTrueFalseTotal
if $response->{"content"} =~ /^\+OK 01/ 0 0 0
71  
72 $@ = {
73 as_string => $response->{content},
74 0 };
75  
76 0 return 0;
77 }
78  
79 1 1;
80  
81 __END__
↑ Summary