Data::DPath::Validator::Visitor - Data::Visitor subclass for generating DPaths
version 0.093411
use Data::DPath::Validator::Visitor; my $v = Data::DPath::Validator::Visitor->new(); $v->visit({foo => '*'}); $v->templates; # [ '/foo/*' ]
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.
templates contains the parsed paths from calling visit on template data
handles => { add_template => 'push' }
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 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 keeps track of how deep we are in the data structure.
handles => { lower => 'inc', higher => 'dec', },
value_type keeps track of what kind of element we are viewing inside visit_value. This attribute is important for determining path construction.
dive() increases our depth into the data structure, pushing the current template onto the template stack.
rise() decreases our depth from the data structure, popping a template from the template stack and replacing the current_template with it.
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.
visit_hash is advised to adjust our depth and prep our current template.
After calling the original method, depth is adjusted back.
visit_hash_key is advised to set value_type to HashKey prior to calling the original method
visit_hash_value is advised to set value_type to HashVal prior to calling the original method
visit_hash_entry is advised to adjust out depth prior to evaluating the key and value.
visit_array is advised to adjust our depth and prep our current template.
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.
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.
Nicholas Perez <nperez@cpan.org>
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.
To install Data::DPath::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::DPath::Validator
CPAN shell
perl -MCPAN -e shell install Data::DPath::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.