File: Items.pm

package info (click to toggle)
libanyevent-xmpp-perl 0.55-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 784 kB
  • ctags: 553
  • sloc: perl: 8,004; makefile: 13
file content (122 lines) | stat: -rw-r--r-- 2,202 bytes parent folder | download | duplicates (6)
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
package AnyEvent::XMPP::Ext::Disco::Items;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use strict;

=head1 NAME

AnyEvent::XMPP::Ext::Disco::Items - Service discovery items

=head1 SYNOPSIS

=head1 DESCRIPTION

This class represents the result of a disco items request
sent by a C<AnyEvent::XMPP::Ext::Disco> handler.

=head1 METHODS

=over 4

=cut

sub new {
   my $this = shift;
   my $class = ref($this) || $this;
   my $self = bless { @_ }, $class;
   $self->init;
   $self
}

=item B<xml_node ()>

Returns the L<AnyEvent::XMPP::Node> object of the IQ query.

=cut

sub xml_node {
   my ($self) = @_;
   $self->{xmlnode}
}

sub init {
   my ($self) = @_;
   my $node = $self->{xmlnode};
   return unless $node;

   my (@items) = $node->find_all ([qw/disco_items item/]);
   for (@items) {
      push @{$self->{items}}, {
         jid  => $_->attr ('jid'),
         name => $_->attr ('name'),
         node => $_->attr ('node'),
         xml_node => $_,
      };
   }
}

=item B<jid ()>

Returns the JID these items belong to.

=cut

sub jid { $_[0]->{jid} }

=item B<node ()>

Returns the node these items belong to (may be undef).

=cut

sub node { $_[0]->{node} }

=item B<items ()>

Returns a list of hashreferences which contain following keys:

  jid, name, node and xml_node

C<jid> contains the JID of the item.
C<name> contains the name of the item and might be undef.
C<node> contains the node id of the item and might be undef.
C<xml_node> contains the L<AnyEvent::XMPP::Node> object of the item
for further analyses.

=cut

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

=item B<debug_dump ()>

Prints these items to stdout for debugging.

=cut

sub debug_dump {
   my ($self) = @_;
   printf "ITEMS FOR %s (%s):\n", $self->jid, $self->node;
   for ($self->items) {
      printf "   - %-40s (%30s): %s\n", $_->{jid}, $_->{node}, $_->{name}
   }
   print "END ITEMS\n";
}

=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;