John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
That is what XML::Simple does, but without sufficient guidance of what is wanted, and without all features being available. That is what .NET (excuse my French) does with the "Deserialize" attributes, and something that I've wrestled with because it's poorly designed and incomplete.
The point is, there is a step to do this transformation. And the work is mostly simple and repetitive. When coding, in an initial effort I decomposed the step into a function; e.g. take a DOM Node of type Element, and return a Foo structure (dumb structure, not a class). To eliminate duplicate code, I pushed the most common thing to do here into a separate function: take a list of names, and copy attributes having those names (if they exist) into a destination hash.
The idea is that a small number of to-the-point functions, with a reasonable amount of flexibility staying within its point, can be called to easily implement the function that converts a DOM Element into a Foo, for any Foo. That's as opposed to having a huge complex configuration structure that does it all automatically once set up, assuming the designer thought of everything. The provided functions can be used when applicable, with a small amount of code between them to handle odd things, and no problem convincing it to do something totally different.
So why isn't this already a nice CPAN module?
Has everyone written code like this? Or am I missing something?
—John
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading structures from XML
by Your Mother (Archbishop) on May 06, 2009 at 19:37 UTC | |
by BrowserUk (Patriarch) on May 07, 2009 at 01:13 UTC | |
by Your Mother (Archbishop) on May 07, 2009 at 15:19 UTC | |
by John M. Dlugosz (Monsignor) on May 06, 2009 at 20:56 UTC | |
|
Re: Reading structures from XML
by Jenda (Abbot) on May 07, 2009 at 00:37 UTC |