From 943149067814dfa24c55abac679722d8471e5f02 Mon Sep 17 00:00:00 2001 From: dakkar Date: Sun, 22 Oct 2023 20:57:24 +0100 Subject: simpler proxy object turns out you can get the name of the sender by using `caller` as a parameter type (it's documented in Net::DBus::Exporter, section "magic types") --- lib/App/XScreenSaver/DBus/SaverProxy.pm | 38 +++------------------------------ 1 file changed, 3 insertions(+), 35 deletions(-) (limited to 'lib/App/XScreenSaver/DBus/SaverProxy.pm') diff --git a/lib/App/XScreenSaver/DBus/SaverProxy.pm b/lib/App/XScreenSaver/DBus/SaverProxy.pm index 858dcba..69a689c 100644 --- a/lib/App/XScreenSaver/DBus/SaverProxy.pm +++ b/lib/App/XScreenSaver/DBus/SaverProxy.pm @@ -2,45 +2,13 @@ package App::XScreenSaver::DBus::SaverProxy; use v5.20; use strict; use warnings; -use experimental qw(signatures postderef); # this is the interface name use Net::DBus::Exporter qw(org.freedesktop.ScreenSaver); -use parent 'Net::DBus::Object'; +use parent 'Net::DBus::ProxyObject'; # VERSION # ABSTRACT: proxy dbus object -=head1 DESCRIPTION - -This is functionally the same as L<< C >>, but -specialised for this application, and with a hack to allow L<< -C >> to access the sender of the -message. - -=cut - -dbus_method('Inhibit',['string','string'],['uint32']); -dbus_method('UnInhibit',['uint32'],[]); - -sub new($class,$service,$path,$inhibit_cb,$uninhibit_cb) { - my $self = $class->SUPER::new($service, $path); - bless $self, $class; - $self->{__inhibit_cb} = $inhibit_cb; - $self->{__uninhibit_cb} = $uninhibit_cb; - return $self; -} - -our $_message; -sub _dispatch_object($self,$connection,$message,@etc) { - local $_message = $message; - return $self->SUPER::_dispatch_object($connection,$message,@etc); -} - -sub Inhibit($self,$name,$reason) { - return $self->{__inhibit_cb}->($name,$reason,$_message); -} - -sub UnInhibit($self,$cookie) { - return $self->{__uninhibit_cb}->($cookie,$_message); -} +dbus_method('Inhibit',['string','string','caller'],['uint32']); +dbus_method('UnInhibit',['uint32','caller'],[]); 1; -- cgit v1.2.3