GSM::SMS::TransportRouterFactory - router object factory


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

Index


Code Index:

NAME

Top

GSM::SMS::TransportRouterFactory - router object factory

DESCRIPTION

Top

This class instantiates a TransportRouter object of a defined type, if available.

METHODS

Top

factory - Return the router of the specific type

AUTHOR

Top

Johan Van den Brande <johan@vandenbrande.com>


GSM-SMS documentation Contained in the GSM-SMS distribution.
package GSM::SMS::TransportRouterFactory;
use strict;
use vars qw( $VERSION );

use Log::Agent;

sub factory {
	my ($proto, %arg) = @_;

	my $router_type = $arg{-type} || logcroak "'-type' is mandatory";
	my $router_class = 'GSM::SMS::TransportRouter::' . $router_type;

	my $transport = $arg{-transport};

	unless ( eval "require $router_class" )
	{
		my $msg = "the requested router class '$router_class' is not available : $@";
		logdbg "debug", $msg;
		logcroak $msg;
	}

	my $router_instance = $router_class->new( -transport => $transport );
	unless ( $router_instance )
	{
		logdbg "debug", "error loading router ($router_class)";
		return undef;
	}

	return $router_instance;
}

1;

__END__