File Coverage

blib/lib/Net/TextMessage/Canada.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Net::TextMessage::Canada;
2 1     1   23087 use 5.006;
  1         3  
  1         38  
3 1     1   2187 use Moose;
  0            
  0            
4              
5             =head1 NAME
6            
7             Net::TextMessage::Canada - determine the email address for a mobile phone
8            
9             =cut
10              
11             our $VERSION = '0.02';
12              
13             =head1 SYNOPSIS
14            
15             This module will determine the email address for a canadian mobile phone
16             from the phone number and mobile provider.
17            
18             use Net::TextMessage::Canada;
19              
20             my $ntmc = Net::TextMessage::Canada->new;
21              
22             # Get the list of providers and their nice names
23             my $providers = $ntmc->providers;
24             for (@$providers) { ... }
25              
26             # Convert a mobile phone provider + phone number into an email
27             my $email = $ntmc->to_email( $provider, $mobile_number );
28              
29             =head1 DESCRIPTION
30              
31             This module provides an easy interface to map a mobile phone to an
32             email address to send them a text message.
33              
34             If this list becomes out of date, please send me updated details.
35              
36             =head2 IMPORTANT NOTE
37              
38             The functionality of the email-to-SMS gateway is carrier dependent. That is to say: some carriers that appreciate you as a human being make it work seamlessly. Other carriers that want to maximize their wallets may make receiving these messages expensive and awkward. YMMV, IANAL, see store for details.
39              
40             =cut
41            
42             has 'provider_map' => (is => 'ro', isa => 'HashRef', lazy_build => 1);
43              
44             =head1 METHODS
45            
46             =head2 $ntmc->providers();
47            
48             This method returns an arrayref containing a hashref for each
49             mobile provider in Canada. The hashref has two keys: id and name
50             that contain a short id and the full name of the mobile provider.
51            
52             =cut
53              
54             sub providers {
55             my $self = shift;
56             my $map = $self->provider_map;
57             return [ map { {id => $_, name => $map->{$_}{name}} }
58             sort { $map->{$a}{name} cmp $map->{$b}{name} } keys %$map ];
59             }
60              
61             =head2 $ntmc->to_email( $provider, $number );
62            
63             This method returns the email address for the given number and
64             mobile provider.
65            
66             =cut
67              
68             sub to_email {
69             my $self = shift;
70             my $provider = shift;
71             my $number = shift;
72            
73             my $map = $self->provider_map;
74             my $p = $map->{$provider};
75             die "$provider is not a valid provider!" unless defined $p;
76              
77             return join '@', $number, $p->{domain};
78             }
79              
80              
81             sub _build_provider_map {
82             my $self = shift;
83             return {
84             bell => {
85             name => 'Bell Canada',
86             domain => 'txt.bell.ca',
87             },
88             rogers => {
89             name => 'Rogers Wireless',
90             domain => 'pcs.rogers.com',
91             },
92             fido => {
93             name => 'Fido',
94             domain => 'fido.ca',
95             },
96             telus => {
97             name => 'Telus',
98             domain => 'msg.telus.com',
99             },
100             virgin => {
101             name => 'Virgin Mobile',
102             domain => 'vmobile.ca',
103             },
104             pcmobile => {
105             name => 'PC Mobile',
106             domain => 'mobiletxt.ca',
107             },
108             koodo => {
109             name => 'Koodo Mobile',
110             domain => 'msg.koodomobile.com',
111             },
112             sasktel => {
113             name => 'SaskTel',
114             domain => 'sms.sasktel.com',
115             },
116             };
117             }
118              
119             =head1 AUTHOR
120            
121             Luke Closs, C<< <cpan at 5thplane.com> >>
122            
123             =head1 BUGS
124            
125             Please report any bugs or feature requests to C<bug-net-textmessage-canada at rt.cpan.org>, or through
126             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-TextMessage-Canada>.
127             I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
128            
129             =head1 SUPPORT
130            
131             You can find documentation for this module with the perldoc command.
132            
133             perldoc Net::TextMessage::Canada
134            
135             You can also look for information at:
136            
137             =over 4
138            
139             =item * RT: CPAN's request tracker
140            
141             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-TextMessage-Canada>
142            
143             =item * AnnoCPAN: Annotated CPAN documentation
144            
145             L<http://annocpan.org/dist/Net-TextMessage-Canada>
146            
147             =item * CPAN Ratings
148            
149             L<http://cpanratings.perl.org/d/Net-TextMessage-Canada>
150            
151             =item * Search CPAN
152            
153             L<http://search.cpan.org/dist/Net-TextMessage-Canada/>
154            
155             =back
156            
157             =head1 ACKNOWLEDGEMENTS
158            
159             Thanks to Canada's wonderful mobile phone companies for providing this service.
160            
161             =head1 COPYRIGHT & LICENSE
162            
163             Code is copyright 2009 Luke Closs, all rights reserved.
164             All company names and email domains are obviously owned by those companies.
165            
166             This program is free software; you can redistribute it and/or modify it
167             under the same terms as Perl itself.
168            
169             =cut
170              
171             __PACKAGE__->meta->make_immutable;
172             1;