CTK::ConfGenUtil - Config::General structure utility functions
Version 2.66
use CTK; use CTK::ConfGenUtil; my $c = new CTK; my $config = $c->config; # <Foo> # <Bar> # Baz qux # </Bar> # </Foo> my $foo = node( $config, 'foo' ); # { bar => { baz => 'qux' } } my $bar = node( $config, 'foo', 'bar' ); # { baz => 'qux' } my $bar = node( $config, ['foo', 'bar'] ); # { baz => 'qux' } my $bar = node( $config, 'foo/bar' ); # { baz => 'qux' } my $baz = value( $config, 'foo/bar/baz' ); # qux # Foo bar my $foo = value( $config, 'foo' ); # bar # Foo 123 # Foo 456 # Foo 789 my $foo = array( $config, 'foo' ); # [123,456,789] # <Foo> # Bar baz # </Foo> my $foo = hash( $config, 'foo' ); # { bar => 'baz' } # <Foo> # <Bar> # Baz blah-blah-blah # Qux 123 # Qux 456 # Qux 789 # </Bar> # </Foo> is_scalar( $foo ); say "Is scalar : ", is_scalar($config, 'foo/bar/baz') ? 'OK' : 'NO'; # OK is_array( $foo ); say "Is array : ", is_array($config, 'foo/bar/qux') ? 'OK' : 'NO'; # OK is_hash( $foo ); say "Is hash : ", is_hash($config, 'foo/bar') ? 'OK' : 'NO'; # OK
This module based on Config::General::Extended
Working sample:
<Foo> <Bar> Baz blah-blah-blah Qux 123 Qux 456 Qux 789 </Bar> </Foo>
This method returns the found node of a given key.
my $bar = node( $config, 'foo', 'bar' ); my $bar = node( $config, ['foo', 'bar'] ); my $bar = node( $config, 'foo/bar' ); my $bar = node( $config, ['foo/bar'] ); my $bar_hash = hash($bar); my $baz = value($bar, 'baz'); # blah-blah-blah
This method returns the scalar value of a given key.
my $baz = value( $config, 'foo/bar/baz' );
This method returns a array reference (if it is one!) from the config which is referenced by "key". Given the sample config above you would get:
my $qux = array( $config, 'foo/bar/qux' );
This method returns a hash reference (if it is one!) from the config which is referenced by "key". Given the sample config above you would get:
my $bar = hash( $config, 'foo/bar' );
As seen above, you can access parts of your current config using hash, array or scalar functions. This function returns just true if the given key is scalar (regular value)
is_scalar( $baz ); is_scalar( $config, 'foo/bar/baz' );
As seen above, you can access parts of your current config using hash, array or scalar functions. This function returns just true if the given key is array (reference)
is_array( $qux ); is_array( $config, 'foo/bar/qux' );
As seen above, you can access parts of your current config using hash, array or scalar functions. This function returns just true if the given key is hash (reference)
is_hash( $bar ); is_hash( $config, 'foo/bar' );
Reserved. Coming soon
This method returns just true if the given key exists in the config.
Config::General::Extended
Sergey Lepenkov (Serz Minus) http://www.serzik.com <minus@mail333.com>
Copyright (C) 1998-2017 D&D Corporation. All Rights Reserved
This program is free software; you can redistribute it and/or modify it under the same terms and conditions as Perl itself.
This program is distributed under the GNU LGPL v3 (GNU Lesser General Public License version 3).
See LICENSE file
LICENSE
To install CTK, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CTK
CPAN shell
perl -MCPAN -e shell install CTK
For more information on module installation, please visit the detailed CPAN module installation guide.