# Connecting an object to the bus, under a service package main; use Net::DBus; # Attach to the bus my $bus = Net::DBus->find; # Create our application's object instance my $object = Demo::HelloWorld->new() # Acquire a service 'org.demo.Hello' my $service = $bus->export_service("org.demo.Hello"); # Finally export the object to the bus my $proxy = Demo::HelloWorld::DBus->new($object); ....rest of program... # Define a new package for the object we're going # to export package Demo::HelloWorld; sub new { my $class = shift; my $service = shift; my $self = {}; $self->{sighandler} = undef; bless $self, $class; return $self; } sub sighandler { my $self = shift; my $callback = shift; $self->[sighandler} = $callback; } sub Hello { my $self = shift; my $name = shift; &{$self->{sighandler}}("Greeting", "Hello $name"); return "Said hello to $name"; } sub Goodbye { my $self = shift; my $name = shift; &{$self->{sighandler}}("Greeting", "Goodbye $name"); return "Said goodbye to $name"; } # Define a new package for the object we're going # to export package Demo::HelloWorld::DBus; # 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::ProxyObject); # 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"]); sub new { my $class = shift; my $service = shift; my $impl = shfit; my $self = $class->SUPER::new($service, "/org/demo/HelloWorld", $impl); bless $self, $class; $self->sighandler(sub { my $signame = shift; my $arg = shift; $self->emit_signal($signame, $arg); }); return $self; } # 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");