AnyEven...:Client(3)
πΈ AnyEven...:Client(3) β bestie's guide to the XMPP client β¨
okay so real quick, before we dive in: this page lives in the User Contributed Perl Documentation section of the manual, and the module itself is AnyEvent::XMPP::Client(3). that's the whole header bit, slay, moving on π
π NAME π
AnyEvent::XMPP::Client β the XMPP Client abstraction, aka your new bestie for talking to XMPP stuff π¦
β¨ SYNOPSIS β¨
okay bestie here's the whole vibe, literally copy-paste this and you're that girl:
use AnyEvent::XMPP::Client;
use AnyEvent;
my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new;
$cl->start;
$j->wait;
π DESCRIPTION π
so this module is out here trying to give you a straight forward and easy to use API for communicating with XMPP entities. AnyEvent::XMPP::Client handles connections and timeouts and all such stuff for you β like, the boring parts? handled. you're welcome π«Ά
and if you want more flexibility, bestie please go look at AnyEvent::XMPP::Connection and AnyEvent::XMPP::IM::Connection β those let you control what and how something is being sent, way more precisely. different vibe, more main character control π₯
π METHODS π
π new (%args)
these are the args you can pass in %args:
debug => 1β this installs callbacks that produce debugging output. heads up though: this requiresXML::Twigto be installed, since it's what's used for pretty printing theXMLoutput. noXML::Twig, no pretty debug glow-up π
π add_account ($jid, $password, $host, $port, $connection_args)
this one adds a jabber account for connection with the JID $jid and the password $password. periodt π
$host and $port can be undef β and if they are, the defaults are the domain of the $jid, and the default for the "port" parameter to the constructor of AnyEvent::XMPP::Connection (go look there for details about DNS-SRV lookups, iykyk).
$connection_args must either be undef or a hash reference to additional arguments for the constructor of the AnyEvent::XMPP::IM::Connection that will be used to connect the account.
returns 1 on success, and undef when the account already exists. not me getting rejected because you're already in my contacts π
π¦ start ()
this method initiates the connections to the XMPP servers. go off, king π
β update_connections ()
this method tries to connect all unconnected accounts. like a lil matchmaker for your logins β¨
πΈ disconnect ($msg)
disconnect all accounts. that's it. that's the whole thing π
π remove_accounts ($reason)
removes all accounts and disconnects. $reason should be some descriptive reason why this account was removed β but ngl it's just for logging purposes, so it's not that deep π
π§ remove_account ($acc, $reason)
removes and disconnects account $acc (which is a AnyEvent::XMPP::IM::Account object). the reason for the removal can be given via $reason.
π set_accounts (%$accounts)
sets the set of (to be connected) accounts. $accounts must be a hash reference which contains the JIDs of the accounts as keys and the values for $password, $domain, $port and $connection_args as described in "add_account" above.
if the account is not yet connected it will be connected on the next call to "update_connections", and if an account is connected that is not in $accounts it will be disconnected. vibe check: not on the list? you're out π
π₯ send_message ($msg, $dest_jid, $src, $type)
sends a message to the destination $dest_jid. $msg can either be a string or a AnyEvent::XMPP::IM::Message object. if $msg is such an object, $dest_jid is optional, but when passed it will override the destination of the message. iconic override behavior, honestly π
NOTE: $dest_jid is transformed into a bare JID, and the routing is done by the conversation tracking mechanism which keeps track of which resource should get the message. so like, the message finds its person. no cap π¬
$src is optional. it specifies which account to use to send the message. if it is not passed, AnyEvent::XMPP::Client will try to find an account itself. first it will look through all rosters to find $dest_jid, and if none found it will pick any of the accounts that are connected. independent queen behavior π
$src can either be a JID or a AnyEvent::XMPP::IM::Account object as returned by "add_account" and "get_account".
$type is optional but overrides the type of the message object in $msg if $msg is such an object.
$type should be 'chat' for normal chatter. if no $type is specified the type of the message defaults to the value documented in AnyEvent::XMPP::IM::Message (should be 'normal'). so like, default 'normal', but you can be a 'chat' girlie if you want π
π«Ά get_account ($jid)
returns the AnyEvent::XMPP::IM::Account account object for the JID $jid if there is any such account added. returns undef otherwise. sorry bestie, they're not in your account list π
β¨ get_accounts ()
returns a list of AnyEvent::XMPP::IM::Accounts. all of them. the whole friend group πΈ
π get_connected_accounts ()
returns a list of connected AnyEvent::XMPP::IM::Accounts.
same as:
grep { $_->is_connected } $client->get_accounts ();
literally the same thing, we're just being extra about it π
π¦ find_account_for_dest_jid ($jid)
this method tries to find any account that has the contact $jid on his roster. if no account with $jid on his roster was found, it takes the first one that is connected. (return value is a AnyEvent::XMPP::IM::Account object.) it's giving "who's got the vibes for this one" π
if no account is connected it returns undef. nobody home, bestie π
β get_contacts_for_jid ($jid)
this method returns all contacts that we are connected to. that means: it joins the contact lists of all account's rosters that we are connected to. squad assemble π€
π get_priority_presence_for_jid ($jid)
this method returns the presence for the contact $jid with the highest priority. highest priority = main character energy, obviously π
if the contact $jid is on multiple account's rosters, it's undefined which roster the presence belongs to. like, it's a mystery, don't come for me π
π set_presence ($show, $status, $priority)
this sets the presence of all accounts. for a meaning of $show, $status and $priority see the description of the %attrs hash in the "send_presence" method of AnyEvent::XMPP::Writer. go read that one, it's got the deets π
π EVENTS π
in the following event descriptions, the argument $account is always a AnyEvent::XMPP::IM::Account object.
all events from AnyEvent::XMPP::IM::Connection are forwarded to the client, only that the first argument for every event is a $account object. so like, the same events with a lil glow-up β¨
aside fom those (yes, that's the original spelling, leaving it exactly as the manpage had it π
), these events can be registered on with "reg_cb":
connected => $accountβ this event is sent when the$accountwas successfully connected. we love a successful login era πconnect_error => $account, $reasonβ this event is emitted when an error occured in the connection process for the account$account. tragic, honestly πerror => $account, $errorβ this event is emitted when any error occured while communicating over the connection to the$accountβ after a connection was established. so the connection worked, but then the vibes went off π$erroris an error object which is derived fromAnyEvent::XMPP::Error. it will reveal human readable information about the error by calling the"string ()"method (which returns a descriptive error string about the nature of the error). human readable! we stan π«Άadded_account => $accountβ called whenever an account is added. new friend unlocked β¨removed_account => $accountβ called whenever an account is removed. friendship ended, but we don't do mean here, it's just a callback π
π§ AUTHOR π§
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" β legend behavior honestly π
π 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. slay, permissive licensing fr fr π«Ά
and that's the page, bestie π this was documented with perl v5.42.2 on 2026-02-15, so if the future looks different, blame the future, not me πβ¨
π¦ 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