ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/IM/Presence.pm
Revision: 1.6
Committed: Thu Jul 5 20:26:00 2007 UTC (19 years, 4 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -1 lines
Log Message:
fixed some more typos

File Contents

# Content
1 package Net::XMPP2::IM::Presence;
2 use strict;
3 use Net::XMPP2::Util;
4 use Net::XMPP2::IM::Message;
5
6 =head1 NAME
7
8 Net::XMPP2::IM::Presence - XMPP presence
9
10 =head1 SYNOPSIS
11
12 =head1 DESCRIPTION
13
14 This module represents an XMPP presence. It stores
15 the full JID of the contact, the show value, status value
16 and priority.
17
18 =head1 METHODS
19
20 =over 4
21
22 =cut
23
24 sub new {
25 my $this = shift;
26 my $class = ref($this) || $this;
27 bless { @_ }, $class;
28 }
29
30 sub clone {
31 my ($self) = @_;
32 my $p = $self->new (connection => $self->{connection});
33 $p->{$_} = $self->{$_} for qw/show jid priority status/;
34 $p
35 }
36
37 sub update {
38 my ($self, $node) = @_;
39
40 my $type = $node->attr ('type');
41 my ($show) = $node->find_all ([qw/client show/]);
42 my ($priority) = $node->find_all ([qw/client priority/]);
43
44 my %stati;
45 $stati{$_->attr ('lang') || ''} = $_->text
46 for $node->find_all ([qw/client status/]);
47
48 my $old = $self->clone;
49
50 $self->{show} = $show ? $show->text : undef;
51 $self->{priority} = $priority ? $priority->text : undef;
52 $self->{status} = \%stati;
53 $self->{type} = $type;
54
55 $old
56 }
57
58 =item B<jid>
59
60 Returns the full JID of this presence.
61
62 =cut
63
64 sub jid { $_[0]->{jid} }
65
66 =item B<priority>
67
68 Returns the priority of this presence.
69
70 =cut
71
72 sub priority { $_[0]->{priority} }
73
74 =item B<status_all_lang>
75
76 Returns all language tags of available status descriptions.
77 See also L<status>.
78
79 =cut
80
81 sub status_all_lang {
82 my ($self, $jid) = @_;
83 keys %{$self->{status} || []}
84 }
85
86 =item B<show>
87
88 Returns the show value of this presence, which is one of:
89
90 'away', 'chat', 'dnd', 'xa'
91
92 or the empty string if the presence is 'available'.
93
94 =cut
95
96 sub show { $_[0]->{show} }
97
98 =item B<status ([$lang])>
99
100 Returns the presence description. C<$lang> is optional can should be one of
101 the tags returned by C<status_all_lang>.
102
103 =cut
104
105 sub status {
106 my ($self, $lang) = @_;
107
108 if (defined $lang) {
109 return $self->{status}->{$lang}
110 } else {
111 return $self->{status}->{''}
112 if defined $self->{status}->{''};
113 return $self->{status}->{en}
114 if defined $self->{status}->{en};
115 }
116
117 undef
118 }
119
120 =item B<make_message>
121
122 Returns a L<Net::XMPP2::IM::Message> object with the to field set to
123 this presence full JID.
124
125 =cut
126
127 sub make_message {
128 my ($self) = @_;
129 Net::XMPP2::IM::Message->new (
130 connection => $self->{connection},
131 to => $self->jid
132 );
133 }
134
135 sub debug_dump {
136 my ($self) = @_;
137 printf " * %-30s [%-5s] (%3d) {%s}\n",
138 $self->jid,
139 $self->show || '',
140 $self->priority || 0,
141 $self->status || '',
142 }
143
144 =back
145
146 =head1 AUTHOR
147
148 Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
149
150 =head1 COPYRIGHT & LICENSE
151
152 Copyright 2007 Robin Redeker, all rights reserved.
153
154 This program is free software; you can redistribute it and/or modify it
155 under the same terms as Perl itself.
156
157 =cut
158
159 1;