Nick Perez wrote:
> 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.

OK, I played around some more and I think I know how to do it in
theory. The really hard part will be the unification between Moose
and dbus types.

[...]
>         # 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);
[...]

The dbus typesystem knows no classes, only some basic types (string,
int, ...) and compound types (array, dict and struct)¹.

With that in mind, how does one translate the attributes of complex
Moose objects into these simple types? For a simple class with
declarations like

   has 'y' => (is => 'rw', isa => 'Int');
   has 'z' => (is => 'rw', isa => 'Str');

I could go through the classes' attributes and construct a dbus type
like

  ["struct", "int", "string"]

But y and z could also have more complex data types, even with
circular references (type-wise), so a general solution for MXMS (or
Moose for that matter) can not exist (am I right?). Also I'm not sure
how to interpret the "returns" feature only working "with scalar
return values and [still being] considered to be experimental."²

Could the solution be to create a trait, that, when consumed, prevents
creation of objects too complex to translate into a dbus type?

I am *very* new to Moose. If some of what I said doesn't make sense,
that is why :-)

TIA,
Tobias


________
¹ 
http://search.cpan.org/~danberr/Net-DBus-1.0.0/lib/Net/DBus/Exporter.pm#SCALAR_TYPES
  and #COMPOUND_TYPES respectively
² 
http://search.cpan.org/~flora/MooseX-Method-Signatures-0.36/lib/MooseX/Method/Signatures.pm#What_about_the_return_value?


[...]
> On Thu, 25 Aug 2011 10:32:30 +0200
> Tobias Nissen <t...@movb.de> 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

Attachment: signature.asc
Description: PGP signature

Reply via email to