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
|
package AnyEvent::XMPP::Ext::Disco::Info;
use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
use strict;
=head1 NAME
AnyEvent::XMPP::Ext::Disco::Info - Service discovery info
=head1 SYNOPSIS
=head1 DESCRIPTION
This class represents the result of a disco info 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}
}
=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} }
sub init {
my ($self) = @_;
my $node = $self->{xmlnode};
return unless $node;
my (@ids) = $node->find_all ([qw/disco_info identity/]);
for (@ids) {
push @{$self->{identities}}, {
category => $_->attr ('category'),
type => $_->attr ('type'),
name => $_->attr ('name'),
xml_node => $_,
};
}
my (@fs) = $node->find_all ([qw/disco_info feature/]);
$self->{features}->{$_->attr ('var')} = $_ for @fs;
}
=item B<identities ()>
Returns a list of hashrefs which contain following keys:
category, type, name, xml_node
C<category> is the category of the identity. C<type> is the
type of the identity. C<name> is the human readable name of
the identity and might be undef. C<xml_node> is the L<AnyEvent::XMPP::Node>
object of the <identity/> node.
C<category> and C<type> may be one of those defined on:
http://www.xmpp.org/registrar/disco-categories.html
=cut
sub identities {
my ($self) = @_;
@{$self->{identities}}
}
=item B<features ()>
Returns a hashref of key/value pairs where the key is the feature name
as listed on:
http://www.xmpp.org/registrar/disco-features.html
and the value is a L<AnyEvent::XMPP::Node> object for the <feature/> node.
=cut
sub features { $_[0]->{features} || {} }
=item B<debug_dump ()>
Prints the information of this Info object to stdout.
=cut
sub debug_dump {
my ($self) = @_;
printf "INFO FOR %s (%s):\n", $self->jid, $self->node;
for ($self->identities) {
printf " ID : %20s/%-10s (%s)\n", $_->{category}, $_->{type}, $_->{name}
}
for (sort keys %{$self->features}) {
printf " FEATURE: %s\n", $_;
}
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;
|