NAME
Config::Model::ObjTreeScanner - Scan config tree and perform call-backs
SYNOPSIS
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) ;
DESCRIPTION
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.
CONSTRUCTOR
new ( ... )
One way or another, the ObjTreeScanner object must be able to find all callback for all the items of the tree:
- leaf callback:
-
leaf_cb
,enum_value_cb
,enum_integer_value_cb
,integer_value_cb
,number_value_cb
,boolean_value_cb
,string_value_cb
- node callback:
-
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'.
Callbacks prototypes
The leaf callbacks will be called with the following parameters:
($object,$element,$index, $obj_object)
where:
$object
is the node that contain the leaf.$element
is the element (or attribute) that contain the leaf.$index
is the index (or hash key) used to get the leaf. This may be undefined if the element type is scalar.$obj
is the Config::Model::Value object.
Others :
list_cb
:-
($object,$element,@indexes)
@indexes
is an list containing all the indexes of the array. hash_cb
:-
($object,$element,@keys)
@keys
is an list containing all the keys of the hash. element_cb
:-
($object,@element_list)
@element_list
contains all the elements of the node. node_cb
-
($object,$element)
METHODS
scan_node ($object)
Explore the object and call element_cb
on all elements.
scan_element($object,$element)
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)
scan_hash ($object,$element,$key)
Explore the hash member (or hash value) and call either node_cb
or a leaf call-back.
scan_list ($object,$element,$index)
Just like scan_hash
: Explore the list member and call either node_cb
or a leaf call-back.
get_keys ($object, $element)
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.
SEE ALSO
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 136:
You forgot a '=back' before '=head1'
- Around line 193:
=back without =over