DBus Perl Bindings/2

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;
dbus-perl screenshot
Obligatory screenshot of the bindings

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.

2 Replies to “DBus Perl Bindings/2”

  1. Hi,

    Did this ever become a perl module or a finished project ?

    Thanks,
    Nathan

  2. nope, because the D-Bus perl bindings that Daniel Berrange wrote are already great, maintained, and he can keep them updated. there’s no point replicating his awesome work.

    you can find the official perl d-bus bindings on CPAN, inside the Net::DBus package.

Comments are closed.