talexb has asked for the wisdom of the Perl Monks concerning the following question:
I'm interested in learning how to use Moose to create an object at run-time. I have a CSV file with field names and lengths, and I have a flat file that's in that format. I'd love to be able to go from those two data sources and come up with a collection of Moose objects that I can then Do Stuff With.
My research so far has turned up this contentious solution and the suggestion to look at Moose::Meta::Class. However, that last module seems to build on another class, when I don't want to do that -- I want to create a class so that (among other reasons) I can take advantage of Moose's code to check that a field's data is of the right type.
Update: Upon re-reading this, after posting it, I realized I'm not as clear here as I was when the question was in my head. I want to add attributes at run-time, rather than specify them (has, etc.) beforehand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating a Moose object at run-time
by jeffa (Bishop) on Oct 22, 2015 at 19:49 UTC | |
by talexb (Chancellor) on Oct 22, 2015 at 21:31 UTC | |
|
Re: Creating a Moose object at run-time
by nevdka (Pilgrim) on Oct 22, 2015 at 23:53 UTC | |
by gnosti (Chaplain) on Oct 23, 2015 at 00:01 UTC | |
by talexb (Chancellor) on Oct 23, 2015 at 14:26 UTC |