tito80 has asked for the wisdom of the Perl Monks concerning the following question:
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:
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: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> ....
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.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> ....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building Perl classes dynamically based on an input schema/template
by davido (Cardinal) on Nov 11, 2016 at 23:27 UTC | |
by karlgoethebier (Abbot) on Nov 15, 2016 at 19:47 UTC | |
by davido (Cardinal) on Nov 16, 2016 at 01:18 UTC | |
by tito80 (Novice) on Nov 16, 2016 at 20:29 UTC | |
by karlgoethebier (Abbot) on Nov 16, 2016 at 11:35 UTC |