|
NAMEConfig::Model::CheckList - Handle check list element VERSIONversion 2.155 SYNOPSIS use Config::Model;
# define configuration tree object
my $model = Config::Model->new;
$model->create_config_class(
name => "MyClass",
element => [
# type check_list uses 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( steps => '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'
DESCRIPTIONThis 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 :
CONSTRUCTORCheckList object should not be created directly. CheckList model declarationA check list element must be declared with the following parameters:
For example:
Introspection methodsThe following methods returns the checklist parameter : Choice referenceThe 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 "steps" parameter of grab(...) See refer_to parameter. Reference examples
Methodsget_typeReturns "check_list". cargo_typeReturns 'leaf'. checkSet 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) uncheckUnset 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) is_checkedParameters: "( choice, [ check => yes|skip ] , [ mode => ... ])" 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 has_dataReturn true if the check_list contains a set of checks different from default or upstream default set of check. get_choiceReturns an array of all items names that can be checked (i.e. that can have value 0 or 1). get_helpParameters: "(choice_value)" Return the help string on this choice value get_infoReturns a list of information related to the check list. See "get_info" in Config::Model::Value for more details. clearReset the check list (can also be called as "clear_values") clear_itemParameters: "(choice_value)" Reset an element of the checklist. get_checked_list_as_hashAccept a parameter (referred below as "mode" parameter) similar to "mode" in "fetch" in Config::Model::Value. 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 returns all items set by the user, or items set in preset mode or checked by default. With a "mode" parameter set to a value from the list below, this method returns:
get_checked_listParameters: "( < mode > )" Returns a list (or a list ref) of all checked items (i.e. all items set to 1). fetchParameters: "( < mode > )" Returns a string listing the checked items (i.e. "A,B,C") getParameters: "( path [, < mode> ] )" Get a value from a directory like path. Method to check or clear items in the check listAll these methods accept an optional "check" parameter that can be:
setParameters: "( path, items_to_set, [ check => [ yes | no | skip ] ] )" 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 items to set in the check list. Example : $leaf->set('','A,C,Z');
$leaf->set('','A,C,Z', check => 'skip');
set_checked_listSet all passed items to checked (1). All other available items in the check list are set to 0. Example, for a check list that contains A B C and D check items: # set cl to A=0 B=1 C=0 D=1
$cl->set_checked_list('B','D')
$cl->set_checked_list( [ 'B','D' ])
$cl->set_checked_list( [ 'B','D' ], check => 'yes')
store_setAlias to "set_checked_list", so a list and a check_list can use the same store method storeSet all items listed in a string to checked. The items must be separated by commas. All other available items in the check list are set to 0. Example: $cl->store('B, D')
$cl->store( value => 'B,C' )
$cl->store( value => 'B,C', check => 'yes' )
loadAlias to "store". set_checked_list_as_hashSet check_list items. Missing items in the given hash of parameters are cleared (i.e. set to undef). Example for a check list containing A B C D $cl->set_checked_list_as_hash( { A => 1, B => 0} , check => 'yes' )
# result A => 1 B => 0 , C and D are undef
load_dataLoad items as an array or hash ref. Array is forwarded to set_checked_list , and hash is forwarded to set_checked_list_as_hash. Example: $cl->load_data(['A','B']) # cannot use check param here
$cl->load_data( data => ['A','B'])
$cl->load_data( data => ['A','B'], check => 'yes')
$cl->load_data( { A => 1, B => 1 } )
$cl->load_data( data => { A => 1, B => 1 }, check => 'yes')
is_bad_modeAccept a mode parameter. This function checks if the mode is accepted by "fetch" method. Returns an error message if not. For instance: if (my $err = $val->is_bad_mode('foo')) {
croak "my_function: $err";
}
This method is intented as a helper ti avoid duplicating the list of accepted modes for functions that want to wrap fetch methods (like Config::Model::Dumper or Config::Model::DumpAsData) Ordered checklist methodsAll the methods below are valid only for ordered checklists. swapParameters: "( choice_a, choice_b)" Swap the 2 given choice in the list. Both choice must be already set. move_upParameters: "( choice )" Move the choice up in the checklist. move_downParameters: "( choice )" Move the choice down in the checklist. AUTHORDominique Dumont, (ddumont at cpan dot org) SEE ALSOConfig::Model, Config::Model::Instance, Config::Model::Node, Config::Model::AnyId, Config::Model::ListId, Config::Model::HashId, Config::Model::Value AUTHORDominique Dumont COPYRIGHT AND LICENSEThis 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
|