Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Automatically creating data validation module from XSD

by Zaxo (Archbishop)
on Aug 10, 2007 at 04:19 UTC ( #631699=note: print w/ replies, xml ) Need Help??


in reply to Automatically creating data validation module from XSD

I think Tie::Constrained will do what you want. It will let you tie a scalar from your structure to some particular condition through a boolean coderef.

An attempt to assign an invalid value (meaning it fails the condition) invokes a failure function which you can define for each type.

Inheritance is the preferred way to specialize Tie::Constrained to a type.

I've discussed and demonstrated Tie::Constrained in several pm articles: To Validate Data In Lvalue Subs, Tie Me Up, Tie Me Down, Re^2: Writing general code: real world example - and doubts! (reply to you!), and in the my Dog $spot; thread.

Part of the problem of combining attributes automatically under Tie::Constrained can be handled by the trick I showed in FunkOpera: Abstracting Perl Operators (where did I get that silly name? . . .). The skeletal FunkOpera.pm shown there overloads operators to combine coderefs to return a coderef which combines their returns in the suitable way.

Sorry, I've never done anything significant with xml, so I don't really understand what I can take as given in your problem. I think the base types would need to be hand encoded, but user-defined ones might be automated through some XML magic and an extension of the unfortunately named FunkOpera.pm.

After Compline,
Zaxo


Comment on Re: Automatically creating data validation module from XSD

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://631699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2015-07-01 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (11 votes), past polls