line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SMS; |
2
|
1
|
|
|
1
|
|
1005
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
1058
|
use SMS::Send; |
|
1
|
|
|
|
|
24010
|
|
|
1
|
|
|
|
|
269
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
1
|
|
|
1
|
1
|
56
|
my ($self, $app, $conf) = @_; |
9
|
1
|
|
50
|
|
|
6
|
$conf ||= {}; |
10
|
1
|
|
|
|
|
3
|
$conf->{driver} = delete $conf->{driver}; |
11
|
1
|
|
|
|
|
5
|
my $sms_send = SMS::Send->new($conf->{driver}, %$conf); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$app->helper( |
14
|
|
|
|
|
|
|
sms => sub { |
15
|
1
|
|
|
1
|
|
37237
|
my $self = shift; |
16
|
1
|
|
|
|
|
3
|
my %params; |
17
|
1
|
50
|
0
|
|
|
4
|
if (@_ == 2) { |
|
|
0
|
|
|
|
|
|
18
|
1
|
|
|
|
|
8
|
@params{qw(to text)} = @_; |
19
|
|
|
|
|
|
|
} elsif (@_ > 2 && @_ % 2 == 0) { |
20
|
0
|
|
|
|
|
0
|
%params = @_; |
21
|
|
|
|
|
|
|
} else { |
22
|
0
|
|
|
|
|
0
|
die "Invalid params passed to sms helper!"; |
23
|
|
|
|
|
|
|
} |
24
|
1
|
|
|
|
|
9
|
return $sms_send->send_sms(%params); |
25
|
|
|
|
|
|
|
} |
26
|
1
|
|
|
|
|
1384
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Mojolicious::Plugin::SMS - Easy SMS sending from Mojolicious apps |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Mojolicious::Lite |
38
|
|
|
|
|
|
|
plugin 'SMS' => { |
39
|
|
|
|
|
|
|
driver => 'Test' |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Mojolicious |
43
|
|
|
|
|
|
|
$self->plugin(SMS => { |
44
|
|
|
|
|
|
|
driver => 'Nexmo', |
45
|
|
|
|
|
|
|
_username => 'testuser', |
46
|
|
|
|
|
|
|
_password => 'testpassword' |
47
|
|
|
|
|
|
|
_from => 'Bender' |
48
|
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# in controller named params |
51
|
|
|
|
|
|
|
$self->sms( |
52
|
|
|
|
|
|
|
to => '+380506022375', |
53
|
|
|
|
|
|
|
text => 'use Perl or die;' |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# in controller positional params |
57
|
|
|
|
|
|
|
$self->sms('+380506022375', 'use Perl or die;'); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Provides a quick and easy way to send SMS messages using L drivers |
62
|
|
|
|
|
|
|
(of which there are many, so chances are the service you want to use is already |
63
|
|
|
|
|
|
|
supported; if not, they're easy to write, and if you want to change providers |
64
|
|
|
|
|
|
|
later, you can simply update a few lines in your config file, and you're done. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 OPTIONS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L has one required option 'driver', all other options |
69
|
|
|
|
|
|
|
are passed to appropriate L driver. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 C |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
L driver name. This is a required option. You may specify 'Test' if |
74
|
|
|
|
|
|
|
you need a testing driver. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 HELPERS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L implements one helper. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 sms |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Send an SMS message. You can pass the destination and message as positional |
83
|
|
|
|
|
|
|
params: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sms $to, $message; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Or, you can use named params: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sms to => $to, text => $message; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The latter form may be clearer, and would allow any additional driver-specific |
92
|
|
|
|
|
|
|
parameters to be passed too, but the former is terser. The choice is yours. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 METHODS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L inherits all methods from L |
97
|
|
|
|
|
|
|
and implements the following new ones. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 C |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$plugin->register; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Register plugin hooks and helpers in L application. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L, L, L. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 AUTHOR |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Yuriy Syrota |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Copyright (C) 2011 by Yuriy Syrota. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
118
|
|
|
|
|
|
|
under the same terms as Perl itself. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |