Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Framework for making Moose-compatible object from json

by nataraj (Sexton)
on Sep 04, 2022 at 11:28 UTC ( [id://11146676]=note: print w/replies, xml ) Need Help??


in reply to Framework for making Moose-compatible object from json

Actually I started wiriting one MooseX::Embody::JSON and MooseX::Embody::JSON::Role

This allows me to do things exactly I would expect it:

package WebService::DreamWidth::Entry; use Moose; use MooseX::Embody::JSON; use WebService::DreamWidth::Icon; use WebService::DreamWidth::Poster; # this one is not part of Embody::Json yet has "tags" => (is=>'ro', isa => 'ArrayRef[Str]'); j_obj "icon" =>(class => "WebService::DreamWidth::Icon", is =>'ro'); j_obj "poster" =>(class => "WebService::DreamWidth::Poster", is =>'ro' +); j_attr "security" => (is => 'ro'); j_attr "body_html"=> (is => 'ro'); j_attr "subject_raw"=> (is => 'ro'); j_attr "subject_html"=> (is => 'ro'); j_attr "allowmask"=> (is => 'ro'); j_attr "body_raw"=> (is => 'ro'); j_attr "icon_keyword"=> (is => 'ro'); j_attr "entry_id"=> (is => 'ro'); j_attr "datetime"=> (is => 'ro'); j_attr "url" => (is => 'ro');

This is early prototype, I need to play with it a lot, before releasing in even as beta, and some internals may be needs changing a log, but is is exactly the thing I think is needed for creating JSON-based REST clients.

And yes, comments and suggestion are appreciated.

Replies are listed 'Best First'.
Re^2: Framework for making Moose-compatible object from json
by Arunbear (Prior) on Sep 05, 2022 at 11:04 UTC
    I'm curious about why MooseX::Storage (mentioned previously in this thread) wasn't up to the task?
      I'm curious about why MooseX::Storage (mentioned previously in this thread) wasn't up to the task?

      Because I consider that case "object inside object inside object" is common case, and should be solved without any Moose code, just by mentioning "This is a subobject of following type". Like this:

      j_obj "icon" =>(class => "WebService::DreamWidth::Icon", is =>'ro');

      I even thinking about removing "is =>'ro'", making it default. In simple case developer should just list attributes and child objects. This is not case for MooseX::Storage

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146676]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-26 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found