GSM::SMS::Transport::Transport - Base class for transports


GSM-SMS documentation Contained in the GSM-SMS distribution.

Index


Code Index:

NAME

Top

GSM::SMS::Transport::Transport - Base class for transports

DESCRIPTION

Top

This class is a base class for all transports, i.e. all transports must inherit from this class.

METHODS

Top

new - Constructor
has_valid_route - Do we have a valid route for this msisdn
	$transport->has_valid_route( $msisdn );

ABSTRACT METHODS

Top

send - Send a (PDU encoded) message
receive - Receive a PDU encoded message


	$PDU = $transport->receive();

close - Close the transport
ping - return an informative string on success
get_info - Returns info on the transport
DESTROY - The destructor

AUTHOR

Top

Johan Van den Brande <johan@vandenbrande.com>


GSM-SMS documentation Contained in the GSM-SMS distribution.
package GSM::SMS::Transport::Transport;
use strict;

use vars qw( $VERSION $AUTOLOAD );

use Carp;

$VERSION = "0.161";

sub new 
{
	my ($proto, %args) = @_;
	my $class = ref($proto) || $proto;

	my $self = {
		_name			=> $args{-name} || croak("missing name"),
		_originator		=> $args{-originator} || 'GSM::SMS',
		_match			=> $args{-match} 	|| croak("missing match regexp")
	};

	bless($self, $class);
	return $self;
}


sub has_valid_route {
	my ($self, $msisdn) = @_;

	foreach my $route ( split /,/, $self->get_match() ) {
		return -1 if $msisdn =~ /$route/;
	}
	return 0;
}

sub METHOD::ABSTRACT
{
	my ($self) = @_;
	my $object_class = ref($self);
	my ($file, $line, $method) = (caller(1))[1..3];
	die "Call to abstract method ${method} at $file, line $line\n";
}

sub send {	ABSTRACT METHOD @_ }


sub receive {	ABSTRACT METHOD @_ }	

sub close {	ABSTRACT METHOD @_ }

sub ping {	ABSTRACT METHOD @_ }

sub get_info { ABSTRACT METHOD @_ }

sub DESTROY {}

sub AUTOLOAD
{
	my ($self, $newval) = @_;

	# Handle get_... method
	$AUTOLOAD =~ /.*::get(_\w+)/
		and $self->_accessible($1, 'read')
		and return $self->{$1};

	# Handle set_... method
	$AUTOLOAD =~ /.*::set(_\w+)/
		and $self->_accessible($1, 'write')
		and do { $self->{$1} = $newval; return; };

	# Oops ... a mistake
	croak "No such method: $AUTOLOAD";
}

1;
__END__