Skip to content

Feature request: alternative to alias_method for validating setters #1

@dmolesUC

Description

@dmolesUC

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions