POE::Component::Jabber::ProtocolFactory - POE::Component::Jabber::ProtocolFactory documentation


POE-Component-Jabber documentation Contained in the POE-Component-Jabber distribution.

Index


Code Index:

NAME

Top

POE::Component::Jabber::ProtocolFactory

SYNOPSIS

Top

PCJ::ProtocolFactory is a protected helper class used to instantiate specific Protocols based on exported constants

DESCRIPTION

Top

PCJ internally uses PCJ::ProtocolFactory to turn the ConnectionType argument into a Protocol object used to implement the various supported dialects. This is why the accepted arguments are exported as constants upon use.

FUNCTIONS

Top

By default no functions are exported beyond the accepted arguments. Only a package function is available:

get_guts [Protected]

get_guts takes a single argument and that is a defined constant exported by this module. It returns a PCJ::Protocol object.

See PCJ::Protocol for details on its methods and implementing different Protocols.

CONSTANTS

Top

Below are the constants that are exported. Their names are rather self-explanatory:

XMPP
LEGACY
JABBERD14_COMPONENT
JABBERD20_COMPONENT

NOTES

Top

All supported Protocol types are implemented herein. get_guts will confess if it receives an invalid argument.

AUTHOR

Top

(c) Copyright 2007-2009 Nicholas Perez. Released under the GPL.


POE-Component-Jabber documentation Contained in the POE-Component-Jabber distribution.

package POE::Component::Jabber::ProtocolFactory;
use warnings;
use strict;

use Carp;
use POE::Component::Jabber::XMPP;
use POE::Component::Jabber::Legacy;
use POE::Component::Jabber::J14;
use POE::Component::Jabber::J2;

use constant
{
	'JABBERD14_COMPONENT'	=> 0,
	'LEGACY'				=> 1,
	'JABBERD20_COMPONENT'	=> 2,
	'XMPP'					=> 4,
};

use base('Exporter');
our @EXPORT = qw/ JABBERD14_COMPONENT JABBERD20_COMPONENT LEGACY XMPP /;

our $VERSION = '3.00';

sub get_guts($)
{
	my $type = shift(@_);
	
	Carp::confess('No argument provided') if not defined($type);
	Carp::confess('Invalid Helper type: ' . $type) if $type =~ /\D+/;

	if($type == +XMPP)
	{
		return POE::Component::Jabber::XMPP->new();
	
	} elsif ($type == +LEGACY) {

		return POE::Component::Jabber::Legacy->new();
	
	} elsif ($type == +JABBERD14_COMPONENT) {

		return POE::Component::Jabber::J14->new();

	} elsif ($type == +JABBERD20_COMPONENT) {

		return POE::Component::Jabber::J2->new();
	
	} else {

		Carp::confess('Unknown Helper type: ' . $type);
	}
}

1;

__END__