AnyEven...::VCard(3)
Hey bestie π welcome to the AnyEven...::VCard(3) page from User Contributed Perl Documentation β this one is all about AnyEvent::XMPP::Ext::VCard, aka VCards (XEP-0054 & XEP-0084). Itβs giving XMPP glow-up energy, and weβre gonna get through every detail together π«Άβ¨
β¨ NAME β¨
AnyEvent::XMPP::Ext::VCard - VCards (XEP-0054 & XEP-0084)
π SYNOPSIS π
use AnyEvent::XMPP::Ext::VCard;
my $vcard = AnyEvent::XMPP::Ext::VCard->new;
$con->reg_cb (
stream_ready => sub { $vcard->hook_on ($con) }
);
$vcard->retrieve ($con, 'elmex@jabber.org', sub {
my ($jid, $vcard, $error) = @_;
if ($error) {
warn "couldn't get vcard for elmex@jabber.org: " . $error->string . "\n";
} else {
print "vCard nick for elmex@jabber.org: ".$vcard->{NICKNAME}."\n";
print "Avatar hash for elmex@jabber.org: ".$vcard->{_avatar_hash}."\n";
}
});
$vcard->store ($con, undef, { NICKNAME => 'net-xmpp2' }, sub {
my ($error) = @_;
if ($error) {
warn "upload failed: " . $error->string . "\n";
} else {
print "upload successful\n";
}
});
$disco->enable_feature ($vcard->disco_feature);
π DESCRIPTION π
This extension handles setting and retrieval of the VCard and the VCard based avatars. Iconic behavior, honestly.
For example, go peek at the test suite of AnyEvent::XMPP β thatβs where the real demo energy lives πβ¨
π METHODS π
π« new (%args) π«
Creates a new vcard extension. It can take a cache argument, which should be a tied hash that should be able to save the retrieved vcards. If no cache is set, an internal hash will be used and the vcards will be retrieved every time the program is restarted π (no cap, thatβs the default).
The keys will be the stringprepped bare JIDs of the people we got a vcard from, and the value will be a non-cyclic hash/array datastructure representing the vcard.
About this datastructure, see below at VCARD STRUCTURE β itβs got lore π§
If you want to support avatars correctly, make sure you hook up the connection via the hook_on method. Periodt.
πͺ hook_on ($con, $dont_retrieve_vcard) πͺ
$con must be an object of the class AnyEvent::XMPP::Connection (or derived). Once the vCard extension has been hooked up on a connection, it will add the avatar information to all outgoing presence stanzas. Slay π
IMPORTANT: You need to hook on the connection BEFORE it was connected. The initial presence stanza needs to contain the information that we support avatars. The vcard will automatically retrieved if the session wasnβt already started. Otherwise you will have to retrieve the vcard manually if you hook it up after the session_ready event was received. You can prevent the automatic retrieval by giving a true value in $dont_retrieve_vcard. However, just make sure to hook up on any connection before it is connected if you want to offer avatar support on it. This is one of those βread it twice, bestieβ moments ππ
Best is probably to do it like this:
my $vcard = AnyEvent::XMPP::Ext::VCard->new;
$con->reg_cb (
stream_ready => sub { $vcard->hook_on ($con) }
);
πͺ my_vcard ($con) πͺ
This method returns the vcard for the account connected by $con. This only works if vcard was (successfully) retrieved. If the connection was hoooked up, the vcard was automatically retrieved.
Alternatively $con can also be a string reprensenting the JID of an account. Lowkey handy π«Ά
ποΈ cache ([$newcache]) ποΈ
See also new about the meaning of cache hashes. If no argument is given, the current cache is returned. Thatβs it, thatβs the method β¨
πΎ store ($con, $vcard, $cb) πΎ
This method will store your $vcard on the connected server. $cb is called when either an error occured or the storage was successful. If an error occured, the first argument is not undefined and contains an AnyEvent::XMPP::Error::IQ object.
$con should be a AnyEvent::XMPP::Connection or an object from some derived class.
$vcard has a datastructure as described below in VCARD STRUCTURE.
π retrieve ($con, $jid, $cb) π
This method will retrieve the vCard for $jid via the connection $con. If $jid is undefined, the vCard of yourself is retrieved. The callback $cb is called when an error occured or the vcard was retrieved. The first argument of the callback will be the JID to which the vCard belongs, the second argument is the vCard itself (as described in VCARD STRUCTURE below), and the thrid argument is the error, if an error occured (undef otherwise).
𧬠VCARD STRUCTURE π§¬
As there are currently no nice DOM implementations in Perl and I strongly dislike the DOM API in general, this module has a simple Perl datastructure without cycles to represent the vCard. We love a pragmatic icon π
First, an example: a fetched vCard hash may look like this:
{
'URL' => ['http://www.ta-sa.org/'],
'ORG' => [{
'ORGNAME' => 'nethype GmbH'
}],
'N' => [{
'FAMILY' => 'Redeker'
}],
'EMAIL' => ['elmex@ta-sa.org'],
'BDAY' => ['1984-06-01'],
'FN' => ['Robin'],
'ADR' => [
{
HOME => undef,
'COUNTRY' => 'Germany'
},
{
WORK => undef,
COUNTRY => 'Germany',
LOCALITY => 'Karlsruhe'
}
],
'NICKNAME' => ['elmex'],
'ROLE' => ['Programmer']
}
The keys represent the toplevel element of a vCard, and the values are always array references containing one or more values for the key. If the value is a hash reference again, its value will not be an array reference but either undef or plain values.
The values of the toplevel keys are all array references because fields like ADR may occur multiple times.
Consult XEP-0054 for an explanation of what these fields mean or contain. Itβs giving documentation-with-lore π
There are special fields in this structure for handling avatars:
_avatarcontains the binary data for the avatar image._avatar_hashcontains the sha1 hexencoded hash of the binary image data._avatar_typecontains the mime type of the avatar.
If you want to store the vcard, you only have to set _avatar and _avatar_type if you want to store an avatar. Easy peasy π
π£ EVENTS π£
The vcard extension will emit these events:
π TODO π
Implement caching, the cache stuff is just a storage hash at the moment. Or maybe drop it completly and let the application handle caching. Honestly? Mood. Thatβs the whole TODO note πβ¨
retrieve_vcard_error => $iq_errorβ When a vCard retrieval was not successful, this event is emitted. This is neccessary as some retrievals may happen automatically.vcard => $jid, $vcardβ Whenever a vCard is retrieved, either automatically or manually, this event is emitted with the retrieved vCard.
π AUTHOR π
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>"
π 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.
Signing off bestie: this is AnyEven...::VCard(3) from perl v5.42.2, dated 2026-02-15 ππ«Άβ¨
π¦ where this page comes from
- alpine 3.24: perl-anyevent-xmpp-doc 0.55-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms