| 1 |
elmex |
1.1 |
package Net::XMPP2::Disco::Items; |
| 2 |
|
|
use Net::XMPP2::Namespaces qw/xmpp_ns/; |
| 3 |
|
|
|
| 4 |
|
|
=head1 NAME |
| 5 |
|
|
|
| 6 |
|
|
Net::XMPP2::Disco::Items - Service discovery items |
| 7 |
|
|
|
| 8 |
|
|
=head1 SYNOPSIS |
| 9 |
|
|
|
| 10 |
|
|
|
| 11 |
|
|
=head1 DESCRIPTION |
| 12 |
|
|
|
| 13 |
|
|
This class represents the result of a disco items request |
| 14 |
|
|
sent by a C<Net::XMPP2::Disco> handler. |
| 15 |
|
|
|
| 16 |
|
|
=head1 METHODS |
| 17 |
|
|
|
| 18 |
|
|
=cut |
| 19 |
|
|
|
| 20 |
|
|
sub new { |
| 21 |
|
|
my $this = shift; |
| 22 |
|
|
my $class = ref($this) || $this; |
| 23 |
|
|
my $self = bless { @_ }, $class; |
| 24 |
|
|
$self->init; |
| 25 |
|
|
$self |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
=head2 xml_node () |
| 29 |
|
|
|
| 30 |
|
|
Returns the L<Net::XMPP2::Node> object of the IQ query. |
| 31 |
|
|
|
| 32 |
|
|
=cut |
| 33 |
|
|
|
| 34 |
|
|
sub xml_node { |
| 35 |
|
|
my ($self) = @_; |
| 36 |
|
|
$self->{xmlnode} |
| 37 |
|
|
} |
| 38 |
|
|
|
| 39 |
|
|
sub init { |
| 40 |
|
|
my ($self) = @_; |
| 41 |
|
|
my $node = $self->{xmlnode}; |
| 42 |
|
|
|
| 43 |
|
|
my (@items) = $node->find_all ([qw/disco_items item/]); |
| 44 |
|
|
for (@items) { |
| 45 |
|
|
push @{$self->{items}}, { |
| 46 |
|
|
jid => $_->attr ('jid'), |
| 47 |
|
|
name => $_->attr ('name'), |
| 48 |
|
|
node => $_->attr ('node'), |
| 49 |
|
|
xml_node => $_, |
| 50 |
|
|
}; |
| 51 |
|
|
} |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
=head2 jid () |
| 55 |
|
|
|
| 56 |
|
|
Returns the JID these items belong to. |
| 57 |
|
|
|
| 58 |
|
|
=cut |
| 59 |
|
|
|
| 60 |
|
|
sub jid { $_[0]->{jid} } |
| 61 |
|
|
|
| 62 |
|
|
=head2 node () |
| 63 |
|
|
|
| 64 |
|
|
Returns the node these items belong to (may be undef). |
| 65 |
|
|
|
| 66 |
|
|
=cut |
| 67 |
|
|
|
| 68 |
|
|
sub node { $_[0]->{node} } |
| 69 |
|
|
|
| 70 |
|
|
=head2 items () |
| 71 |
|
|
|
| 72 |
|
|
Returns a list of hashreferences which contain following keys: |
| 73 |
|
|
|
| 74 |
|
|
jid, name, node and xml_node |
| 75 |
|
|
|
| 76 |
|
|
C<jid> contains the JID of the item. |
| 77 |
|
|
C<name> contains the name of the item and might be undef. |
| 78 |
|
|
C<node> contains the node id of the item and might be undef. |
| 79 |
|
|
C<xml_node> contains the L<Net::XMPP2::Node> object of the item |
| 80 |
|
|
for further analyses. |
| 81 |
|
|
|
| 82 |
|
|
=cut |
| 83 |
|
|
|
| 84 |
|
|
sub items { |
| 85 |
|
|
my ($self) = @_; |
| 86 |
|
|
@{$self->{items}} |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
=head2 debug_dump () |
| 90 |
|
|
|
| 91 |
|
|
Prints these items to stdout for debugging. |
| 92 |
|
|
|
| 93 |
|
|
=cut |
| 94 |
|
|
|
| 95 |
|
|
sub debug_dump { |
| 96 |
|
|
my ($self) = @_; |
| 97 |
|
|
printf "ITEMS FOR %s (%s):\n", $self->jid, $self->node; |
| 98 |
|
|
for ($self->items) { |
| 99 |
|
|
printf " - %-40s (%30s): %s\n", $_->{jid}, $_->{node}, $_->{name} |
| 100 |
|
|
} |
| 101 |
|
|
print "END ITEMS\n"; |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
=head1 AUTHOR |
| 105 |
|
|
|
| 106 |
|
|
Robin Redeker, C<< <elmex at ta-sa.org> >> |
| 107 |
|
|
|
| 108 |
|
|
=head1 COPYRIGHT & LICENSE |
| 109 |
|
|
|
| 110 |
|
|
Copyright 2007 Robin Redeker, all rights reserved. |
| 111 |
|
|
|
| 112 |
|
|
This program is free software; you can redistribute it and/or modify it |
| 113 |
|
|
under the same terms as Perl itself. |
| 114 |
|
|
|
| 115 |
|
|
=cut |
| 116 |
|
|
|
| 117 |
|
|
1; |