File Coverage

blib/lib/Dancer/Plugin/SMS.pm
Criterion Covered Total %
statement 9 19 47.3
branch 0 6 0.0
condition 0 3 0.0
subroutine 3 5 60.0
pod n/a
total 12 33 36.3


line stmt bran cond sub pod time code
1             package Dancer::Plugin::SMS;
2              
3 1     1   24655 use strict;
  1         2  
  1         37  
4 1     1   5371 use Dancer::Plugin;
  1         111768  
  1         139  
5 1     1   982 use SMS::Send;
  1         30880  
  1         290  
6              
7             our $VERSION = '0.01';
8              
9             =head1 NAME
10              
11             Dancer::Plugin::SMS - Easy SMS sending from Dancer apps
12              
13              
14             =head1 SYNOPSIS
15              
16             In your Dancer app:
17              
18             # Positional params ($to, $message)
19             sms '+440788....', 'Hello there!';
20              
21             # Or named params
22             sms to => '+44...', text => 'Hello!';
23              
24             In your Dancer C, 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:
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 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             my $sms_send;
70             sub sms_driver {
71 0 0   0     return $sms_send if $sms_send;
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             register sms_driver => \&sms_driver;
79              
80             register sms => sub {
81 0     0     my %params;
82 0 0 0       if (@_ == 2) {
    0          
83 0           @params{qw(to text)} = @_;
84             } elsif (@_ > 2 && @_ % 2 == 0) {
85 0           %params = @_;
86             } else {
87 0           die "Invalid params passed to sms keyword!";
88             }
89 0           sms_driver->send_sms(%params);
90             };
91              
92             register_plugin;
93              
94              
95             =head1 AUTHOR
96              
97             David Precious, C<< >>
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
105              
106             L
107              
108              
109             =head1 FEEDBACK / SUPPORT
110              
111             The author can usually be found on C<#dancer> on C - see
112             L for web IRC.
113              
114              
115             =head1 LICENSE AND COPYRIGHT
116              
117             Copyright 2011 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
128              
129             L
130              
131             L
132              
133             =cut
134              
135             1; # End of Dancer::Plugin::SMS