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

In reply to Re: Framework for making Moose-compatible object from json by awncorp
in thread Framework for making Moose-compatible object from json by nataraj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.