On 7/10/06, Jonathan Vanasco <[EMAIL PROTECTED]> wrote:
> On Jul 10, 2006, at 2:20 PM, Clayton Scott wrote:
>> meta :
>>      class : My::Object
>> columns :
>>       a: 1
>>       b : 2
>>       c : 3
>
> personally, id rather see this:
>
>   meta_rosedb:
>      class : My::Object
>      api: 0.73
>    columns:
>       a: 1
>       b: 2
>       c: 3
>
> just because, if this is going into yaml/json/xml, there's a chance
> that its going to be accessed/used with other frameworks - so it
> would be nice to see everything in a rosedb space

Hm, seems like people have different goals here.  My goal was simply
to be able to round-trip from Perl to YAML/JSON and then back to Perl.

    $o = My::Object->new(...);
    $json = $o->as_json;

    $o = My::Object->new;
    $o->init_with_json($json);

In the particular case of JSON, I also wanted the serialized version
to be eval-able in JavaScript to produce something remotely sensible
and useful.

Beyond that, I think it may be easier to just provide the tools people
need to create serializations for other purposes.  Right now, I have
these Helpers in SVN:

    column_value_pairs()
    column_accessor_value_pairs()
    column_mutator_value_pairs()

which return hashes of column name, mutator method name, and accessor
method name and column value pairs.  Building a method to do, say,
Jonathan's suggested format above is pretty simple using these base
helpers:

    sub as_json
    {
      my($self) = shift;
      my %json =
      (
        meta_rosedb =>
        {
          class => $self->meta->class,
          api   => $Rose::DB::Object::VERSION,
        },
        columns => scalar $self->column_value_pairs,
      );
      return wantarray ? %json : \%json;
    }

That's not too onerous is it? :)  If there's no "obvious" JSON or YAML
serialization that'll suit everyone's needs, then I'll probably just
provide helpers to do the round-trip stuff as shown earlier, and let
others build their own variants.  It'd be nice if people shared those
variants as CPAN modules too, but that'd require some sort of official
extension namespace...

-John


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to