ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/lib/Net/XMPP2/IM/Connection.pm
Revision: 1.2
Committed: Sun Jan 28 21:52:19 2007 UTC (19 years, 8 months ago) by elmex
Branch: MAIN
Changes since 1.1: +50 -8 lines
Log Message:
further detail work and implemented extension enabling and extensions xep-0086
along with xml stanza error generation. implemented also first parts
of Net::XMPP2::IM::Connection.

File Contents

# User Rev Content
1 elmex 1.1 package Net::XMPP2::IM::Connection;
2     use warnings;
3     use strict;
4     use Net::XMPP2::Connection;
5     use Net::XMPP2::Namespaces qw/xmpp_ns/;
6     our @ISA = qw/Net::XMPP2::Connection/;
7    
8     =head1 NAME
9    
10     Net::XMPP2::Connection - A XML stream that implements the XMPP RFC 3920.
11    
12     =head1 SYNOPSIS
13    
14     use Net::XMPP2::Connection;
15    
16     my $con = Net::XMPP2::Connection->new;
17    
18     =head1 DESCRIPTION
19    
20     This module represents a XMPP instant messaging connection and implements
21     RFC 3921.
22    
23     This module is a subclass of C<Net::XMPP2::Connection> and inherits all methods.
24     For example C<reg_cb> and the stanza sending routines.
25    
26     For additional events that can be registered to look below in the EVENTS section.
27    
28     =head1 METHODS
29    
30     =cut
31    
32     sub new {
33     my $this = shift;
34     my $class = ref($this) || $this;
35     my $self = $class->SUPER::new (@_);
36 elmex 1.2
37     $self->{ext} = {}; # reserved for extensions
38    
39     $self->reg_cb (message => sub { $self->handle_message (@_); 1 });
40     $self->reg_cb (presence => sub { $self->handle_presence (@_); 1 });
41    
42 elmex 1.1 $self->reg_cb (stream_ready => sub {
43     my ($jid) = @_;
44 elmex 1.2 if ($self->features ()->find_all ([qw/session session/])) {
45     $self->send_session_iq;
46     } else {
47     $self->{session_active} = 1;
48     $self->send_presence ();
49 elmex 1.1 $self->event ('session_ready');
50 elmex 1.2 }
51 elmex 1.1 });
52     $self
53     }
54    
55 elmex 1.2 sub send_session_iq {
56     my ($self) = @_;
57    
58     $self->send_iq (set => sub {
59     my ($w) = @_;
60     $w->addPrefix (xmpp_ns ('session'), '');
61     $w->emptyTag ([xmpp_ns ('session'), 'session']);
62    
63     }, sub {
64     my ($node, $errnode, $errar) = @_;
65     if ($node) {
66     $self->{session_active} = 1;
67     $self->send_presence;
68     $self->event ('session_ready');
69     } else {
70     $self->event (session_error => $errnode, $errar);
71     }
72     });
73     }
74    
75     sub handle_presence {
76     my ($self) = @_;
77    
78     }
79    
80     sub handle_message {
81     my ($self) = @_;
82     }
83    
84 elmex 1.1 =head1 EVENTS
85    
86     These additional events can be registered on with C<reg_cb>:
87    
88     =over 4
89    
90     =item session_ready
91    
92 elmex 1.2 This event is generated when the session has been fully established and
93     can be used to send around messages and other stuff.
94    
95     =item session_error => $erriq, $errarr
96    
97     If an error happened during establishment of the session this
98     event will be generated. C<$erriq> is the L<Net::XMPP2::Node> object
99     of the error iq tag and C<$errar> is an error array as described in
100     L<Net::XMPP2::Connection::send_iq> for error responses for iq requests.
101 elmex 1.1
102     =back
103    
104     =head1 AUTHOR
105    
106     Robin Redeker, C<< <elmex at ta-sa.org> >>
107    
108     =head1 BUGS
109    
110     Please report any bugs or feature requests to
111     C<bug-net-xmpp2 at rt.cpan.org>, or through the web interface at
112     L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-XMPP2>.
113     I will be notified, and then you'll automatically be notified of progress on
114     your bug as I make changes.
115    
116     =head1 SUPPORT
117    
118     You can find documentation for this module with the perldoc command.
119    
120     perldoc Net::XMPP2
121    
122     You can also look for information at:
123    
124     =over 4
125    
126     =item * AnnoCPAN: Annotated CPAN documentation
127    
128     L<http://annocpan.org/dist/Net-XMPP2>
129    
130     =item * CPAN Ratings
131    
132     L<http://cpanratings.perl.org/d/Net-XMPP2>
133    
134     =item * RT: CPAN's request tracker
135    
136     L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-XMPP2>
137    
138     =item * Search CPAN
139    
140     L<http://search.cpan.org/dist/Net-XMPP2>
141    
142     =back
143    
144     =head1 ACKNOWLEDGEMENTS
145    
146     =head1 COPYRIGHT & LICENSE
147    
148     Copyright 2007 Robin Redeker, all rights reserved.
149    
150     This program is free software; you can redistribute it and/or modify it
151     under the same terms as Perl itself.
152    
153     =cut
154    
155    
156    
157     1; # End of Net::XMPP2