|
NAMEConfig::Model::Node - Class for configuration tree nodeVERSIONversion 2.149SYNOPSISuse Config::Model; # define configuration tree object my $model = Config::Model->new; $model->create_config_class( name => 'OneConfigClass', class_description => "OneConfigClass detailed description", element => [ [qw/X Y Z/] => { type => 'leaf', value_type => 'enum', choice => [qw/Av Bv Cv/] } ], status => [ X => 'deprecated' ], description => [ X => 'X-ray description (can be long)' ], summary => [ X => 'X-ray' ], accept => [ 'ip.*' => { type => 'leaf', value_type => 'uniline', summary => 'ip address', } ] ); my $instance = $model->instance (root_class_name => 'OneConfigClass'); my $root = $instance->config_root ; # X is not shown below because of its deprecated status print $root->describe,"\n" ; # name value type comment # Y [undef] enum choice: Av Bv Cv # Z [undef] enum choice: Av Bv Cv # add some data $root->load( steps => 'Y=Av' ); # add some accepted element, ipA and ipB are created on the fly $root->load( steps => q!ipA=192.168.1.0 ipB=192.168.1.1"! ); # show also ip* element created in the last "load" call print $root->describe,"\n" ; # name value type comment # Y Av enum choice: Av Bv Cv # Z [undef] enum choice: Av Bv Cv # ipA 192.168.1.0 uniline # ipB 192.168.1.1 uniline DESCRIPTIONThis class provides the nodes of a configuration tree. When created, a node object gets a set of rules that defines its properties within the configuration tree.Each node contain a set of elements. An element can contain:
Configuration class declarationA class declaration is made of the following parameters:
Element declarationElement typeEach element is declared with a list ref that contains all necessary information:element => [ foo => { ... } ] This most important information from this hash ref is the mandatory type parameter. The type type can be:
Node elementWhen declaring a "node" element, you must also provide a "config_class_name" parameter. For instance:$model ->create_config_class ( name => "ClassWithOneNode", element => [ the_node => { type => 'node', config_class_name => 'AnotherClass', }, ] ) ; Leaf elementWhen declaring a "leaf" element, you must also provide a "value_type" parameter. See Config::Model::Value for more details.Hash elementWhen declaring a "hash" element, you must also provide a "index_type" parameter.You can also provide a "cargo_type" parameter set to "node" or "leaf" (default). See Config::Model::HashId and Config::Model::AnyId for more details. List elementYou can also provide a "cargo_type" parameter set to "node" or "leaf" (default).See Config::Model::ListId and Config::Model::AnyId for more details. ConstructorThe "new" constructor accepts the following parameters:
Introspection methodsnameReturns the location of the node, or its config class name (for root node).get_typeReturns "node".config_modelReturns the entire configuration model (Config::Model object).modelReturns the configuration model of this node (data structure).config_class_nameReturns the configuration class name of this node.instanceReturns the instance object containing this node. Inherited from Config::Model::AnyThinghas_elementArguments: "( name => element_name, [ type => searched_type ], [ autoadd => 1 ] )"Returns 1 if the class model has the element declared. Returns 1 as well if "autoadd" is 1 (i.e. by default) and the element name is matched by the optional "accept" model parameter. If "type" is specified, the element name must also match the type. find_elementParameters: "( element_name , [ case => any ])"Returns $name if the class model has the element declared or if the element name is matched by the optional "accept" parameter. If "case" is set to any, "has_element" returns the element name who match the passed name in a case-insensitive manner. Returns empty if no matching element is found. model_searcherReturns an object dedicated to search an element in the configuration model.This method returns a Config::Model::SearchElement object. See Config::Model::SearchElement for details on how to handle a search. This method is inherited from Config::Model::AnyThing. element_modelParameters: "( element_name )"Returns model of the element. element_typeParameters: "( element_name )"Returns the type (e.g. leaf, hash, list, checklist or node) of the element. Also returns the type of a potentially accepted element. Dies if the element is not known or cannot be accepted. element_nameReturns the element name that contain this object. Inherited from Config::Model::AnyThingindex_valueSee "index_value()" in Config::Model::AnyThingparentSee "parent" in Config::Model::AnyThingrootSee "root" in Config::Model::AnyThinglocationSee "location" in Config::Model::AnyThingbackend_support_annotationReturns 1 if at least one of the backends attached to self or a parent node support to read and write annotations (aka comments) in the configuration file.Element property managementget_element_namesReturn all available element names, including the element that were accepted.Optional parameters are:
"type" and "cargo_type" parameters can be specified together. In this case, this method returns parameters that satisfy both conditions. I.e. with "type =>'hash', cargo_type => 'leaf'", this method returns only hash elements that contain leaf objects. Returns a list in array context, and a string (e.g. "join(' ',@array)") in scalar context. childrenLike "get_element_names" without parameters. Returns the list of elements. This method is polymorphic for all non-leaf objects of the configuration tree.next_elementThis method provides a way to iterate through the elements of a node. Mandatory parameter is "name". Optional parameter: "status".Returns the next element name for status (default "normal"). Returns undef if no next element is available. previous_elementParameters: "( name => element_name )"This method provides a way to iterate through the elements of a node. Returns the previous element name. Returns undef if no previous element is available. get_element_propertyParameters: "( element => ..., property => ... )"Retrieve a property of an element. I.e. for a model : status => [ X => 'deprecated' ] element => [ X => { ... } ] This call returns "deprecated": $node->get_element_property ( element => 'X', property => 'status' ) set_element_propertyParameters: "( element => ..., property => ... )"Set a property of an element. reset_element_propertyParameters: "( element => ... )"Reset a property of an element according to the original model. Information managementfetch_elementArguments: "( name => .. , [ check => ..], [ autoadd => 1 ] )"Fetch and returns an element from a node if the class model has the element declared. Also fetch and returns an element from a node if "autoadd" is 1 (i.e. by default) and the element name is matched by the optional "accept" model parameter. "check" can be set to "yes", "no" or "skip". When "check" is "no" or "skip", this method returns "undef" when the element is unknown, or 0 if the element is not available (hidden). By default, "accepted" elements are automatically created. Set "autoadd" to 0 when this behavior is not wanted. fetch_element_valueParameters: "( name => ... [ check => ...] )"Fetch and returns the value of a leaf element from a node. fetch_gistReturn the gist of the node. See description of "gist" parameter above.store_element_valueParameters: "( name, value )"Store a value in a leaf element from a node. Can be invoked with named parameters (name, value, check). E.g. ( name => 'foo', value => 'bar', check => 'skip' ) is_element_availableParameters: "( name => ..., )"Returns 1 if the element "name" is available and if the element is not "hidden". Returns 0 otherwise. As a syntactic sugar, this method can be called with only one parameter: is_element_available( 'element_name' ) ; accept_elementParameters: "( name )"Checks and returns the appropriate model of an acceptable element (i.e. declared as a model "element" or part of an "accept" declaration). Returns undef if the element cannot be accepted. accept_regexpParameters: "( name )"Returns the list of regular expressions used to check for acceptable parameters. Useful for diagnostics. element_existsParameters: "( element_name )"Returns 1 if the element is known in the model. is_element_definedParameters: "( element_name )"Returns 1 if the element is defined. grabSee "grab"" in Config::Model::Role::Grab.grab_valueSee "grab_value"" in Config::Model::Role::Grab.grab_rootSee "grab_root" in Config::Model::Role::Grab.getParameters: "( path => ..., mode => ... , check => ... , get_obj => 1|0, autoadd => 1|0)"Get a value from a directory like path. If "get_obj" is 1, "get" returns a leaf object instead of returning its value. setParameters: "( path , value)"Set a value from a directory like path. Validationdeep_checkScan the tree and deep check on all elements that support this. Currently only hash or list element have this feature.data modificationmigrateForce a read of the configuration and perform all changes regarding deprecated elements or values. Return 1 if data needs to be saved.apply_fixesScan the tree from this node and apply fixes that are attached to warning specifications. See "warn_if_match" or "warn_unless_match" in "" in Config::Model::Value.loadParameters: "( steps => string [ ... ])"Load configuration data from the string into the node and its siblings. This string follows the syntax defined in Config::Model::Loader. See "load" in Config::Model::Loader for details on parameters. This method can also be called with a single parameter: $node->load("some data:to be=loaded"); load_dataParameters: "( data => hash_ref, [ check => $check, ... ])"Load configuration data with a hash ref. The hash ref key must match the available elements of the node (or accepted element). The hash ref structure must match the structure of the configuration model. Use "check => skip" to make data loading more tolerant: bad data are discarded. "load_data" can be called with a single hash ref parameter. Returns 1 if some data were saved (instead of skipped). needs_savereturn 1 if one of the elements of the node's sub-tree has been modified.Serializationdump_treeDumps the configuration data of the node and its siblings into a string. See "dump_tree" in Config::Model::Dumper for parameter details.This string follows the syntax defined in Config::Model::Loader. The string produced by "dump_tree" can be passed to "load". dump_annotations_as_podDumps the configuration annotations of the node and its siblings into a string. See "dump_annotations_as_pod" in Config::Model::Dumper for parameter details.describeParameters: "( [ element => ... ] )"Provides a description of the node elements or of one element. reportProvides a text report on the content of the configuration below this node.auditProvides a text audit on the content of the configuration below this node. This audit shows only value different from their default value.copy_fromParameters: "( from => another_node_object, [ check => ... ] )"Copy configuration data from another node into this node and its siblings. The copy can be made in a tolerant mode where invalid data is discarded with "check => skip". This method can be called with a single argument: "copy_from($another_node)" Help managementget_helpParameters: "( [ [ description | summary ] => element_name ] )"If called without element, returns the description of the class (Stored in "class_description" attribute of a node declaration). If called with an element name, returns the description of the element (Stored in "description" attribute of a node declaration). If called with 2 argument, either return the "summary" or the "description" of the element. Returns an empty string if no description was found. get_infoReturns a list of information related to the node. See "get_info" in Config::Model::Value for more details.tree_searcherParameters: "( type => ... )"Returns an object able to search the configuration tree. Parameters are :
Then, "search" method must then be called on the object returned by "tree_searcher". Returns a Config::Model::TreeSearcher object. Lazy load of node dataAs configuration model are getting bigger, the load time of a tree gets longer. The Config::Model::BackendMgr class provides a way to load the configuration information only when needed.AUTHORDominique Dumont, (ddumont at cpan dot org)SEE ALSOConfig::Model, Config::Model::Instance, Config::Model::HashId, Config::Model::ListId, Config::Model::CheckList, Config::Model::WarpedNode, Config::Model::ValueAUTHORDominique DumontCOPYRIGHT 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
Visit the GSP FreeBSD Man Page Interface. |