Config::Model::CheckList
Handle check list element
- Provided by: libconfig-model-perl (Version: 2.082-1)
- Report a bug
Handle check list element
version 2.082
use Config::Model;
# define configuration tree object
my $model = Config::Model->new;
$model->create_config_class(
name => "MyClass",
element => [
# type check_list will use Config::Model::CheckList
my_check_list => {
type => 'check_list',
choice => [ 'A', 'B', 'C', 'D' ],
help => {
A => 'A effect is this',
D => 'D does that',
}
},
],
);
my $inst = $model->instance( root_class_name => 'MyClass' );
my $root = $inst->config_root;
# put data
$root->load( step => 'my_check_list=A' );
my $obj = $root->grab('my_check_list');
my $v = $root->grab_value('my_check_list');
print "check_list value '$v' with help '", $obj->get_help($v), "'\n";
# more data
$obj->check('D');
$v = $root->grab_value('my_check_list');
print "check_list new value is '$v'\n"; # prints check_list new value is 'A,D'
This class provides a check list element for a Config::Model::Node. In other words, this class provides a list of booleans items. Each item can be set to 1 or 0.
The available items in the check list can be :
CheckList object should not be created directly.
A check list element must be declared with the following parameters:
For example:
choice_list
=> { type => 'check_list',
choice => ['A' .. 'Z'],
help => { A => 'A help', E => 'E help' } ,
},
choice_list_with_default
=> { type => 'check_list',
choice => ['A' .. 'Z'],
default_list => [ 'A', 'D' ],
},
'warped_choice_list'
=> { type => 'check_list',
warp => { follow => '- macro',
rules => { AD => { choice => [ 'A' .. 'D' ],
default_list => ['A', 'B' ] },
AH => { choice => [ 'A' .. 'H' ] },
}
}
},
The following methods returns the checklist parameter :
The choice items of a check_list can be given by another configuration element. This other element can be:
This other hash or other checklist is indicated by the "refer_to" or "computed_refer_to" parameter. "refer_to" uses the syntax of the "step" parameter of grab(...)
See refer_to parameter.
refer_to_list
=> { type => 'check_list',
refer_to => '- my_hash'
},
other_check_list => { type => 'check_list',
choice => [qw/A B C/]
},
refer_to_list
=> { type => 'check_list',
refer_to => '- other_check_list'
},
refer_to_3_lists
=> { type => 'check_list',
refer_to => '- my_hash + - my_hash2 + - my_hash3'
},
refer_to_check_list_and_choice
=> { type => 'check_list',
computed_refer_to => { formula => '- refer_to_2_list + - $var',
variables { 'var' => '- indirection ' }
},
choice => [qw/A1 A2 A3/],
},
Returns "check_list".
Returns 'leaf'.
Set choice. Parameter is either a list of choices to set or a list ref and some optional parameter. I.e:
check (\@list, check => 'skip') ;
"check" parameter decide on behavior in case of invalid choice value: either die (if yes) or discard bad value (if skip)
Unset choice. Parameter is either a list of choices to unset or a list ref and some optional parameter. I.e:
uncheck (\@list, check => 'skip') ;
"check" parameter decide on behavior in case of invalid choice value: either die (if yes) or discard bad value (if skip)
Return 1 if the given "choice" was set. Returns 0 otherwise.
"check" parameter decide on behavior in case of invalid choice value: either die (if yes) or discard bad value (if skip)
"mode" is either: custom standard preset default layered upstream_default
Returns an array of all items names that can be checked (i.e. that can have value 0 or 1).
Return the help string on this choice value
Reset the check list (can also be called as "clear_values")
Reset an element of the checklist.
Returns a hash (or a hash ref) of all items. The boolean value is the value of the hash.
Example:
{ A => 0, B => 1, C => 0 , D => 1}
By default, this method will return all items set by the user, or items set in preset mode or checked by default.
With a parameter, this method will return either:
Returns a list (or a list ref) of all checked items (i.e. all items set to 1).
Returns a string listing the checked items (i.e. "A,B,C")
Get a value from a directory like path.
Set a checklist with a directory like path. Since a checklist is a leaf, the path should be empty. The values are a comma separated list of checked items.
Example : "$leaf->set('','A,C,Z') ;"
Set all passed items to checked (1). All other available items in the check list are set to 0.
Example:
# set cl to A=0 B=1 C=0 D=1
$cl->set_checked_list('B','D')
Set check_list items. Missing items in the given list of parameters are cleared (i.e. set to undef).
Load check_list as an array or hash ref. Array is forwarded to set_checked_list , and hash is forwarded to set_checked_list_as_hash.
All the methods below are valid only for ordered checklists.
Swap the 2 given choice in the list. Both choice must be already set.
Move the choice up in the checklist.
Move the choice down in the checklist.
Dominique Dumont, (ddumont at cpan dot org)
Config::Model, Config::Model::Instance, Config::Model::Node, Config::Model::AnyId, Config::Model::ListId, Config::Model::HashId, Config::Model::Value
Dominique Dumont
This software is Copyright (c) 2005-2016 by Dominique Dumont.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999