AnyEvent-XMPP

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    to file a bugreport to them, one hack less in AnyEvent::XMPP means more
    time for bug fixing and improvements and new features.

Why (yet) another XMPP module?
    The main outstanding feature of this module in comparison to the other
    XMPP (aka Jabber) modules out there is the support for AnyEvent.
    AnyEvent permits you to use this module together with other I/O event
    based programs and libraries (ie. Gtk2 or Event).

    The other modules could often only be integrated in those applications
    or libraries by using threads. I decided to write this module because I
    think CPAN lacks an event based XMPP module. Threads are unfortunately
    not an alternative in Perl at the moment due the limited threading
    functionality they provide and the global speed hit. I also think that a
    simple event based I/O framework might be a bit easier to handle than
    threads.

    Another thing was that I didn't like the APIs of the other modules. In
    AnyEvent::XMPP I try to provide low level modules for speaking XMPP as
    defined in RFC 3920 and RFC 3921 (see also AnyEvent::XMPP::Connection
    and AnyEvent::XMPP::IM::Connection). But I also try to provide a high
    level API for easier usage for instant messaging tasks and clients (eg.
    AnyEvent::XMPP::Client).

Supported extensions
    See AnyEvent::XMPP::Ext for a list.

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

fixing and improvements and new features.

=head1 Why (yet) another XMPP module?

The main outstanding feature of this module in comparison to the other XMPP
(aka Jabber) modules out there is the support for L<AnyEvent>. L<AnyEvent>
permits you to use this module together with other I/O event based programs and
libraries (ie. L<Gtk2> or L<Event>).

The other modules could often only be integrated in those applications or
libraries by using threads. I decided to write this module because I think CPAN
lacks an event based XMPP module. Threads are unfortunately not an alternative
in Perl at the moment due the limited threading functionality they provide and
the global speed hit. I also think that a simple event based I/O framework
might be a bit easier to handle than threads.

Another thing was that I didn't like the APIs of the other modules. In
L<AnyEvent::XMPP> I try to provide low level modules for speaking XMPP as defined
in RFC 3920 and RFC 3921 (see also L<AnyEvent::XMPP::Connection> and
L<AnyEvent::XMPP::IM::Connection>). But I also try to provide a high level API for
easier usage for instant messaging tasks and clients (eg. L<AnyEvent::XMPP::Client>).

=head1 Supported extensions

See L<AnyEvent::XMPP::Ext> for a list.

lib/AnyEvent/XMPP/Ext/MUC/Message.pm  view on Meta::CPAN

   my ($self, $room) = @_;

   if ($room) {
      $self->{room} = $room;
      $self->{connection} = $self->{room}->{connection};
   }

   my @add;
   push @add, (subject => $self->{subjects})
      if %{$self->{subjects} || {}};
   push @add, (thread => $self->thread)
      if $self->thread;
   push @add, (from => $self->from)
      if defined $self->from;

   $self->{connection}->send_message (
      $self->to, $self->type, $self->{create_cbs},
      body => $self->{bodies},
      @add
   );
}

lib/AnyEvent/XMPP/IM/Message.pm  view on Meta::CPAN

sub from_node {
   my ($self, $node) = @_;
   $self->{node} = $node;

   $self->fetch_delay_from_node ($node);

   my $id       = $node->attr ('id');
   my $from     = $node->attr ('from');
   my $to       = $node->attr ('to');
   my $type     = $node->attr ('type');
   my ($thread) = $node->find_all ([qw/client thread/]);

   my %bodies;
   my %subjects;

   $bodies{$_->attr ('lang') || ''} = $_->text
      for $node->find_all ([qw/client body/]);
   $subjects{$_->attr ('lang') || ''} = $_->text
      for $node->find_all ([qw/client subject/]);

   $self->{id}       = $id;
   $self->{from}     = $from;
   $self->{to}       = $to;
   $self->{type}     = $type;
   $self->{thread}   = $thread;
   $self->{bodies}   = \%bodies;
   $self->{subjects} = \%subjects;
}

sub to_string {
   my ($self) = @_;
   $self->any_body
}

=item B<id ([$msg_id])>

lib/AnyEvent/XMPP/IM/Message.pm  view on Meta::CPAN

=cut

sub send {
   my ($self, $connection) = @_;

   $self->{connection} = $connection if $connection;

   my @add;
   push @add, (subject => $self->{subjects})
      if %{$self->{subjects} || {}};
   push @add, (thread => $self->thread)
      if $self->thread;
   push @add, (from => $self->from)
      if $self->from;

   push @add, (id => $self->id)
      if $self->id;

   $self->{connection}->send_message (
      $self->to, $self->type, $self->{create_cbs},
      body => $self->{bodies},
      @add

lib/AnyEvent/XMPP/IM/Message.pm  view on Meta::CPAN


=cut

sub type {
   my ($self, $type) = @_;
   $self->{type} = $type
      if defined $type;
   $self->{type}
}

=item B<thread ([$thread])>

This method returns the thread id of this message,
which might be undefined.

If you want to set the threadid simply pass the C<$thread>
argument.

=cut

sub thread {
   my ($self, $thread) = @_;
   $self->{thread} = $thread
      if defined $thread;
   $self->{thread}
}

=item B<lang ([$lang])>

This returns the default language tag of this message,
which can be undefined.

To set the language tag pass the C<$lang> argument, which
should be the new default language tag.

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

the keys will be interpreted as language identifiers for the xml:lang attribute
of each body element. If one of these keys is the empty string '' no xml:lang attribute
will be generated for it. The values will be the character content of the body tags.

If C<%attrs> contains a 'subject' key: a child xml tag with that name will be generated
with the value as content. If the value of the 'subject' key is an hash reference
the keys will be interpreted as language identifiers for the xml:lang attribute
of each subject element. If one of these keys is the empty string '' no xml:lang attribute
will be generated for it. The values will be the character content of the subject tags.

If C<%attrs> contains a 'thread' key: a child xml tag with that name will be generated
and the value will be the character content.

Please note that all attribute values and character data will be filtered
by C<filter_xml_chars> (see also L<AnyEvent::XMPP::Util>).

=cut

sub send_message {
   my ($self, $id, $to, $type, $create_cb, %attrs) = @_;

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

   my $w = $self->{writer};
   $w->addPrefix (xmpp_ns ('client'), '');

   my @add;
   push @add, (id => $id) if defined $id;

   $type ||= 'chat';

   my %fattrs =
      map { $_ => $attrs{$_} }
         grep { my $k = $_; not grep { $k eq $_ } qw/subject body thread/ }
            keys %attrs;

   if (defined $create_cb) {
      $w->startTag ([xmpp_ns ('client'), 'message'], @add, to => $to, type => $type, %fattrs);
      _generate_key_xmls ($w, subject => $attrs{subject})    if defined $attrs{subject};
      _generate_key_xmls ($w, body => $attrs{body})          if defined $attrs{body};
      _generate_key_xml ($w, thread => $attrs{thread})       if defined $attrs{thread};
      $create_cb->($w);
      $w->endTag;
   } else {
      if (exists $attrs{subject} or $attrs{body} or $attrs{thread}) {
         $w->startTag ([xmpp_ns ('client'), 'message'], @add, to => $to, type => $type, %fattrs);
         _generate_key_xmls ($w, subject => $attrs{subject})    if defined $attrs{subject};
         _generate_key_xmls ($w, body => $attrs{body})          if defined $attrs{body};
         _generate_key_xml ($w, thread => $attrs{thread})       if defined $attrs{thread};
         $w->endTag;
      } else {
         $w->emptyTag ([xmpp_ns ('client'), 'message'], @add, to => $to, type => $type, %fattrs);
      }
   }

   $self->flush;
}




( run in 0.537 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )