Well, for fun I poked at Net::DBus, this will give you a service:

use 5.020; use strict; use warnings; package My::Dog::Rex; use Net::DBus::Exporter qw(org.my.rex.Runner); use base qw(Net::DBus::Object); # use Rex -feature => [qw/1.4/]; dbus_method("walk_dog", [], []); sub walk_dog { my $self = shift; say "Walking the dog"; # user "root"; # password "ch4ngem3"; # # desc "Show system information"; # task "sysinfo", sub { # say run "uname -a"; # }; } 1; package My::Rex::Service; use base qw(Net::DBus::Service); sub new { my $class = shift; my $self = $class->SUPER::new(@_); My::Dog::Rex->new($self, "/my/dog/rex"); return $self; } package main; use Net::DBus; use Net::DBus::Reactor; my $bus = Net::DBus->session; my $rex = My::Rex::Service->new($bus, "org.my.rex"); Net::DBus::Reactor->main->run; exit 0;

This is how you would trigger methods (from a separate script)

use 5.020; use strict; use warnings; use Net::DBus; my $bus = Net::DBus->session; my $rex = $bus->get_service("org.my.rex")->get_object("/my/dog/rex"); $rex->walk_dog;

And when you want to run on the system bus instead of the user's session bus, change all the ->session to ->system, add the following to "/etc/dbus-1/system.d/org.my.rex.conf" and then run "systemctl reload dbus.service"

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuratio +n 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.d +td"> <busconfig> <!-- Root can own or use the Rex service --> <policy user="root"> <allow own="org.my.rex"/> <allow send_destination="org.my.rex"/> <allow receive_sender="org.my.rex"/> </policy> <!-- Nobody else can do anything --> <policy context="default"> <deny send_destination="org.my.rex"/> <deny receive_sender="org.my.rex"/> </policy> </busconfig>

Good Day,
    Dean


In reply to Re^3: Recommendation for a persistent perl solution? (Net::DBus micro-tutorial) by duelafn
in thread Recommendation for a persistent perl solution? by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.