|configfile(filename)||Set the filename to be used by <B>saveB> to filename. It returns the current configured filename if called without arguments.|
Returns a new object (of Config::General::Extended Class) from the given key.
Assume you have the following config:
Or, here is another use:
If the key from which you want to create a new object is empty, an empty object will be returned. If you run the following on the above config:
Then $obj will be empty, just like if you have had run this:
Read operations on this empty object will return nothing or even fail. But you can use an empty object for creating a new config using write operations, i.e.:
If the key points to a list of hashes, a list of objects will be returned. Given the following example config:
you could write code like this to access the list the OOP way:
Please note that the list will be returned as a reference to an array.
Empty elements or non-hash elements of the list, if any, will be skipped.
This method returns a hash(if it <B>isB> one!) from the config which is referenced by
key. Given the sample config above you would get:
This the equivalent of <B>B>hash()<B>B> mentioned above, except that it returns an array.
Again, we use the sample config mentioned above:
This method returns the scalar value of a given key. Given the following sample
you could do something like that:
You can use this method also to set the value of key to something if you give over a hash reference, array reference or a scalar in addition to the key. An example:
Please note, that this method does not complain about existing values within key!
|is_hash(key) is_array(key) is_scalar(key)||
As seen above, you can access parts of your current config using hash, array or scalar
methods. But you are right if you guess, that this might become problematic, if
for example you call <B>B>hash()<B>B> on a key which is in real not a hash but a scalar. Under
normal circumstances perl would refuse this and die.
To avoid such behavior you can use one of the methods is_hash() is_array() is_scalar() to check if the value of key is really what you expect it to be.
An example(based on the config example from above):
|exists(key)||This method returns just true if the given key exists in the config.|
Returns an array of the keys under the specified key. If you use the example
config above you could do that:
If no key name was supplied, then the keys of the object itself will be returned.
|delete(key)||This method removes the given key and all associated data from the internal hash structure. If key contained data, then this data will be returned, otherwise undef will be returned.|
Given a list of nodes, ->find will search for a tree that branches in
just this way, returning the Config::General::Extended object it finds
at the bottom if it exists. You can also search partway down the tree
and ->find should return where you left off.
Another useful feature is implemented in this class using the <B>AUTOLOADB> feature of perl. If you know the keynames of a block within your config, you can access to the values of each individual key using the method notation. See the following example and you will get it:
We assume the following config:
<person> name = Moser prename = Peter birth = 12.10.1972 </person>
Now we read it in and process it:
my $conf = Config::General::Extended->new("configfile"); my $person = $conf->obj("person"); print $person->prename . " " . $person->name . " is " . $person->age . " years old\n";
This notation supports only scalar values! You need to make sure, that the block <person> does not contain any subblock or multiple identical options(which will become an array after parsing)!
Of course you can use this kind of methods for writing data too:
This changes the value of the name key to Neustein. This feature behaves exactly like <B>B>value()<B>B>, which means you can assign hash or array references as well and that existing values under the given key will be overwritten.
Copyright (c) 2000-2014 Thomas Linden
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
none known yet.
Thomas Linden <tlinden |AT| cpan.org>
|perl v5.20.3||GENERAL::EXTENDED (3)||2015-10-22|