lib/SMS/Send/Kannel/SMSbox.pm

filter: Statementstmt 32.4% 12 / 37 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 37.5% 3 / 8 Podpod 100% 1 / 1 totaltotal 22.5% 16 / 71 CC 12 SCAR 46.0
CC
12
Cov
20%
send_sms
156.0
_host_default
2.0
_protocol_default
2.0
CRAP 99.1
↑ Summary script/perl-SMS-Send-Kannel-SMSbox-send_sms.pl »
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.08';
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-0000',
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 => '+18005550000',
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 0 ▶sub send_sms {
Subroutine send_sms: not called CC=12 SCAR=50.5
Pod documented
56 0 my $self = shift;
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 ▶ print "Package: $PACKAGE, Method: send_sms, to: $to\n" if $self->debug >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug >= 3 0 0 0
60 0 ▶ my $text = defined($argv{"text"}) ? $argv{"text"} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $argv{'text'} ? : 0 0 0
61 0 ▶ print "Package: $PACKAGE, Method: send_sms, text: $text\n" if $self->debug >= 3;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug >= 3 0 0 0
62 0 my $url = $self->url; #isa URI
63 0 my @form = (
64 username => $self->username,
65 password => $self->password,
66 to => $to,
67 text => $text,
68 );
69 0 $url->query_form(\@form);
70 0 ▶ print "Package: $PACKAGE, Method: send_sms, URL: $url\n" if $self->debug >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug >= 2 0 0 0
71 0 my $response = $self->ua->get($url);
72 0 ▶ die(sprintf("HTTP Error: %s", $response->status_line)) unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
73 0 ▶ if ($self->debug >= 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug >= 6) 0 0 0
74 0 require Data::Dumper;
75 0 print Data::Dumper::Dumper($response);
76 }
77 0 my $content = $response->decoded_content;
78 0 ▶ print "Package: $PACKAGE, Method: send_sms, content: $content\n" if $self->debug >= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug >= 1 0 0 0
79 0 $self->{"__data"} = $self->{"__content"} = $content;
80 0 ▶ my $status = $content =~ m/^0:/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$content =~ /^0:/ ? : 0 0 0
81 0 ▶ warn("Package: $PACKAGE, Method: send_sms, Status: $status, Content: $content\n") if ($status != 1 and $self->warnings);
Branch: 1 branch
BranchTrueFalseTotal
if $status != 1 and $self->warnings 0 0 0
Condition0%0/3
$status != 1 and $self->warnings
!ll&&!rl&&r
000
MC/DC0%0/2
$status != 1 and $self->warnings
$status != 1 $self->warnings
Truth table0%0/3
A and B
A= $status != 1B= $self->warnings
ABresult
0X0
100
111
82 0 return $status;
83 }
84  
85 =head1 PROPERTIES
86  
87 =head2 username
88  
89 Sets and returns the username string value
90  
91 Override in sub class
92  
93 sub _username_default {"myusername"};
94  
95 Override in configuration
96  
97 [Kannel::SMSbox]
98 username=myusername
99  
100 =cut
101  
102 #see SMS::Send::Driver::WebService->userame
103  
104 =head2 password
105  
106 Sets and returns the password string value
107  
108 Override in sub class
109  
110 sub _password_default {"mypassword"};
111  
112 Override in configuration
113  
114 [Kannel::SMSbox]
115 password=mypassword
116  
117 =cut
118  
119 #see SMS::Send::Driver::WebService->password
120  
121 =head2 host
122  
123 Default: 127.0.0.1
124  
125 Override in sub class
126  
127 sub _host_default {"myhost.domain.tld"};
128  
129 Override in configuration
130  
131 [Kannel::SMSbox]
132 host=myhost.domain.tld
133  
134 =cut
135  
136 #see SMS::Send::Driver::WebService->host
137  
138 0 ▶sub _host_default {"127.0.0.1"};
Subroutine _host_default: not called CC=1 SCAR=6.9
139  
140 =head2 protocol
141  
142 Default: http
143  
144 Override in sub class
145  
146 sub _protocol_default {"https"};
147  
148 Override in configuration
149  
150 [Kannel::SMSbox]
151 protocol=https
152  
153 =cut
154  
155 #see SMS::Send::Driver::WebService->protocol
156  
157 0 ▶sub _protocol_default {"http"};
Subroutine _protocol_default: not called CC=1 SCAR=6.9
158  
159 =head2 port
160  
161 Default: 13013
162  
163 Override in sub class
164  
165 sub _port_default {443};
166  
167 Override in configuration
168  
169 [Kannel::SMSbox]
170 port=443
171  
172 =cut
173  
174 #see SMS::Send::Driver::WebService->port
175  
176 0 ▶sub _port_default {13013};
Subroutine _port_default: not called CC=1 SCAR=6.9
177  
178 =head2 script_name
179  
180 Default: /cgi-bin/sendsms
181  
182 Override in sub class
183  
184 sub _script_name_default {"/path/file"};
185  
186 Override in configuration
187  
188 [Kannel::SMSbox]
189 script_name=/path/file
190  
191 =cut
192  
193 #see SMS::Send::Driver::WebService->script_name
194  
195 0 ▶sub _script_name_default {'/cgi-bin/sendsms'};
Subroutine _script_name_default: not called CC=1 SCAR=6.9
196  
197 =head2 url
198  
199 Returns a L<URI> object based on above properties
200  
201 =cut
202  
203 #see SMS::Send::Driver::WebService->url
204  
205 =head2 warnings
206  
207 Default: 0
208  
209 Override in sub class
210  
211 sub _warnings_default {1};
212  
213 Override in configuration
214  
215 [Kannel::SMSbox]
216 warnings=1
217  
218 =cut
219  
220 #see SMS::Send::Driver::WebService->warnings
221  
222 =head2 debug
223  
224 Default: 0
225  
226 Override in sub class
227  
228 sub _debug_default {5};
229  
230 Override in configuration
231  
232 [Kannel::SMSbox]
233 debug=5
234  
235 =cut
236  
237 #see SMS::Send::Driver::WebService->debug
238  
239 =head1 BUGS
240  
241 =head1 SUPPORT
242  
243 =head1 AUTHOR
244  
245 Michael R. Davis
246  
247 =head1 COPYRIGHT and LICENSE
248  
249 Copyright (c) 2025 Michael R. Davis
250  
251 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
252  
253 The full text of the license can be found in the LICENSE file included with this module.
254  
255 =head1 SEE ALSO
256  
257 L<SMS::Send>, L<SMS::Send::Driver::WebService>
258  
259 =cut
260  
261 2 1;
↑ Summary script/perl-SMS-Send-Kannel-SMSbox-send_sms.pl »