Config::Model::ObjTreeScanner - Scan config tree and perform call-backs
use Config::Model::ObjTreeScanner ; # define tree object my $root = ... ; # defined call-backs $scan = Config::Model::ObjTreeScanner-> new ( # node callback list_cb => \&disp_hash , hash_cb => \&disp_hash, element_cb => \&disp_obj , node_cb => \&disp_obj_elt , # leaf callback leaf_cb => \&disp_leaf, enum_value_cb => \&disp_leaf, enum_integer_value_cb => \&disp_leaf, integer_value_cb => \&disp_leaf, number_value_cb => \&disp_leaf, boolean_value_cb => \&disp_leaf, string_value_cb => \&disp_leaf ) ; $scan->scan_node($root) ;
This module creates an object that will explore (depth first) a configuration tree object.
For each node or leaf encountered, the ObjTreeScanner object will call-back one of the subroutine reference passed during construction.
To continue the exploration, these call-backs must also call the scanner. (i.e. perform another call-back). In other words the user's subroutine and the scanner plays a game of ping-pong until the tree is completely explored.
The scanner provides a set of default callback for the nodes. This way, the user only have to provide call-backs for the leaves.
One way or another, the ObjTreeScanner object must be able to find all callback for all the items of the tree:
leaf_cb, enum_value_cb, enum_integer_value_cb, integer_value_cb, number_value_cb, boolean_value_cb, string_value_cb
leaf_cb
enum_value_cb
enum_integer_value_cb
integer_value_cb
number_value_cb
boolean_value_cb
string_value_cb
list_cb, hash_cb, element_cb, node_cb.
list_cb
hash_cb
element_cb
node_cb
The user may specify all of them by passing the sub ref to the constructor:
$scan = Config::Model::ObjTreeScanner-> new ( # node callback list_cb => sub , ... )
Or use some default callback using the fallback parameter. Note that at least one callback must be provided: leaf_cb.
Optional parameter:
fallback: if set to 'node', the scanner will provide default call-back for node items. If set to 'leaf', the scanner will set all leaf callback (like enum_integer_value_cb, enum_value_cb ...) to string_value_cb or to the mandatory leaf_cb value. "fallback" callback will not override callbacks provided by the user.
If set to 'all', equivalent to 'node' and 'leaf'.
The leaf callbacks will be called with the following parameters:
($object,$element,$index, $obj_object)
where:
$object is the node that contain the leaf.
$object
$element is the element (or attribute) that contain the leaf.
$element
$index is the index (or hash key) used to get the leaf. This may be undefined if the element type is scalar.
$index
$obj is the Config::Model::Value object.
$obj
Others :
($object,$element,@indexes)
@indexes is an list containing all the indexes of the array.
@indexes
($object,$element,@keys)
@keys is an list containing all the keys of the hash.
@keys
($object,@element_list)
@element_list contains all the elements of the node.
@element_list
($object,$element)
Explore the object and call element_cb on all elements.
Explore the element and call either hash_cb, list_cb, node_cb or a leaf call-back (the leaf call-back called depends on the Value object properties: enum, string, integer and so on)
Explore the hash member (or hash value) and call either node_cb or a leaf call-back.
Just like scan_hash: Explore the list member and call either node_cb or a leaf call-back.
scan_hash
Returns an list containing the sorted keys of a hash element or returns an list containning (0.. last_index) of an list element.
Throws an exception if element is not an list or a hash element.
Config::Model::Value
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
=back without =over
To install Config::Model, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Model
CPAN shell
perl -MCPAN -e shell install Config::Model
For more information on module installation, please visit the detailed CPAN module installation guide.