## ## OSSP cfg - Configuration Parsing ## Copyright (c) 2002-2006 Ralf S. Engelschall ## Copyright (c) 2002-2006 The OSSP Project ## ## This file is part of OSSP cfg, a configuration parsing library which ## can be found at http://www.ossp.org/pkg/lib/cfg/. ## ## Permission to use, copy, modify, and distribute this software for ## any purpose with or without fee is hereby granted, provided that ## the above copyright notice and this permission notice appear in all ## copies. ## ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ## SUCH DAMAGE. ## ## cfg.pm: Perl Binding (Perl/POD part) ## =pod =head1 NAME OSSP::cfg - B Perl Binding =head1 DESCRIPTION B is the Perl binding to the B API. B is ... B provides three Perl APIs: =head2 SIMPLE API The simple API is a wrapper around the OO-style API and intended for working with configurations the really simple but less flexible way: =over 4 =item C =item C<$cfg = >BC< OSSP::cfg::simple;> =item C<$cfg-E>BC<($txt);> =item C<$cfg-E>BC<($tree);> =item C<$txt = $cfg-E>BC<();> =item C<$tree = $cfg-E>BC<(>[I]C<);> =item C =back The B I are: =over 4 =item C<-merge =E >I Merge all directives with a start token matching against I by appending the argument tokens of second and following directives to the first directive. The resulting data structure is changed as following: before: [['foo','foo1'],['bar'],['foo','foo2']] after: [['foo','foo1','foo2'],['bar']] =item C<-index =E >I Add all directives start tokens matching against I to a pseudo-directive element pointing to the first occurrence of the directive. before: [['foo','foo1'],['bar','bar1'],['quux','quux1']] after: [{'foo'=>1,'bar'=>2,'quux'=>3}, ['foo','foo1'],['bar','bar1'],['quux','quux1']] This leverages perlref(1)'s "Pseudo-hashes: Using an array as a hash" approach to allow one to directly access directives by name. The following are then equivalent: ...->{'bar'} ...->[2] =item C<-strip =E >I Strip start token of all directives where it matches the I. This is useful in combination with B<-index> only. before: [['foo','foo1'],['bar','bar1'],['quux','quux1']] after: [['foo1'],['bar1'],['quux1']] =item C<-flatten =E >I Flatten the tokens of all directives with a start token matching against I by replacing empty arrays with I, arrays containing a single token with just the token and leaving arrays containing more than one token as is. This is useful in combination with B<-index> and B<-strip>. before: [['foo','foo1'],['bar'],['']] after: [['foo','foo1'],'bar',1] =back =head2 OO-STYLE API The OO-style API is a wrapper around the C-style API and intended for high-level and flexible programming. =over 4 =item C =item C<$cfg = >BC< OSSP::cfg;> =item C =item [C<(>]C<$error>[C<, $rc)>]C< = $cfg-E>BC<($cfg>[C<, $rc>]C<);> =item C<$ver = $cfg-E>BC<();> =item C<$cfg-E>BC<($name, $fmt, $str);> =item C<$str = $cfg-E>BC<($name, $fmt);> =item C<$node = $cfg-E>BC<();> =item C<$cfg-E>BC<($node);> =item C<$node2 = $cfg-E>BC<($node);> =item C<$cfg-E>BC<($node, $attr, $value);> =item C<$value = $cfg-E>BC<($node, $attr);> =item C<$node = $cfg-E>BC<();> =item C<$result = $cfg-E>BC<($node, $spec);> =item C<$cont = $cfg-E>BC<($node, \&cb_fct_cmp, $cb_ctx_cmp);> =item C<$cfg-E>BC<($node, \&cb_fct_cmp, $cb_ctx_cmp, \&cb_fct_cb, $cb_ctx_cb);> =item C<$cfg-E>BC<($node, $token);> =item C<$cfg-E>BC<($node, $id, $node2);> =item C<$cfg-E>BC<($node);> =item C<$cfg-E>BC<($data, $attr, $value);> =item C<$value = $cfg-E>BC<($data, $attr);> =item C<$cfg-E>BC<($data, $ctrl>[C<, $value>]C<);> =back =head2 C-STYLE API The C-style API is a direct mapping of the B ISO-C API to Perl and is intended for low-level programming. See cfg(3) for a description of the functions and their expected arguments. =over 4 =item C =item CBC<($cfg);> =item C<$rc = >BC<($cfg);> =item C<$rc = >BC<($cfg, $rc, $error);> =item C<$ver = >BC<();> =item C<$rc = >BC<($cfg, $node, $fmt, $in_ptr, $in_len);> =item C<$rc = >BC<($cfg, $node, $fmt, $ex_ptr, $ex_len);> =item C<$rc = >BC<($cfg, $node);> =item C<$rc = >BC<($cfg, $node);> =item C<$rc = >BC<($cfg, $node, $node2);> =item C<$rc = >BC<($cfg, $node, $attr, ...);> =item C<$rc = >BC<($cfg, $node, $attr, ...);> =item C<$rc = >BC<($cfg, $node);> =item C<$rc = >BC<($cfg, $node, $result, $spec);> =item C<$rc = >BC<($cfg, $node, $cb_fct_cmp, $cb_ctx_cmp, $cont);> =item C<$rc = >BC<($cfg, $node, $cb_fct_cmp, $cb_ctx_cmp, $cb_fct_cb, $cb_ctx_cb);> =item C<$rc = >BC<($cfg, $node, $token);> =item C<$rc = >BC<($cfg, $node, $id, $node2);> =item C<$rc = >BC<($cfg, $node);> =item C<$rc = >BC<($data, $attr, ...);> =item C<$rc = >BC<($data, $attr, ...);> =item C<$rc = >BC<($data, $ctrl, ...);> =back Additionally, the following constants are exported for use in C<$rc>, C<$attr>, C<$ctrl> and variable arguments: C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C. =head1 EXAMPLES FIXME =head1 SEE ALSO cfg(3), cfg-config(1). =head1 HISTORY The Perl binding B to B was implemented in November 2004 by Ralf S. Engelschall Erse@engelschall.comE. =cut