I’ve been trying to find a Perl module that converts a YAML file into moose objects without having to pre-declare the structure as you seem to need to do when using MooseX::YAML. Does anyone know of such a module (or script)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t.
Moose classes, their attributes, and whatever else belongs to them, have a lot of meta-data attached to them. You can’t infer all of that meta-data from the data of a single instance.
I’m assuming, given a yaml document as
you’d expect and object back that responds to calls to a
fooand abarmethod, returning the respective values. But how should those accessors behave? Should they be simple reader-methods, or also allow writing? Should they validate against any kind of typeconstraint? etc.If all you really need is something that makes some unblessed data-structure accessible like an object, have a look at
Data::Hive,Hash::AsObject, and similar modules instead.If you really want to build proper Moose classes, and are either alright with the guesswork that’d be involved, or happen to have the necessary meta-data available somewhere, you can just use the meta-protocol.