Net-TextMessage-Canada
view release on metacpan or search on metacpan
lib/Net/TextMessage/Canada.pm view on Meta::CPAN
package Net::TextMessage::Canada;
use 5.006;
use Moose;
=head1 NAME
Net::TextMessage::Canada - determine the email address for a mobile phone
=cut
our $VERSION = '0.02';
=head1 SYNOPSIS
This module will determine the email address for a canadian mobile phone
from the phone number and mobile provider.
use Net::TextMessage::Canada;
my $ntmc = Net::TextMessage::Canada->new;
# Get the list of providers and their nice names
my $providers = $ntmc->providers;
for (@$providers) { ... }
# Convert a mobile phone provider + phone number into an email
my $email = $ntmc->to_email( $provider, $mobile_number );
=head1 DESCRIPTION
This module provides an easy interface to map a mobile phone to an
email address to send them a text message.
If this list becomes out of date, please send me updated details.
=head2 IMPORTANT NOTE
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 exp...
=cut
has 'provider_map' => (is => 'ro', isa => 'HashRef', lazy_build => 1);
=head1 METHODS
=head2 $ntmc->providers();
This method returns an arrayref containing a hashref for each
mobile provider in Canada. The hashref has two keys: id and name
that contain a short id and the full name of the mobile provider.
=cut
sub providers {
my $self = shift;
my $map = $self->provider_map;
return [ map { {id => $_, name => $map->{$_}{name}} }
sort { $map->{$a}{name} cmp $map->{$b}{name} } keys %$map ];
}
=head2 $ntmc->to_email( $provider, $number );
This method returns the email address for the given number and
mobile provider.
=cut
sub to_email {
my $self = shift;
my $provider = shift;
my $number = shift;
my $map = $self->provider_map;
my $p = $map->{$provider};
die "$provider is not a valid provider!" unless defined $p;
return join '@', $number, $p->{domain};
}
sub _build_provider_map {
my $self = shift;
return {
bell => {
name => 'Bell Canada',
domain => 'txt.bell.ca',
},
rogers => {
name => 'Rogers Wireless',
domain => 'pcs.rogers.com',
},
fido => {
name => 'Fido',
domain => 'fido.ca',
},
telus => {
name => 'Telus',
domain => 'msg.telus.com',
},
virgin => {
name => 'Virgin Mobile',
domain => 'vmobile.ca',
( run in 1.413 second using v1.01-cache-2.11-cpan-39bf76dae61 )