| Filename | /mnt/catalyst/koha/C4/SMS.pm | 
| Statements | Executed 10 statements in 349µs | 
| Calls | P | F | Exclusive Time | Inclusive Time | Subroutine | 
|---|---|---|---|---|---|
| 1 | 1 | 1 | 454µs | 468µs | C4::SMS::BEGIN@35 | 
| 1 | 1 | 1 | 10µs | 18µs | C4::SMS::BEGIN@36 | 
| 1 | 1 | 1 | 8µs | 10µs | C4::SMS::BEGIN@38 | 
| 1 | 1 | 1 | 6µs | 24µs | C4::SMS::BEGIN@40 | 
| 1 | 1 | 1 | 3µs | 3µs | C4::SMS::BEGIN@42 | 
| 0 | 0 | 0 | 0s | 0s | C4::SMS::driver | 
| 0 | 0 | 0 | 0s | 0s | C4::SMS::send_sms | 
| Line | State ments | Time on line | Calls | Time in subs | Code | 
|---|---|---|---|---|---|
| 1 | package C4::SMS; | ||||
| 2 | |||||
| 3 | # Copyright 2007 Liblime | ||||
| 4 | # | ||||
| 5 | # This file is part of Koha. | ||||
| 6 | # | ||||
| 7 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
| 8 | # terms of the GNU General Public License as published by the Free Software | ||||
| 9 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
| 10 | # version. | ||||
| 11 | # | ||||
| 12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
| 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
| 14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
| 15 | # | ||||
| 16 | # You should have received a copy of the GNU General Public License along | ||||
| 17 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 19 | |||||
| 20 | =head1 NAME | ||||
| 21 | |||||
| 22 | C4::SMS - send SMS messages | ||||
| 23 | |||||
| 24 | =head1 SYNOPSIS | ||||
| 25 | |||||
| 26 | my $success = C4::SMS->send_sms( message => 'This is my text message', | ||||
| 27 | destination => '212-555-1212' ); | ||||
| 28 | |||||
| 29 | =head1 DESCRIPTION | ||||
| 30 | |||||
| - - | |||||
| 33 | =cut | ||||
| 34 | |||||
| 35 | 2 | 29µs | 2 | 482µs | # spent 468µs (454+14) within C4::SMS::BEGIN@35 which was called:
#    once (454µs+14µs) by C4::Letters::BEGIN@31 at line 35 # spent   468µs making 1 call to C4::SMS::BEGIN@35
# spent    14µs making 1 call to strict::import | 
| 36 | 2 | 22µs | 2 | 27µs | # spent 18µs (10+9) within C4::SMS::BEGIN@36 which was called:
#    once (10µs+9µs) by C4::Letters::BEGIN@31 at line 36 # spent    18µs making 1 call to C4::SMS::BEGIN@36
# spent     9µs making 1 call to warnings::import | 
| 37 | |||||
| 38 | 2 | 24µs | 2 | 12µs | # spent 10µs (8+2) within C4::SMS::BEGIN@38 which was called:
#    once (8µs+2µs) by C4::Letters::BEGIN@31 at line 38 # spent    10µs making 1 call to C4::SMS::BEGIN@38
# spent     2µs making 1 call to C4::Context::import | 
| 39 | |||||
| 40 | 2 | 27µs | 2 | 41µs | # spent 24µs (6+17) within C4::SMS::BEGIN@40 which was called:
#    once (6µs+17µs) by C4::Letters::BEGIN@31 at line 40 # spent    24µs making 1 call to C4::SMS::BEGIN@40
# spent    17µs making 1 call to vars::import | 
| 41 | |||||
| 42 | # spent 3µs within C4::SMS::BEGIN@42 which was called:
#    once (3µs+0s) by C4::Letters::BEGIN@31 at line 44 | ||||
| 43 | 1 | 3µs | $VERSION = 3.07.00.049; | ||
| 44 | 1 | 241µs | 1 | 3µs | } # spent     3µs making 1 call to C4::SMS::BEGIN@42 | 
| 45 | |||||
| 46 | =head1 METHODS | ||||
| 47 | |||||
| 48 | =cut | ||||
| 49 | |||||
| 50 | # The previous implmentation used username and password. | ||||
| 51 | # our $user = C4::Context->config('smsuser'); | ||||
| 52 | # our $pwd = C4::Context->config('smspass'); | ||||
| 53 | |||||
| 54 | =head2 send_sms | ||||
| 55 | |||||
| 56 | =cut | ||||
| 57 | |||||
| 58 | sub send_sms { | ||||
| 59 | my $self = shift; | ||||
| 60 | my $params= shift; | ||||
| 61 | |||||
| 62 | foreach my $required_parameter ( qw( message destination ) ) { | ||||
| 63 | # Should I warn in some way? | ||||
| 64 | return unless defined $params->{ $required_parameter }; | ||||
| 65 | } | ||||
| 66 | |||||
| 67 | eval { require SMS::Send; }; | ||||
| 68 | if ( $@ ) { | ||||
| 69 | # we apparently don't have SMS::Send. Return a failure. | ||||
| 70 | return; | ||||
| 71 | } | ||||
| 72 | |||||
| 73 | # This allows the user to override the driver. See SMS::Send::Test | ||||
| 74 | my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); | ||||
| 75 | return unless $driver; | ||||
| 76 | |||||
| 77 | # warn "using driver: $driver to send message to $params->{'destination'}"; | ||||
| 78 | |||||
| 79 | # Create a sender | ||||
| 80 | my $sender = SMS::Send->new( $driver, | ||||
| 81 | _login => C4::Context->preference('SMSSendUsername'), | ||||
| 82 | _password => C4::Context->preference('SMSSendPassword'), | ||||
| 83 | ); | ||||
| 84 | |||||
| 85 | # Send a message | ||||
| 86 | my $sent = $sender->send_sms( to => $params->{'destination'}, | ||||
| 87 | text => $params->{'message'}, | ||||
| 88 | ); | ||||
| 89 | # warn 'failure' unless $sent; | ||||
| 90 | return $sent; | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | =head2 driver | ||||
| 94 | |||||
| 95 | =cut | ||||
| 96 | |||||
| 97 | sub driver { | ||||
| 98 | my $self = shift; | ||||
| 99 | |||||
| 100 | # return 'US::SprintPCS'; | ||||
| 101 | return C4::Context->preference('SMSSendDriver'); | ||||
| 102 | |||||
| 103 | } | ||||
| 104 | |||||
| 105 | 1 | 2µs | 1; | ||
| 106 | |||||
| 107 | __END__ |