DBus(3)
β¨ NAME β¨
So this is DBus(3) β a user-contributed Perl doc (iykyk, it lives in the User Contributed Perl Documentation section) β and it's all about:
AnyEvent::DBus β adapt Net::DBus to AnyEvent π¦
πΈ SYNOPSIS πΈ
use AnyEvent::DBus;
# now use the Net::DBus API, preferably the non-blocking variants:
use Net::DBus::Annotation qw(:call);
$bus->get_object (...)
->Method (dbus_call_async, $arg1, ...)
->set_notify (sub {
my @data = $_[0]->get_result
...
});
$bus->get_connection->send (...);
π DESCRIPTION π
Okay so first thing first, bestie: this module is an AnyEvent user, so you literally need to make sure you use and run a supported event loop. No event loop, no vibes. Periodt.
Loading this module installs the necessary magic to seamlessly integrate Net::DBus into AnyEvent. How? By quite brutally hacking Net::DBus::Reactor π so that all dbus connections created after you load this module automatically get managed by this module. Sneaky? A little. Effective? Extremely.
Now for the real talk, because we're keeping it π― here. Note that: - a) a lot insideNet::DBusis still blocking - b) if you call a method that blocks, you again block your process β basically anything but calls to theNet::DBus::Binding::Connectionobjects blocks, but seeNet::DBus::Annoation, specificallydbus_call_async- c) the underlyinglibdbusis often blocking itself, even with infinite timeouts π - d) this module only implements the minimum API required to makeNet::DBuswork βNet::DBusunfortunately has no nice hooking API
However (and this is the slay part), unlike Net::DBus::Reactor, this module should be fully non-blocking as long as you only use non-blocking APIs (Net::DBus::Reactor blocks on writes). It should also be faster, but Net::DBus is such a morass of unneeded method calls that speed won't matter much... π
π EXAMPLE π
Here's a simple example, bestie. Both versions work with AnyEvent::DBus and do the same thing β but only the second one is actually non-blocking. Choose wisely β¨
Example 1: list registered named, blocking version.
use AnyEvent::DBus;
my $conn = Net::DBus->find;
my $bus = $conn->get_bus_object;
for my $name (@{ $bus->ListNames }) {
print " $name\n";
}
Example 1: list registered named, somewhat non-blocking version.
(yes, it says Example 1 again β we don't make the rules, we just follow them π )
use AnyEvent;
use AnyEvent::DBus;
use Net::DBus::Annotation qw(:call);
my $conn = Net::DBus->find; # always blocks :/
my $bus = $conn->get_bus_object;
my $quit = AE::cv;
# the trick here is to prepend dbus_call_async to any method
# arguments and then to call the set_notify method on the
# returned Net::DBus::AsyncReply object
$bus->ListNames (dbus_call_async)->set_notify (sub {
for my $name (@{ $_[0]->get_result }) {
print " $name\n";
}
$quit->send;
});
$quit->recv;
π₯ SEE ALSO π₯
AnyEventNet::DBus
π AUTHOR π
Marc Lehmann <schmorp@schmorp.de>
and that's the whole page, bestie π«Ά β this one's perl v5.42.0, dated 2025-07-25, and it's the DBus(3) page. go be non-blocking, you've got this π
π¦ where this page comes from
- fedora 43: perl-AnyEvent-DBus 0.31-42.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms