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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
package AnyEvent::XMPP::IM::Presence;
use strict;
use AnyEvent::XMPP::Util;
use AnyEvent::XMPP::IM::Message;
use AnyEvent::XMPP::IM::Delayed;
our @ISA = qw/AnyEvent::XMPP::IM::Delayed/;
=head1 NAME
AnyEvent::XMPP::IM::Presence - XMPP presence
=head1 SYNOPSIS
=head1 DESCRIPTION
This module represents an XMPP presence. It stores
the full JID of the contact, the show value, status value
and priority.
L<AnyEvent::XMPP::IM::Presence> is derived from L<AnyEvent::XMPP::IM::Delayed>,
use the interface described there to find out whether this presence was delayed.
=head1 METHODS
=over 4
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
bless { @_ }, $class;
}
sub clone {
my ($self) = @_;
my $p = $self->new (connection => $self->{connection});
$p->{$_} = $self->{$_} for qw/show jid priority status/;
$p
}
sub update {
my ($self, $node) = @_;
$self->fetch_delay_from_node ($node);
my $type = $node->attr ('type');
my ($show) = $node->find_all ([qw/client show/]);
my ($priority) = $node->find_all ([qw/client priority/]);
my %stati;
$stati{$_->attr ('lang') || ''} = $_->text
for $node->find_all ([qw/client status/]);
my $old = $self->clone;
$self->{show} = $show ? $show->text : undef;
$self->{priority} = $priority ? $priority->text : undef;
$self->{status} = \%stati;
$self->{type} = $type;
$old
}
=item B<jid>
Returns the full JID of this presence.
=cut
sub jid { $_[0]->{jid} }
=item B<priority>
Returns the priority of this presence.
=cut
sub priority { $_[0]->{priority} }
=item B<status_all_lang>
Returns all language tags of available status descriptions.
See also L<status>.
=cut
sub status_all_lang {
my ($self, $jid) = @_;
keys %{$self->{status} || []}
}
=item B<show>
Returns the show value of this presence, which is one of:
'away', 'chat', 'dnd', 'xa'
or the empty string if the presence is 'available'.
=cut
sub show { $_[0]->{show} }
=item B<status ([$lang])>
Returns the presence description. C<$lang> is optional can should be one of
the tags returned by C<status_all_lang>.
=cut
sub status {
my ($self, $lang) = @_;
if (defined $lang) {
return $self->{status}->{$lang}
} else {
return $self->{status}->{''}
if defined $self->{status}->{''};
return $self->{status}->{en}
if defined $self->{status}->{en};
}
undef
}
=item B<make_message (%args)>
Returns a L<AnyEvent::XMPP::IM::Message> object with the to field set to
this presence full JID.
C<%args> are further arguments to the constructor of the message.
=cut
sub message_class { 'AnyEvent::XMPP::IM::Message' }
sub make_message {
my ($self, %args) = @_;
$self->message_class ()->new (
connection => $self->{connection},
to => $self->jid,
%args
);
}
sub debug_dump {
my ($self) = @_;
printf " * %-30s [%-5s] (%3d) {%s}\n",
$self->jid,
$self->show || '',
$self->priority || 0,
$self->status || '',
}
=back
=head1 AUTHOR
Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
=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;
|