I have a requirement to read a JSON/YAML file and build a Perl-based data structure dynamically based on the schema. The .yml file is basically the schema/template and the Perl data-structures would be classes with data-members, and methods to get/set those data members.

For e.g., the YAML hash keys might be class names, sub-keys would be data-members, and the sub-keys will have array/hash elements in turn to signify methods to get/set those data-members. Example below:

student: name: - get: <system_command_to_get_student_name> - set: <system_command_to_set_student_name> student_ID: - get: <system_command_to_get_student_name> - set: <system_command_to_set_student_name> ....
So I would have effectively have a class 'student' with data-members 'name' and 'student_ID', and appropriate 'get_student_name' and 'set_student_name' methods, etc. The schema can be edited easily to replace 'student' with 'employee' keeping the source code undisturbed. For e.g. the same source code should consume the following YAML tomorrow:
employee: SSN: - get: <system_command_to_get_SSN> - set: <system_command_to_set_SSN> pay: - get: <system_command_to_get_pay> - set: <system_command_to_set_pay> ....
I looked at Perl packages CLASS::MOP, Moose, MooseX::Declare, etc. but I have never used them earlier. Any kind of help from Perl gurus would be helpful.

In reply to Building Perl classes dynamically based on an input schema/template by tito80

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.