Nicholas Perez > Data-DPath-Validator > Data::DPath::Validator::Visitor

Download:
Data-DPath-Validator-0.093411.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.093411   Source  

NAME ^

Data::DPath::Validator::Visitor - Data::Visitor subclass for generating DPaths

VERSION ^

version 0.093411

SYNOPSIS ^

    use Data::DPath::Validator::Visitor;
    my $v = Data::DPath::Validator::Visitor->new();
    $v->visit({foo => '*'});

    $v->templates; # [ '/foo/*' ]

DESCRIPTION ^

Data::DPath::Validator::Visitor subclasses Data::Visitor to parse arbitrary Perl data structures into Data::DPath paths. It stores these paths in its templates attribute.

ATTRIBUTES ^

templates is: ro, isa: ArrayRef[Str], traits: Array

templates contains the parsed paths from calling visit on template data

    handles =>
    {
        add_template => 'push'
    }

current_template is: ro, isa: Str, default: '', traits: String

current_template holds the template as it is being build prior to being added to the templates attribute

    handles =>
    {
        append_text => 'append',
        prepend_text => 'prepend',
        reset_template => 'clear',
    }

template_stack is: ro, isa: ArrayRef[Str], default: [], traits: Array

template_stack maintains the templates as we branch down the data structure. At each level down, the current template is pushed onto the stack and popped off when the that branch bottom is reached.

    handles =>
    {
        push_template => 'push',
        pop_template => 'pop',
    },

structure_depth is: ro, isa: Int, default: 0, traits: Counter

structure_depth keeps track of how deep we are in the data structure.

    handles =>
    {
        lower => 'inc',
        higher => 'dec',
    },

value_type is: rw, isa: enum ArrayElem HashVal HashKey NONE, default:NONE

value_type keeps track of what kind of element we are viewing inside visit_value. This attribute is important for determining path construction.

METHODS ^

dive

dive() increases our depth into the data structure, pushing the current template onto the template stack.

rise

rise() decreases our depth from the data structure, popping a template from the template stack and replacing the current_template with it.

visit_value

visit_value is overriden to provide the meat of the DPath generation algorithm. It reads $self->value_type to know how append to the current_template.

around visit_hash

visit_hash is advised to adjust our depth and prep our current template.

After calling the original method, depth is adjusted back.

around visit_hash_key

visit_hash_key is advised to set value_type to HashKey prior to calling the original method

around visit_hash_value

visit_hash_value is advised to set value_type to HashVal prior to calling the original method

around visit_hash_entry

visit_hash_entry is advised to adjust out depth prior to evaluating the key and value.

After calling the original method, depth is adjusted back.

around visit_array

visit_array is advised to adjust our depth and prep our current template.

After calling the original method, depth is adjusted back.

around visit_array_entry

visit_array_entry is advised to set the value_type to ArrayElem and to also prep the current template with the array index before calling the original.

After calling the original method, depth is adjusted back.

around visit

visit is advised to prep the initial template if the structure depth is zero before calling the original. Afterward, if the depth has resolved back to zero, the current template is reset.

AUTHOR ^

Nicholas Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2009 by Infinity Interactive.

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

syntax highlighting: