Config...terator(3pm)

πŸ’– NAME πŸ’–

Config::Model::Iterator β€” the class that iterates forward or backward through a configuration tree.

(also, hello, this is a User Contributed Perl Documentation page, and yes it's serving πŸ’…)


✨ VERSION ✨

version 2.166


πŸ¦‹ SYNOPSIS πŸ¦‹

 use Config::Model;

 # define configuration tree object
 my $model = Config::Model->new;
 $model->create_config_class(
    name    => "Foo",
    element => [
        [qw/bar baz/] => {
            type       => 'leaf',
            value_type => 'string',
            level => 'important' ,
        },
    ]
 );
 $model->create_config_class(
    name    => "MyClass",
    element => [
        foo_nodes => {
            type       => 'hash',     # hash id
            index_type => 'string',
            level => 'important' ,
            cargo      => {
                type              => 'node',
                config_class_name => 'Foo'
            },
        },
    ],
 );

 my $inst = $model->instance( root_class_name => 'MyClass' );
 # create some Foo objects
 $inst->config_root->load("foo_nodes:foo1 - foo_nodes:foo2  ") ;

 my $my_leaf_cb = sub {
    my ($iter, $data_r,$node,$element,$index, $leaf_object) = @_ ;
    print "leaf_cb called for ",$leaf_object->location,"\n" ;
 } ;
 my $my_hash_cb = sub {
    my ($iter, $data_r,$node,$element,@keys) = @_ ;
    print "hash_element_cb called for element $element with keys @keys\n" ;
 } ;

 my $iterator = $inst -> iterator (
    leaf_cb         => $my_leaf_cb,
    hash_element_cb => $my_hash_cb ,
 );

 $iterator->start ;
 ### prints
 # hash_element_cb called for element foo_nodes with keys foo1 foo2
 # leaf_cb called for foo_nodes:foo1 bar
 # leaf_cb called for foo_nodes:foo1 baz
 # leaf_cb called for foo_nodes:foo2 bar
 # leaf_cb called for foo_nodes:foo2 baz

🌸 DESCRIPTION 🌸

okay bestie so this module gives you a class that can iterate forward or backward through a configuration tree. The iterator stops and calls back user defined subroutines on one of these conditions, no cap:

  • A configuration item contains an error (mostly undefined mandatory values) 😭
  • A configuration item contains warnings and the constructor's argument call_back_on_warning was set.
  • A configuration item has an important level and the constructor's argument call_back_on_important was set.. See level parameter for details.

The iterator supports going forward and backward (to support "back" and "next" buttons on a wizard widget). it's giving wizard energy fr fr πŸ§™β€β™€οΈ


πŸ‘‘ CONSTRUCTOR πŸ‘‘

The constructor should be used only by Config::Model::Instance with the iterator method. don't be out here calling it yourself, iykyk πŸ™ˆ

πŸŽ€ Creating an iterator πŸŽ€

A iterator requires at least two kind of call-back: a call-back for leaf elements and a call-back for hash elements (which is also used for list elements).

These call-back must be passed when creating the iterator (the parameters are named leaf_cb and hash_element_cb) β€” literally non-negotiable, they're mandatory πŸ’…

Here are the the parameters accepted by iterator:

call_back_on_important

Whether to call back when an important element is found (default 0).

call_back_on_warning

Whether to call back when an item with warnings is found (default 0).

status

Specifies the status of the element scanned by the wizard (default 'standard').

leaf_cb

Subroutine called backed for leaf elements. See "Callback prototypes" in Config::Model::ObjTreeScanner for signature and details. (mandatory)

hash_element_cb

Subroutine called backed for hash elements. See "Callback prototypes" in Config::Model::ObjTreeScanner for signature and details. (mandatory)

🌈 Custom callbacks 🌈

By default, leaf_cb is called for all types of leaf elements (i.e enum. integer, strings, ...). But you can provide dedicated call-back for each type of leaf, if you're feeling extra:

 enum_value_cb, integer_value_cb, number_value_cb, boolean_value_cb,
 uniline_value_cb, string_value_cb

Likewise, you can also provide a call-back dedicated to list elements with list_element_cb 🫢

⭐ Methods ⭐

start

Start the scan and perform call-back when needed. This function returns when the scan is completely done. she's thorough, she's committed, periodt πŸ‘‘

bail_out

When called, a variable is set so that all call_backs returns as soon as possible. Used to abort wizard. (emergency exit bestie πŸƒβ€β™€οΈπŸ’¨)

go_forward

Set wizard in forward (default) mode.

go_backward

Set wizard in backward mode.


πŸ’œ AUTHOR πŸ’œ

Dominique Dumont, (ddumont at cpan dot org)


πŸ”₯ SEE ALSO πŸ”₯

Config::Model, Config::Model::Instance, Config::Model::Node, Config::Model::HashId, Config::Model::ListId, Config::Model::Value, Config::Model::CheckList, Config::Model::ObjTreeScanner,


πŸ“ AUTHOR πŸ“

Dominique Dumont


This software is Copyright (c) 2005-2022 by Dominique Dumont.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999

and that's the whole page, bestie!! go slay your config tree traversal πŸ’–βœ¨

this has been perl v5.42.3, dated 2026-07-23, signing off from the Config::Model::Iterator manual page β€” mwah, take care of her πŸ«ΆπŸ’…πŸŽ€

πŸ“¦ where this page comes from