head 1.7; access; symbols FSL_1_7_0:1.7 CFG_0_9_11:1.7 FSL_1_6_1:1.6 CFG_0_9_10:1.6 FSL_1_6_0:1.6 FSL_1_6b2:1.6 CFG_0_9_9:1.6 FSL_1_6b1:1.6 CFG_0_9_8:1.6 CFG_0_9_7:1.5 CFG_0_9_6:1.5 CFG_0_9_5:1.5; locks; strict; comment @# @; 1.7 date 2006.08.10.19.36.00; author rse; state Exp; branches; next 1.6; commitid Isy241gp4yykKkIr; 1.6 date 2004.12.31.19.16.34; author rse; state Exp; branches; next 1.5; 1.5 date 2004.11.27.19.41.18; author rse; state Exp; branches; next 1.4; 1.4 date 2004.11.27.19.40.33; author rse; state Exp; branches; next 1.3; 1.3 date 2004.11.20.17.09.35; author rse; state Exp; branches; next 1.2; 1.2 date 2004.11.17.13.15.35; author rse; state Exp; branches; next 1.1; 1.1 date 2004.11.14.18.38.53; author rse; state Exp; branches; next ; desc @@ 1.7 log @cleanup source tree for status as of 2006 @ text @## ## 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 @ 1.6 log @Adjust copyright messages for new year 2005. @ text @d3 2 a4 3 ## Copyright (c) 2002-2005 Ralf S. Engelschall ## Copyright (c) 2002-2005 The OSSP Project ## Copyright (c) 2002-2005 Cable & Wireless @ 1.5 log @fix POD syntax @ text @d3 3 a5 3 ## Copyright (c) 2002-2004 Ralf S. Engelschall ## Copyright (c) 2002-2004 The OSSP Project ## Copyright (c) 2002-2004 Cable & Wireless @ 1.4 log @Ok, let's rock: add four optional post-processing functions which allow one to adjust an unpacked data structure in a way it can be used more conveniently and intuitive. @ text @d62 1 a62 1 =item C<$tree = $cfg-E>BC<(>[I @ 1.3 log @Add OSSP:::cfg::simple Perl convenience API which is an ultra high-level API allowing especially the bi-directional conversion between the C API node tree representation and a simplified Perl data structure representation. @ text @d62 1 a62 1 =item C<$tree = $cfg-E>BC<();> d68 51 @ 1.2 log @document both the C and Perl APIs @ text @d43 24 a66 1 B provides two Perl APIs: d71 1 a71 1 high-level and regular programming. d77 1 a77 1 =item CBC< OSSP::cfg;> @ 1.1 log @Initial cut for Perl bindings to OSSP cfg. Still partly broken, of course ;-) @ text @d56 37 a92 1 =item C<$cfg-E>BC<($name);> d94 1 a94 1 =item C d110 1 a110 1 =item C<$str = >BC<($rc);> d112 1 a112 1 =item C<$str = >BC<($rc);> d116 33 a148 1 =item C<$rc = >BC<($cfg);> d152 2 a153 1 Additionally, the following constants are exported for use in C<$rc>, C<$mode>, C<$fmt> and C<$ver>: d155 37 a191 6 C, C, C, C, C, C. @