File: ProtocolFactory.pm

package info (click to toggle)
libpoe-component-jabber-perl 2.02-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 232 kB
  • ctags: 88
  • sloc: perl: 2,623; makefile: 44
file content (120 lines) | stat: -rw-r--r-- 2,292 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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,
};

require Exporter;
our $VERSION = '2.02';
our @ISA = qw/ Exporter /;
our @EXPORT = qw/ JABBERD14_COMPONENT JABBERD20_COMPONENT LEGACY XMPP /;

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__

=pod

=head1 NAME

POE::Component::Jabber::ProtocolFactory

=head1 SYNOPSIS

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

=head1 DESCRIPTION

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.

=head1 FUNCTIONS

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

=over 4 

=item 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.

=back

=head1 CONSTANTS

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

=over 4

=item XMPP


=item LEGACY


=item JABBERD14_COMPONENT


=item JABBERD20_COMPONENT

=back

=head1 NOTES

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

=head1 AUTHOR

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

=cut