blib/lib/Dancer/Plugin/SMS.pm

filter: Statementstmt 60.0% 15 / 25 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 43.9% 18 / 41 CC 5 SCAR 23.6
CC
5
Cov
44%
__ANON__
20.0
sms_driver
6.0
BEGIN
1.0
CRAP 10.6
↑ Summary
1 package Dancer::Plugin::SMS;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Dancer::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use SMS::Send;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.02';
8  
9 =head1 NAME
10  
11 Dancer::Plugin::SMS - Easy SMS text message sending from Dancer apps
12  
13  
14 =head1 SYNOPSIS
15  
16 In your Dancer app:
17  
18 # Positional params ($to, $message)
19 sms '+44788....', 'Hello there!';
20  
21 # Or named params
22 sms to => '+44...', text => 'Hello!';
23  
24 In your Dancer C<config.yml>, provide the SMS::Send::* driver name, and whatever
25 params are appropriate for that driver (see the driver documentation for
26 details) - example configuration for using L<SMS::Send::AQL>:
27  
28 plugins:
29 SMS:
30 driver: 'AQL'
31 _login: 'youraqlusername'
32 _password: 'youraqlpassword'
33 _sender: '+4478....'
34  
35  
36 =head1 DESCRIPTION
37  
38 Provides a quick and easy way to send SMS messages using L<SMS::Send> drivers
39 (of which there are many, so chances are the service you want to use is already
40 supported; if not, they're easy to write, and if you want to change providers
41 later, you can simply update a few lines in your config file, and you're done).
42  
43  
44 =head1 Keywords
45  
46 =head2 sms
47  
48 Send an SMS message. You can pass the destination and message as positional
49 params:
50  
51 sms $to, $message;
52  
53 Or, you can use named params:
54  
55 sms to => $to, text => $message;
56  
57 The latter form may be clearer, and would allow any additional driver-specific
58 parameters to be passed too, but the former is terser. The choice is yours.
59  
60  
61 =head2 sms_driver
62  
63 Returns the SMS::Send driver object, in case you need to do things with it
64 directly.
65  
66 =cut
67  
68  
69 2 my $sms_send;
70 0 ▶sub sms_driver {
Subroutine sms_driver: not called CC=2 SCAR=17.9
71 0 ▶ return $sms_send if $sms_send;
Branch: 1 branch
BranchTrueFalseTotal
if $sms_send 0 0 0
72
73 # OK, get the plugin's settings, and create a new object
74 0 my $config = plugin_setting;
75 0 my $driver = delete $config->{driver};
76 0 return $sms_send = SMS::Send->new($driver, %$config);
77 }
78 2 register sms_driver => \&sms_driver;
79  
80 0 ▶register sms => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
81 0 my %params;
82 0 ▶ if (@_ == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 0 0 0
elsif (@_ > 2 and @_ % 2 == 0) { } 0 0 0
83 0 @params{qw(to text)} = @_;
84 ▶ } elsif (@_ > 2 && @_ % 2 == 0) {
Condition0%0/3
@_ > 2 and @_ % 2 == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 2 and @_ % 2 == 0
@_ > 2 @_ % 2 == 0
Truth table0%0/3
A and B
A= @_ > 2B= @_ % 2 == 0
ABresult
0X0
100
111
85 0 %params = @_;
86 } else {
87 0 die "Invalid params passed to sms keyword!";
88 }
89 0 sms_driver->send_sms(%params);
90 2 };
91  
92 2 register_plugin;
93  
94  
95 =head1 AUTHOR
96  
97 David Precious, C<< <davidp@preshweb.co.uk> >>
98  
99 =head1 BUGS
100  
101 Please report any bugs or feature requests, preferably on GitHub, or on
102 rt.cpan.org:
103  
104 L<http://github.com/bigpresh/Dancer-Plugin-SMS/issues>
105  
106 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-SMS>
107  
108  
109 =head1 FEEDBACK / SUPPORT
110  
111 The author can usually be found on C<#dancer> on C<irc.perl.org> - see
112 L<http://www.perldancer.org/irc> for web IRC.
113  
114  
115 =head1 LICENSE AND COPYRIGHT
116  
117 Copyright 2011-2014 David Precious.
118  
119 This program is free software; you can redistribute it and/or modify it
120 under the terms of either: the GNU General Public License as published
121 by the Free Software Foundation; or the Artistic License.
122  
123 See http://dev.perl.org/licenses/ for more information.
124  
125 =head1 SEE ALSO
126  
127 L<Dancer>
128  
129 L<SMS::Send>
130  
131 L<http://www.aql.com/>
132  
133 =cut
134  
135 2 1; # End of Dancer::Plugin::SMS
↑ Summary