File Coverage

blib/lib/SMS/Handler/Invoke.pm
Criterion Covered Total %
statement 15 22 68.1
branch 0 2 0.0
condition 0 6 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 39 56.4


line stmt bran cond sub pod time code
1             package SMS::Handler::Invoke;
2              
3             require 5.005_62;
4              
5 1     1   80817 use Carp;
  1         3  
  1         75  
6 1     1   16 use strict;
  1         2  
  1         36  
7 1     1   5 use warnings;
  1         1  
  1         31  
8 1     1   4 use SMS::Handler;
  1         3  
  1         56  
9 1     1   5 use vars qw(@ISA);
  1         1  
  1         222  
10              
11             # $Id: Invoke.pm,v 1.2 2002/12/22 19:03:02 lem Exp $
12              
13             (our $VERSION = q$Revision: 1.2 $) =~ s/Revision //;
14              
15             our $Debug = 0;
16              
17             =pod
18              
19             =head1 NAME
20              
21             SMS::Handler::Invoke - Invoke a user-supplied method on a SMA
22              
23             =head1 SYNOPSIS
24              
25             use SMS::Handler::Invoke;
26              
27             my $h = new SMS::Handler::Invoke sub { ... };
28              
29             $h->handle({ ... });
30              
31             =head1 DESCRIPTION
32              
33             Invokes the method passed as the only argument to the C<-Enew()>
34             method, passing the SMS sent to its C<-Ehandle()> method. This is
35             useful to implement quick transforms in the source or destination
36             numbers, or implementing custom message handling.
37              
38             The supplied sub will receive as its only argument, the SMS reference
39             passed to the C<-Ehandle()> method. Its return value will be
40             returned by the C<-Ehandle()> method.
41              
42             =over 4
43              
44             =item C<-Enew()>
45              
46             Creates a new C object.
47              
48             =cut
49              
50             sub new
51             {
52 0     0 1   my $name = shift;
53 0   0       my $class = ref($name) || $name;
54 0           my $method = shift;
55              
56 0 0 0       if (defined $method and ref($method) eq 'CODE')
57             {
58 0           return bless { sub => $method }, $class;
59             }
60              
61 0           return undef;
62             }
63              
64             =pod
65              
66             =item C<-Ehandle()>
67              
68             Invokes the user supplied sub on the SMS reference. Returns whatever
69             the user-supplied sub returns.
70              
71             =cut
72              
73 0     0 1   sub handle { return $_[0]->{sub}->($_[1]); }
74              
75             1;
76             __END__