Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 taking refuge in the Monastery: (9)
As of 2014-11-25 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls