<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    Validation::Class::Document - Data Validation for Hierarchical Data

VERSION
    version 0.000009

SYNOPSIS
        package MyApp::Person;

        use Validation::Class::Document;

        field  'id' =&gt; {
            mixin      =&gt; [':str'],
            filters    =&gt; ['numeric'],
            max_length =&gt; 2,
        };

        field  'name' =&gt; {
            mixin      =&gt; [':str'],
            pattern    =&gt; qr/^[A-Za-z ]+$/,
            max_length =&gt; 20,
        };

        field  'rating' =&gt; {
            mixin      =&gt; [':str'],
            pattern    =&gt; qr/^\-?\d+$/,
        };

        field  'tag' =&gt; {
            mixin      =&gt; [':str'],
            pattern    =&gt; qr/^(?!evil)\w+/,
            max_length =&gt; 20,
        };

        document 'person' =&gt; {
            'id'                             =&gt; 'id',
            'name'                           =&gt; 'name',
            'company.name'                   =&gt; 'name',
            'company.supervisor.name'        =&gt; 'name',
            'company.supervisor.rating.@.*'  =&gt; 'rating',
            'company.tags.@'                 =&gt; 'name'
        };

        package main;

        my $data = {
            "id"      =&gt; "1234-ABC",
            "name"    =&gt; "Anita Campbell-Green",
            "title"   =&gt; "Designer",
            "company" =&gt; {
                "name"       =&gt; "House of de Vil",
                "supervisor" =&gt; {
                    "name"   =&gt; "Cruella de Vil",
                    "rating" =&gt; [
                        {   "support"  =&gt; -9,
                            "guidance" =&gt; -9
                        }
                    ]
                },
                "tags" =&gt; [
                    "evil",
                    "cruelty",
                    "dogs"
                ]
            },
        };

        my $person = MyApp::Person-&gt;new;

        unless ($person-&gt;validate_document(person =&gt; $data)) {
            warn $person-&gt;errors_to_string if $person-&gt;error_count;
        }

DESCRIPTION
    This module allows you to validate hierarchical structures using the
    Validation::Class framework. This is an experimental yet highly
    promising approach toward the consistent processing of nested
    structures. The current interface is not expected to change. This module
    was inspired by MooseX::Validation::Doctypes. Gone are the days of data
    submitted to an application in key/value form and especially in regards
    to the increasing demand for communication between applications,
    serializing and transmitting structured data over a network connection.

METHODS
  validate_document
    The validate_document method (or document_validates) is used to validate
    the specified hierarchical data against the specified document
    declaration. This is extremely valuable for validating serialized
    messages passed between machines. This method requires two arguments,
    the name of the document declaration to be used, and the data to be
    validated which should be submitted in the form of a hashref.

DOCUMENT NOTATION
    Validation::Class::Document exports the document (or dom) keyword which
    allows you to pre-define/configure your path matching rules for your
    data structure. The "path matching rules", which is actually a custom
    object notation, referred to as the document notation, can be thought of
    as a kind-of simplified regular expression which is executed against the
    flattened data structure. The following are a few general use-cases:

        # given the data structure
        {
            "id": "1234-A",
            "name": {
                "first_name" : "Bob",
                "last_name"  : "Smith",
             },
            "title": "CIO",
            "friends" : [],
        }

        # select id to validate against the string rules
        document 'foobar' =&gt;
            { 'id' =&gt; 'string' };

        # select name -&gt; first_name/last_name to validate against the string rules
        document 'foobar' =&gt;
          {'name.first_name' =&gt; 'string', 'name.last_name' =&gt; 'string'};

        # or
        document 'foobar' =&gt;
          {'name.*_name' =&gt; 'string'};

        # select each element in friends to validate against the string rules
        document 'foobar' =&gt;
            { 'friends.@' =&gt; 'string' };

        # or select an element within a hashref within in friends to validate
        document 'foobar' =&gt;
            { 'friends.@.name' =&gt; 'string' };

    The document declaration keys should be follow the aforementioned
    document notation scheme and the values should be strings which
    correspond to the names of fields (or other document declarations) that
    will be used to preform the data validation. It is possible to combine
    document declarations to validation hierarchical data that contains data
    strucutres matching one or more document patterns. The following is an
    example of what that might look like.

        package MyApp::Person;

        use Validation::Class::Document;

        field  'name' =&gt; {
            mixin      =&gt; [':str'],
            pattern    =&gt; qr/^[A-Za-z ]+$/,
            max_length =&gt; 20,
        };

        document 'friend' =&gt; {
            'name' =&gt; 'name'
        };

        document 'person' =&gt; {
            'name' =&gt; 'name',
            'friends.@' =&gt; 'friend'
        };

        package main;

        my $data = {
            "name"   =&gt; "Anita Campbell-Green",
            "friend" =&gt; [
                { "name" =&gt; "Horace" },
                { "name" =&gt; "Skinner" },
                { "name" =&gt; "Alonzo" },
                { "name" =&gt; "Frederick" },
            ],
        };

        my $person = MyApp::Person-&gt;new;

        unless ($person-&gt;validate_document(person =&gt; $data)) {
            warn $person-&gt;errors_to_string if $person-&gt;error_count;
        }

AUTHOR
    Al Newkirk &lt;anewkirk@ana.io&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2013 by Al Newkirk.

    This is free software; you can redistribute it and/or modify it under
    the same terms as the Perl 5 programming language system itself.

</pre></body></html>