Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: alternative to alias_method for validating setters #1

Open
dmolesUC opened this issue Jan 27, 2016 · 0 comments
Open

Comments

@dmolesUC
Copy link
Owner

XML::Mapping creates setters for all nodes. In general, these setters don't provide validation. The obvious way to provide validation is to create a private alias for the setter, and redefine the public setter to validate before calling the private one, e.g., the value and identifier_type nodes in this example.

However, alias_method can behave badly if a file is required via two different paths -- the second require will hide the original generated setter completely, instead aliasing the redefined public setter. When the redefined public setter attempts to call the private setter, it instead calls itself, resulting in a stack overflow as in datacite-mapping #1.

This is a general problem with alias_method, but since adding validation to setters is such a common use case in XML mapping, it would be nice if XML::MappingExtensions would provide a safer validation alternative, e.g. some sort of node-definition wrapper that takes a validation block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant