After four hours straight of hacking, double-checking references, learning D-Bus and the intricacies of Perl XS programming, I have a preliminary draft of perl bindings for D-Bus.
At the moment, they do nothing, since there isn’t much more than the DBus::Connection
object, but they are loading correctely, and the approach is right.
The API should resemble the C one, with a perlish twist. A simple service lister program should be:
use DBus; # we could use this class method... my $bus = DBus->get_session_bus; # or just the DBus::Bus class... #my $bus = DBus::Bus->get('session'); # the result is the same: $bus will contain a reference to the session bus. # but it is also a perl hash reference, so it could hold something, such a string: $bus->{service} = 'org.freedesktop.DBus'; # then we could use them in order to get a service my $service = $bus->get_service($bus->{service}); # $service is also a perl hashref, so we could use it to store some more strings: $service->{path} = '/org/freedesktop/DBus'; $service->{interface} = 'org.freedesktop.DBus'; # and the get the object: my $object = $service->get_object($service->{path}, $service->{interface}); # here's the remote method call: print "Service: $_\n" foreach ($object->ListServices); 0;
I plan to make the low-level bindings work as soon as this weekend.
Future plans: creating a DBus::Object::Subclass
pragmatic module, similar to Glib’s Glib::Object::Subclass
, that permits the creation of D-Bus aware objects. This could be tricky, but I’m really optimistic.