Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Framework for making Moose-compatible object from json

by awncorp (Acolyte)
on Aug 23, 2022 at 16:44 UTC ( [id://11146328]=note: print w/replies, xml ) Need Help??


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

I can't go into a lot of detail at the moment, but if you're open to using something non-Moose based (at least for inflating the nested data structures), Venus can do all of this for you via the "Venus::Role::Coerciable" role. If you want to stick with Moose you could try reverse engineering "Venus::Role::Coerciable" and using it with your Moose classes. Here's how to do it in Venus:

package JsonData; use Venus::Class; with 'Venus::Role::Coercible'; attr 'icon'; attr 'url'; attr 'datetime'; attr 'subject_html'; sub coerce { { ..., icon => 'JsonData/Icon', url => 'Mojo/URL', datetime => 'Mojo/Date', subject_html => 'Mojo/DOM', ..., } } package JsonData::Icon; use Venus::Class; with 'Venus::Role::Coercible'; attr 'url'; attr 'comment'; attr 'picid'; attr 'keywords'; sub coerce { { ..., url => 'Mojo/URL', ..., } } 1;

Venus::Class

Venus::Role::Coercible

"I am inevitable." - Thanos

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found