AnyEvent-XMPP

 view release on metacpan or  search on metacpan

lib/AnyEvent/XMPP/Connection.pm  view on Meta::CPAN

   });
   $con->send_message ("Test message!" => 'elmex@jabber.org', undef, 'chat');

=item presence_xml => $node

This event is sent when a presence stanza is received. C<$node> is the
L<AnyEvent::XMPP::Node> object that represents the <presence> tag.

If you want to overtake the handling of the stanza, see C<iq_xml>
below.

=item message_xml => $node

This event is sent when a message stanza is received. C<$node> is the
L<AnyEvent::XMPP::Node> object that represents the <message> tag.

If you want to overtake the handling of the stanza, see C<iq_xml>
below.

=item iq_xml => $node

This event is emitted when a iq stanza arrives. C<$node> is the
L<AnyEvent::XMPP::Node> object that represents the <iq> tag.

If you want to overtake the handling of a stanza, you should
register a callback for the C<before_iq_xml> event and call the
C<stop_event> method. See also L<Object::Event>. This is an example:

   $con->reg_cb (before_iq_xml => sub {
      my ($con, $node) = @_;

      if (...) {
         # and stop_event will stop internal handling of the stanza:
         $con->stop_event;
      }
   });

Please note that if you overtake handling of a stanza none of the internal
handling of that stanza will be done. That means you won't get events
like C<iq_set_request_xml> anymore.

=item iq_set_request_xml => $node, $rhandled

=item iq_get_request_xml => $node, $rhandled

These events are sent when an iq request stanza of type 'get' or 'set' is received.
C<$type> will either be 'get' or 'set' and C<$node> will be the L<AnyEvent::XMPP::Node>
object of the iq tag.

To signal the stanza was handled set the scalar referenced by C<$rhandled>
to a true value.
If the stanza was not handled an error iq will be generated.

=item iq_result_cb_exception => $exception

If the C<$result_cb> of a C<send_iq> operation somehow threw a exception
or failed this event will be generated.

=item send_iq_hook => $id, $type, $attrs, \@create_cb

This event lets you add any desired number of additional create callbacks
to a IQ stanza that is about to be sent.

C<$id>, C<$type> are described in the documentation of C<send_iq> of
L<AnyEvent::XMPP::Writer>. C<$attrs> is the hashref to the C<%attrs> hash that can
be passed to C<send_iq> and also has the exact same semantics as described in
the documentation of C<send_iq>.

You can push values into C<create_cb> (as documented for C<send_iq>), for
example a callback that fills the IQ.

Example:

   # this appends a <test/> element to all outgoing IQs
   # and also a <test2/> element to all outgoing IQs
   $con->reg_cb (send_iq_hook => sub {
      my ($con, $id, $type, $attrs, $create_cb) = @_;
      push @$create_cb, sub {
         my $w = shift; # $w is a XML::Writer instance
         $w->emptyTag ('test');
      };
      push @$create_cb, {
         node => { name => "test2" } # see also simxml() defined in AnyEvent::XMPP::Util
      };
   });

=item send_message_hook => $id, $to, $type, $attrs, \@create_cb

This event lets you add any desired number of additional create callbacks
to a message stanza that is about to be sent.

C<$id>, C<$to>, C<$type> and the hashref C<$attrs> are described in the documentation
for C<send_message> of L<AnyEvent::XMPP::Writer> (C<$attrs> is C<%attrs> there).

To actually append something you need to push into C<create_cb> as described in
the C<send_iq_hook> event above.

=item send_presence_hook => $id, $type, $attrs, \@create_cb

This event lets you add any desired number of additional create callbacks
to a presence stanza that is about to be sent.

C<$id>, C<$type> and the hashref C<$attrs> are described in the documentation
for C<send_presence> of L<AnyEvent::XMPP::Writer> (C<$attrs> is C<%attrs> there).

To actually append something you need to push into C<create_cb> as described in
the C<send_iq_hook> event above.

=back

=head1 AUTHOR

Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>

=head1 CONTRIBUTORS

melo - minor fixes

=head1 COPYRIGHT & LICENSE

Copyright 2007, 2008 Robin Redeker, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1; # End of AnyEvent::XMPP



( run in 1.086 second using v1.01-cache-2.11-cpan-39bf76dae61 )