Nazz has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to create a snippet that prevents Linux machines running Gnome to go into standby mode. The functionality I am trying to implement comes from this little Python script below. Getting this to work in perl can't be that hard although getting this dbus stuff to work is trickier then I thought.... I have no idea what I am doing.
Anyway, the result will go into a community plugin for Squeezecenter an open platform that has it's software written in Perl. So i guess it's all for a good cause.... This is the piece of reference code from the official Gnome-Power-Manager website wiki that explains what I want to do.
#!/usr/bin/python import dbus bus = dbus.Bus(dbus.Bus.TYPE_SESSION) devobj = bus.get_object('org.gnome.PowerManager', '/org/gnome/PowerMan +ager') dev = dbus.Interface(devobj, "org.gnome.PowerManager") cookie = dev.Inhibit('Nautilus', 'Copying files') #do something dev.UnInhibit(cookie)
and this is what I thought it should look like in perl.
use Net::DBus; #get the session bus my $bus = Net::DBus->session; #Get the Gnome power manager object === Wrong!!! my $devobj = $bus->get_object("/org/gnome/PowerManager", "org.gnome.Po +werManager"); #Get the interface === Wrong!!! my $dev = $bus->Interface($devobj,"org.gnome.PowerManager"); my $cookie = $dev->Inhibit("Squeezecenter", "Playing"); .... more code $dev->UnInhibit($cookie); 1;

Replies are listed 'Best First'.
Re: Anyone speak dbus?
by gam3 (Curate) on Jan 20, 2008 at 14:17 UTC
    It seems that with Net::DBus you need to call get_service and then call get_object on the service object.

    I am not running gnome so I can't test this, but I think that this code will get you closer:

    use Net::DBus; #get the session bus my $bus = Net::DBus->session; my $srv = $bus->get_service("org.gnome"); my $devobj = $srv->get_object("/org/gnome/PowerManager", "org.gnome.Po +werManager"); my $cookie = $devobj->Inhibit("Squeezecenter", "Playing"); #.... more code $devobj->UnInhibit($cookie);
    -- gam3
    A picture is worth a thousand words, but takes 200K.
      I have found some additional info on : http://lists.freedesktop.org/archives/xdg/2006-June/006523.html
Re: Anyone speak dbus?
by bigmacbear (Monk) on Jan 21, 2008 at 18:47 UTC

    This is the piece of reference code from the official Gnome-Power-Manger website wiki that explains what I want to do.

    Presenting: Mighty Morphin' Power Mangers! The perfect Christmas gift!

    sorry... couldn't resist... ;-)

      Does not compute !!??
Re: Anyone speak dbus?
by Anonymous Monk on Jan 20, 2008 at 13:39 UTC
    explain "Wrong!!!"