DBus - Perl extension for the DBus message system
####### Attaching to the bus ########### use Net::DBus; # Find the most appropriate bus my $bus = Net::DBus->find; # ... or explicitly go for the session bus my $bus = Net::DBus->session; # .... or explicitly go for the system bus my $bus = Net::DBus->system ######## Accessing remote services ######### # Get the service known by 'org.freedesktop.DBus' my $service = $bus->get_service("org.freedesktop.DBus"); # See if SkyPE is around if ($bus->has_service("com.skype.API")) { my $skype = $bus->get_service("com.skype.API"); ... do stuff with skype ... } else { print STDERR "SkyPE does not appear to be running\n"; exit 1 } ######### Providing services ############## # Register a service known as 'org.example.Jukebox' my $service = $bus->export_service("org.example.Jukebox");
Net::DBus provides a Perl API for the DBus message system. The DBus Perl interface is currently operating against the 0.32 development version of DBus, but should work with later versions too, providing the API changes have not been too drastic.
Users of this package are either typically, service providers in which case the Net::DBus::Service and Net::DBus::Object modules are of most relevance, or are client consumers, in which case Net::DBus::RemoteService and Net::DBus::RemoteObject are of most relevance.
my $bus = Net::DBus->find(%params);
Search for the most appropriate bus to connect to and return a connection to it. The heuristic used for the search is
- If DBUS_STARTER_BUS_TYPE is set to 'session' attach to the session bus - Else If DBUS_STARTER_BUS_TYPE is set to 'system' attach to the system bus - Else If DBUS_SESSION_BUS_ADDRESS is set attach to the session bus - Else attach to the system bus
The optional params hash can contain be used to specify connection options. The only support option at this time is nomainloop which prevents the bus from being automatically attached to the main Net::DBus::Reactor event loop.
params
nomainloop
my $bus = Net::DBus->system(%params);
Return a connection to the system message bus. Note that the system message bus is locked down by default, so unless appropriate access control rules are added in /etc/dbus/system.d/, an application may access services, but won't be able to export services. The optional params hash can contain be used to specify connection options. The only support option at this time is nomainloop which prevents the bus from being automatically attached to the main Net::DBus::Reactor event loop.
my $bus = Net::DBus->session(%params);
Return a connection to the session message bus. The optional params hash can contain be used to specify connection options. The only support option at this time is nomainloop which prevents the bus from being automatically attached to the main Net::DBus::Reactor event loop.
my $bus = Net::DBus->new($address, %params);
Return a connection to a specific message bus. The $address parameter must contain the address of the message bus to connect to. An example address for a session bus might look like unix:abstract=/tmp/dbus-PBFyyuUiVb,guid=191e0a43c3efc222e0818be556d67500, while one for a system bus would look like unix:/var/run/dbus/system_bus_socket. The optional params hash can contain be used to specify connection options. The only support option at this time is nomainloop which prevents the bus from being automatically attached to the main Net::DBus::Reactor event loop.
$address
unix:abstract=/tmp/dbus-PBFyyuUiVb,guid=191e0a43c3efc222e0818be556d67500
unix:/var/run/dbus/system_bus_socket
my $connection = $bus->connection;
Return a handle to the underlying, low level connection object associated with this bus. The returned object will be an instance of the Net::DBus::Binding::Bus class. This method is not intended for use by (most!) application developers, so if you don't understand what this is for, then you don't need to be calling it!
my $service = $bus->get_service($name);
Retrieves a handle for the remote service identified by the service name $name. The returned object will be an instance of the Net::DBus::RemoteService class.
$name
my $bool = $bus->has_service($name);
Returns a true value if the bus has an active service with a name of $name. Returns a false value, if it does not. NB services can disappear from the bus at any time, so be prepared to handle failure at a later time, even if this method returns true.
my $service = $bus->export_service($name);
Registers a service with the bus, returning a handle to the service. The returned object is an instance of the Net::DBus::Service class.
Net::DBus, Net::DBus::RemoteService, Net::DBus::Service, Net::DBus::RemoteObject, Net::DBus::Object, Net::DBus::Exporter, Net::DBus::Dumper, Net::DBus::Reactor, dbus-monitor(1), dbus-daemon-1(1), dbus-send(1), http://dbus.freedesktop.org,
Daniel Berrange <dan@berrange.com>
Copyright 2004 by Daniel Berrange
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You can't have =items (as at line 86) unless the first thing after the =over is an =item
To install Net::DBus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::DBus
CPAN shell
perl -MCPAN -e shell install Net::DBus
For more information on module installation, please visit the detailed CPAN module installation guide.