Net::DB...Exporter(3)
okay bestie, welcome to Net::DBus::Exporter(3) β the manual page all about exporting object methods and signals to the bus. Itβs giving main character energy for your D-Bus object, and no cap, itβs useful.
πΈ NAME πΈ
Net::DBus::Exporter β export object methods and signals to the bus. periodt.
β¨ SYNOPSIS β¨
bestie, hereβs the whole setup in one code block, exactly as the page lays it out:
# Define a new package for the object we're going
# to export
package Demo::HelloWorld;
# Specify the main interface provided by our object
use Net::DBus::Exporter qw(org.example.demo.Greeter);
# We're going to be a DBus object
use base qw(Net::DBus::Object);
# Ensure only explicitly exported methods can be invoked
dbus_strict_exports;
# Export a 'Greeting' signal taking a stringl string parameter
dbus_signal("Greeting", ["string"]);
# Export 'Hello' as a method accepting a single string
# parameter, and returning a single string value
dbus_method("Hello", ["string"], ["string"]);
# Export 'Goodbye' as a method accepting a single string
# parameter, and returning a single string, but put it
# in the 'org.exaple.demo.Farewell' interface
dbus_method("Goodbye", ["string"], ["string"], "org.example.demo.Farewell");
π DESCRIPTION π
The Net::DBus::Exporter module is the one that exports methods and signals defined in an object to the message bus. Perl is a loosely typed language, so thereβs literally no way to automatically figure out the correct type information for the methods you want to export. Thatβs why, when you sub-class Net::DBus::Object, this package provides the type information for methods and signals.
When you import this package, you can optionally supply an argument that sets the default interface name to associate with methods and signals that donβt have an explicit interface specified. So in the super common case where your objects only provide a single interface, this removes the need to repeat the interface name against every single method you export. obsessed with the convenience, honestly.
π¦ SCALAR TYPES π¦
When youβre specifying scalar data types for parameters and return values, you must use the following string constants to denote the data type. When values corresponding to these types are (un)marshalled, they are represented as the Perl SCALAR data type (see perldata).
"string"β a UTF-8 string of characters"int16"β a 16-bit signed integer"uint16"β a 16-bit unsigned integer"int32"β a 32-bit signed integer"uint32"β a 32-bit unsigned integer"int64"β a 64-bit signed integer. NB, this type is not supported by many builds of Perl on 32-bit platforms, so if used, your data is liable to be truncated at 32-bits."uint64"β a 64-bit unsigned integer. NB, this type is not supported by many builds of Perl on 32-bit platforms, so if used, your data is liable to be truncated at 32-bits."byte"β a single 8-bit byte"bool"β a boolean value"double"β an IEEE double-precision floating point
π COMPOUND TYPES π
When youβre specifying compound data types for parameters and return values, you have to use an array reference, with the first element being the name of the compound type. iykyk, the array ref is the whole vibe.
π ["array", ARRAY-TYPE]
An array of values, whose type is ARRAY-TYPE. The ARRAY-TYPE can be either a scalar type name, or a nested compound type. When values corresponding to the array type are (un)marshalled, they are represented as the Perl ARRAY data type (see perldata). If, for example, a method was declared to have a single parameter with the type ["array", "string"], then when calling the method one would provide an array reference of strings:
$object->hello(["John", "Doe"])
π ["dict", KEY-TYPE, VALUE-TYPE]
A dictionary of values, more commonly known as a hash table. The KEY-TYPE is the name of the scalar data type used for the dictionary keys. The VALUE-TYPE is the name of the scalar, or compound data type used for the dictionary values. When values corresponding to the dict type are (un)marshalled, they are represented as the Perl HASH data type (see perldata). If, for example, a method was declared to have a single parameter with the type ["dict", "string", "string"], then when calling the method one would provide a hash reference of strings,
$object->hello({forename => "John", surname => "Doe"});
π ["struct", VALUE-TYPE-1, VALUE-TYPE-2]
A structure of values, best thought of as a variation on the array type where the elements can vary. Many languages have an explicit name associated with each value, but since Perl does not have a native representation of structures, they are represented by the LIST data type. If, for example, a method was declared to have a single parameter with the type ["struct", "string", "string"], corresponding to the C structure
struct {
char *forename;
char *surname;
} name;
then, when calling the method one would provide an array reference with the values ordered to match the structure
$object->hello(["John", "Doe"]);
π MAGIC TYPES π
When youβre specifying introspection data for an exported service, there are a couple of so-called βmagicβ types. Parameters declared as magic types are not visible to clients, but instead their values are provided automatically by the server side bindings. One use of magic types is to get an extra parameter passed with the unique name of the caller invoking the method.
"caller"β the value passed in is the unique name of the caller of the method. Unique names are strings automatically assigned to client connections by the bus daemon, for example':1.15'"serial"β the value passed in is an integer within the scope of a caller, which increments on every method call.
β ANNOTATIONS β
When youβre exporting methods, signals & properties, in addition to the core data typing information, a number of metadata annotations are possible. These are specified by passing a hash reference with the desired keys as the last parameter when defining the export. The following annotations are currently supported:
no_returnβ indicate that this method does not return any value, and thus no reply message should be sent over the wire, likewise informing the clients not to expect / wait for a reply messagedeprecatedβ indicate that use of this method/signal/property is discouraged, and it may disappear altogether in a future release. Clients will typically print out a warning message when a deprecated method/signal/property is used.param_namesβ an array of strings specifying names for the input parameters of the method or signal. If omitted, no names will be assigned.return_namesβ an array of strings specifying names for the return parameters of the method. If omitted, no names will be assigned.strict_exceptionsβ exceptions thrown by this method which are not of typeNet::DBus::Errorwill not be caught and converted to D-Bus errors. They will be rethrown and continue up the stack until something else catches them (or the process dies).
π METHODS π
π
dbus_method($name, $params, $returns, [\%annotations]);
π
dbus_method($name, $params, $returns, $interface, [\%annotations]);
Exports a method called $name, having parameters whose types are defined by $params, and returning values whose types are defined by $returns. If the $interface parameter is provided, then the method is associated with that interface; otherwise the default interface for the calling package is used. The value for the $params parameter should be an array reference with each element defining the data type of a parameter to the method. Likewise, the $returns parameter should be an array reference with each element defining the data type of a return value. And hard no: it is not possible to export a method which accepts a variable number of parameters, or returns a variable number of values.
π
dbus_no_strict_exports();
If an object is using the Exporter to generate DBus introspection data, the default behaviour is to only allow invocation of methods which have been explicitly exported.
To allow clients to access methods which have not been explicitly exported, call dbus_no_strict_exports.
NB, doing this may be a security risk if you have methods considered to be βprivateβ for internal use only. As such this method should not normally be used. It is here only to allow switching export behaviour to match earlier releases. bestie, please read that warning twice.
π
dbus_property($name, $type, $access, [\%attributes]);
π
dbus_property($name, $type, $access, $interface, [\%attributes]);
Exports a property called $name, whose data type is $type. If the $interface parameter is provided, then the property is associated with that interface; otherwise the default interface for the calling package is used.
π
dbus_signal($name, $params, [\%attributes]);
π
dbus_signal($name, $params, $interface, [\%attributes]);
Exports a signal called $name, having parameters whose types are defined by $params. If the $interface parameter is provided, then the signal is associated with that interface; otherwise the default interface for the calling package is used. The value for the $params parameter should be an array reference with each element defining the data type of a parameter to the signal. Signals do not have return values. It is not possible to export a signal which has a variable number of parameters.
β¨ EXAMPLES β¨
okay bestie, this is the part where it all clicks. every example is here, and yes, the code is staying exactly as written. π
No parameters, no return values πΈ
A method which simply prints "Hello World" each time its called β zero args, zero return values, just output and vibes. π
sub Hello {
my $self = shift;
print "Hello World\n";
}
dbus_method("Hello", [], []);
One string parameter, returning an boolean value π
A method which accepts a process name, issues the killall command on it, and returns a boolean value to indicate whether it was successful. very "did it work? yes/no" of it. β¨
sub KillAll {
my $self = shift;
my $processname = shift;
my $ret = system("killall $processname");
return $ret == 0 ? 1 : 0;
}
dbus_method("KillAll", ["string"], ["bool"]);
One list of strings parameter, returning a dictionary π¦
A method which accepts a list of file names, stats them, and returns a dictionary containing the last modification times. lowkey obsessed with a useful return value. π
sub LastModified {
my $self = shift;
my $files = shift;
my %mods;
foreach my $file (@{$files}) {
$mods{$file} = (stat $file)[9];
}
return \%mods;
}
dbus_method("LastModified", ["array", "string"], ["dict", "string", "int32"]);
Annotating methods with metdata π
A method which is targeted for removal, and also does not return any value. big "we're sunsetting this" energy. π
sub PlayMP3 {
my $self = shift;
my $track = shift;
system "mpg123 $track &";
}
dbus_method("PlayMP3", ["string"], [], { deprecated => 1, no_return => 1 });
Or giving names to input parameters:
sub PlayMP3 {
my $self = shift;
my $track = shift;
system "mpg123 $track &";
}
dbus_method("PlayMP3", ["string"], [], { param_names => ["track"] });
π AUTHOR π
Daniel P. Berrange <dan@berrange.com>
π COPYRIGHT π
Copright (C) 2004-2011, Daniel Berrange.
π SEE ALSO π
Net::DBus::Object, Net::DBus::Binding::Introspector
okay that's the whole manual page bestie! mwah π β this edition is from perl v5.42.0, dated 2019-12-17 πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- opensuse-leap 16.0: perl-Net-DBus 1.2.0-160000.2.2 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms