Well, it is Moose and you seem to be using either MooseX::Declare or
MooseX::Method::Signatures. This means good things for you. You could,
on import, merely interrogate your own class, iterate the methods and
call dbus_method() with the necessary parameters. Then once you have
that working, I recommend you bundle that functionality into a Role and
merely consume it whenever you need to expose methods to DBus. Also,
put it on CPAN.

You can also look at some of my POEx modules for some of the meta
fuckery that can be achieved when it comes to interrogating methods
that have signatures and traits, etc.

Sample pseudocode (completely untested, will NOT work if you copy
paste it):

package DBus::Role;
use Moose::Role;
use Net::DBus::Exporter qw/dbus_method/;

sub import {
    my ($class) = @_;
    foreach my $method_name ($class->meta->get_method_list) {
        my $method = $class->meta->get_method($method_name);
        
        # assumes MXMS since it wraps methods to provide signatures
        my $signature = $method->signature;
        my $return = $method->return_signature;
        
        # You need to parse out the signature. Look inside MXMS for this
        # Also, this is lots of hand waving. Consider this pseudocode
        dbus_method($method->name, $signature, $return);
    }
}

1;

...

class MyFancyDBusThingy with DBus::Role {
    method foo(Str $str) returns (Str) {
        return 'Foo!';
    }
}

On Thu, 25 Aug 2011 10:32:30 +0200
Tobias Nissen <[email protected]> wrote:

> Hi,
> 
> I just managed to write a Moose class that extends Net::DBus::Object
> (using MooseX::NonMoose). Now I end up with a lot of code like this:
> 
>   dbus_method("Hello", ["string"], ["string"]);
>   method Hello(Str $name) returns (Str) { ... }
> 
> Let's say I knew that all my DBus types were 1:1 mappable to Moose
> types, what would I have to do to get rid of that "double" method
> declaration?¹
> 
> Do you know of code out there that I could study and that would help
> me on my task of writing a DBus application using Moose?
> 
> TIA,
> Tobias
> 
> ¹ dbus_method() comes from Net::DBus::Exporter and is used to export
>   methods on the (D-)bus


-- 

Nicholas Perez
XMPP/Email: [email protected]
http://search.cpan.org/~nperez/
http://github.com/nperez

Reply via email to