File Coverage

blib/lib/SMS/Send/Test.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 4 4 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             package SMS::Send::Test;
2              
3             =pod
4              
5             =head1 NAME
6              
7             SMS::Send::Test - SMS::Send International-Class Testing Driver
8              
9             =head1 SYNOPSIS
10              
11             # Create a testing sender
12             my $send = SMS::Send->new( 'Test' );
13            
14             # Clear the message trap
15             $send->clear;
16            
17             # Send a message
18             $send->send_sms(
19             text => 'Hi there',
20             to => '+61 (4) 1234 5678',
21             );
22            
23             # Get the message from the trap
24             my @messages = $send->messages;
25              
26             =head1 DESCRIPTION
27              
28             L supports two classes of drivers.
29              
30             An international class named in the format C, which only
31             accept international numbers in C<+1 XXX XXXXX> format, and
32             regional-context drivers in the format C which will
33             also accept a non-leading-plus number in the format applicable within that
34             region (in the above case, Australia).
35              
36             L is the testing driver for the international class of
37             drivers. Except for the name, it is otherwise identical to
38             L.
39              
40             Its two roles are firstly to always exist (be installed) and secondly
41             to act as a "trap" for messages. Messages sent via SMS::Send::Test
42             always succeed, and the messages can be recovered for testing after
43             sending.
44              
45             Note that the trap is done on a per-driver-handle basis, and is not
46             shared between multiple driver handles.
47              
48             =cut
49              
50 3     3   2361 use 5.006;
  3         10  
  3         122  
51 3     3   17 use strict;
  3         6  
  3         103  
52 3     3   14 use SMS::Send::Driver ();
  3         45  
  3         64  
53              
54 3     3   15 use vars qw{$VERSION @ISA};
  3         6  
  3         242  
55             BEGIN {
56 3     3   7 $VERSION = '0.06';
57 3         665 @ISA = 'SMS::Send::Driver';
58             }
59              
60              
61              
62              
63              
64             #####################################################################
65             # Constructor
66              
67             sub new {
68 3     3 1 4 my $class = shift;
69              
70             # Create the object
71 3         13 my $self = bless {
72             messages => [ ],
73             }, $class;
74              
75 3         11 $self;
76             }
77              
78             sub send_sms {
79 1     1 1 2 my $self = shift;
80 1         10 my $messages = $self->{messages};
81 1         3 push @$messages, [ @_ ];
82 1         3 return 1;
83             }
84              
85             =pod
86              
87             =head1 METHODS
88              
89             SMS::Send::Test inherits all the methods of the parent L
90             class, and adds the following.
91              
92             =head2 messages
93              
94             The C method retrieves as a list all of the messages in the
95             message trap.
96              
97             =cut
98              
99             sub messages {
100 1     1 1 597 my $self = shift;
101 1         2 return @{$self->{messages}};
  1         5  
102             }
103              
104             =pod
105              
106             =head2 clear
107              
108             The C method clears the message trap. This should be done before
109             each chunk of test code to ensure you are starting from a known state.
110              
111             Returns true as a convenience.
112             =cut
113              
114             sub clear {
115 3     3 1 2554 my $self = shift;
116 3         9 $self->{messages} = [];
117 3         17 return 1;
118             }
119              
120             1;
121              
122             =pod
123              
124             =head1 SUPPORT
125              
126             Bugs should be reported via the CPAN bug tracker at
127              
128             L
129              
130             For other issues, contact the author.
131              
132             =head1 AUTHOR
133              
134             Adam Kennedy Eadamk@cpan.orgE
135              
136             =head1 COPYRIGHT
137              
138             Copyright 2005 - 2011 Adam Kennedy.
139              
140             This program is free software; you can redistribute
141             it and/or modify it under the same terms as Perl itself.
142              
143             The full text of the license can be found in the
144             LICENSE file included with this module.
145              
146             =cut