package Net::SMS::WAY2SMS; use strict; use warnings; use WWW::Mechanize; use Compress::Zlib; use Carp qw( croak ); =head1 NAME Net::SMS::WAY2SMS - The great new Net::SMS::WAY2SMS! =head1 VERSION Version 0.01 =cut our $VERSION = '0.01'; =head1 SYNOPSIS Perl module to send sms using way2sms for any mobile/s in India Usage: use Net::SMS::WAY2SMS; my $s = Net::SMS::WAY2SMS->new( 'user' => 'xyz' , 'password' => 'xyzpassword', 'mob'=>['12343567890', '1111111111'] ); $s->send('Hello World'); =head2 new Creates a new instance Args: 'user' [required] 'password' [required] 'mob' [array reference of mobile numbers] - [required] =cut sub new { my $class = shift; my %args = @_; my $self = {}; croak 'Username, password and mobile number are mandatory' if(!$args{'user'} || !$args{'password'} || !$args{'mob'}); $self->{'user'} = $args{'user'}; $self->{'password'} = $args{'password'}; $self->{'mob'} = ref $args{'mob'} eq 'ARRAY' ? $args{'mob'} : [$args{'mob'}]; $self->{'debug'} = $args{'debug'} || 0; bless $self, $class; return $self; } =head2 getMob Returns the mobile number of the instance =cut sub getMob { return @{$_[0]->{'mob'}}; } =head2 send send the data to way2sms.com =cut sub send { my ($self, $msg) = @_; my @mobs = $self->getMob(); return croak "mobile numbers and sms text are missing" unless scalar @mobs || $msg; print length($msg)."\n" if($self->{'debug'}); $msg = $msg."\n\n\n\n\n" if(length($msg) < 135); my $mech = WWW::Mechanize->new(); $mech->get("http://wwwl.way2sms.com/content/index.html"); unless($mech->success()) { die 'unable to login to way2sms'; } my $dest = $mech->response->content; my $header = $mech->response->header("Content-Encoding"); print "Fetching...\n" if($self->{'debug'}); $mech->update_html($self->_getgzip($dest)) if($header && $header eq "gzip"); $dest =~ s/