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 requires XML::Twig to be installed, since it's what's used for pretty printing the XML output. no XML::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 $account was 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 πŸ’€ $error is an error object which is derived from AnyEvent::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 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