blib/lib/SMS/Send/Kannel/SMSbox.pm

filter: Statementstmt 38.7% 12 / 31 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 37.5% 3 / 8 Podpod 100% 1 / 1 totaltotal 31.3% 16 / 51 SCAR 29.3
CC
6
Cov
29%
send_sms
42.0
_host_default
2.0
_protocol_default
2.0
CRAP 18.7
↑ Summary
1 package SMS::Send::Kannel::SMSbox;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use base qw{SMS::Send::Driver::WebService};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.04';
7 2 our $PACKAGE = __PACKAGE__;
8  
9 =head1 NAME
10  
11 SMS::Send::Kannel::SMSbox - SMS::Send driver for Kannel SMSbox web service
12  
13 =head1 SYNOPSIS
14  
15 Using L<SMS::Send> Driver API
16  
17 SMS-Send.ini
18 [Kannel::SMSbox]
19 host=mykannelserver
20 username=myuser
21 password=mypass
22  
23 use SMS::Send;
24 my $service = SMS::Send->new('Kannel::SMSbox');
25 my $success = $service->send_sms(
26 to => '+1-800-555-1212',
27 text => 'Hello World!',
28 );
29  
30 =head1 DESCRIPTION
31  
32 SMS::Send driver for Kannel SMSbox web service.
33  
34 =head1 USAGE
35  
36 use SMS::Send::Kannel::SMSbox;
37 my $service = SMS::Send::Kannel::SMSbox->new(
38 username => $username,
39 password => $password,
40 host => $host,
41 );
42 my $success = $service->send_sms(
43 to => '+18005551212',
44 text => 'Hello World!',
45 );
46  
47 =head1 METHODS
48  
49 =head2 send_sms
50  
51 Sends the SMS message and returns 1 for success and 0 for failure or die on critical error.
52  
53 =cut
54  
55 sub send_sms {
56 0 ▶ my $self = shift;
Subroutine send_sms: not called CC=6 SCAR=37.4
Pod documented
57 0 my %argv = @_;
58 0 ▶ my $to = $argv{"to"} or die("Error: to address required");
Branch: 1 branch
BranchTrueFalseTotal
my $to = $argv{"to"} or die "Error: to address required" 0 0 0
59 0 ▶ my $text = defined($argv{"text"}) ? $argv{"text"} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $argv{'text'} ? : 0 0 0
60 0 my $url = $self->url; #isa URI
61 0 my @form = (
62 username => $self->username,
63 password => $self->password,
64 to => $to,
65 text => $text,
66 );
67 0 $url->query_form(\@form);
68 #print "$url\n";
69 0 my $response = $self->ua->get($url);
70 0 ▶ die(sprintf("HTTP Error: %s", $response->status_line)) unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
71 0 my $content = $response->decoded_content;
72 0 $self->{"__content"}=$content;
73 #use Data::Dumper qw{Dumper};
74 #print Dumper($content);
75 0 my $data = $content;
76 0 $self->{"__data"}=$data;
77 #print Dumper($data);
78 0 ▶ my $status = $data || '';
Condition0%0/2
$data || ''
l!l
00
MC/DC0%0/1
$data || ''
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
79 0 ▶ return $status =~ m/^0:/ ? 1 : 0; #0: Accepted for delivery
Branch: 1 branch
BranchTrueFalseTotal
$status =~ /^0:/ ? : 0 0 0
80 }
81  
82 =head1 PROPERTIES
83  
84 =head2 username
85  
86 Sets and returns the username string value
87  
88 Override in sub class
89  
90 sub _username_default {"myusername"};
91  
92 Override in configuration
93  
94 [Kannel::SMSbox]
95 username=myusername
96  
97 =cut
98  
99 #see SMS::Send::Driver::WebService->userame
100  
101 =head2 password
102  
103 Sets and returns the password string value
104  
105 Override in sub class
106  
107 sub _password_default {"mypassword"};
108  
109 Override in configuration
110  
111 [Kannel::SMSbox]
112 password=mypassword
113  
114 =cut
115  
116 #see SMS::Send::Driver::WebService->password
117  
118 =head2 host
119  
120 Default: 127.0.0.1
121  
122 Override in sub class
123  
124 sub _host_default {"myhost.domain.tld"};
125  
126 Override in configuration
127  
128 [Kannel::SMSbox]
129 host=myhost.domain.tld
130  
131 =cut
132  
133 #see SMS::Send::Driver::WebService->host
134  
135 0 ▶sub _host_default {"127.0.0.1"};
Subroutine _host_default: not called CC=1 SCAR=6.9
136  
137 =head2 protocol
138  
139 Default: http
140  
141 Override in sub class
142  
143 sub _protocol_default {"https"};
144  
145 Override in configuration
146  
147 [Kannel::SMSbox]
148 protocol=https
149  
150 =cut
151  
152 #see SMS::Send::Driver::WebService->protocol
153  
154 0 ▶sub _protocol_default {"http"};
Subroutine _protocol_default: not called CC=1 SCAR=6.9
155  
156 =head2 port
157  
158 Default: 13013
159  
160 Override in sub class
161  
162 sub _port_default {443};
163  
164 Override in configuration
165  
166 [Kannel::SMSbox]
167 port=443
168  
169 =cut
170  
171 #see SMS::Send::Driver::WebService->port
172  
173 0 ▶sub _port_default {13013};
Subroutine _port_default: not called CC=1 SCAR=6.9
174  
175 =head2 script_name
176  
177 Default: /cgi-bin/sendsms
178  
179 Override in sub class
180  
181 sub _script_name_default {"/path/file"};
182  
183 Override in configuration
184  
185 [Kannel::SMSbox]
186 script_name=/path/file
187  
188 =cut
189  
190 #see SMS::Send::Driver::WebService->script_name
191  
192 0 ▶sub _script_name_default {'/cgi-bin/sendsms'};
Subroutine _script_name_default: not called CC=1 SCAR=6.9
193  
194 =head2 url
195  
196 Returns a L<URI> object based on above properties
197  
198 =cut
199  
200 #see SMS::Send::Driver::WebService->url
201  
202 =head1 BUGS
203  
204 =head1 SUPPORT
205  
206 =head1 AUTHOR
207  
208 Michael R. Davis
209 CPAN ID: MRDVT
210 Satellite Tracking of People, LLC
211 mdavis@stopllc.com
212 http://www.stopllc.com/
213  
214 =head1 COPYRIGHT
215  
216 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
217  
218 The full text of the license can be found in the LICENSE file included with this module.
219  
220 =head1 SEE ALSO
221  
222 L<SMS::Send>, L<SMS::Send::Driver::WebService>
223  
224 =cut
225  
226 2 1;
↑ Summary