Config-IniFiles
view release on metacpan or search on metacpan
lib/Config/IniFiles.pm view on Meta::CPAN
package Config::IniFiles;
require 5.008;
use strict;
use warnings;
our $VERSION = '3.002000';
use Carp;
use Symbol 'gensym', 'qualify_to_ref'; # For the 'any data type' hack
use Fcntl qw( SEEK_SET SEEK_CUR );
use List::Util 1.33 qw(any none);
use File::Basename qw( dirname );
use File::Temp qw/ tempfile /;
@Config::IniFiles::errors = ();
# $Header: /home/shlomi/progs/perl/cpan/Config/IniFiles/config-inifiles-cvsbackup/config-inifiles/IniFiles.pm,v 2.41 2003-12-08 10:50:56 domq Exp $
sub _nocase
{
my $self = shift;
if (@_)
{
$self->{nocase} = ( shift(@_) ? 1 : 0 );
}
return $self->{nocase};
}
sub _is_parm_in_sect
{
my ( $self, $sect, $parm ) = @_;
return any { $_ eq $parm } @{ $self->{myparms}{$sect} };
}
sub new
{
my $class = shift;
my %parms = @_;
my $errs = 0;
my @groups = ();
my $self = bless {
default => '',
fallback => undef,
fallback_used => 0,
imported => undef,
v => {},
cf => undef,
nomultiline => 0,
handle_trailing_comment => 0,
}, $class;
if ( ref( $parms{-import} )
&& ( $parms{-import}->isa('Config::IniFiles') ) )
{
$self->{imported} = $parms{-import}; # ReadConfig will load the data
$self->{negativedeltas} = 1;
}
elsif ( defined $parms{-import} )
{
carp "Invalid -import value \"$parms{-import}\" was ignored.";
} # end if
delete $parms{-import};
# Copy the original parameters so we
# can use them when we build new sections
%{ $self->{startup_settings} } = %parms;
# Parse options
my ( $k, $v );
$self->_nocase(0);
lib/Config/IniFiles.pm view on Meta::CPAN
This is called a I<delta file> (see L</WriteConfig>). The untouched
[section2] and arg0 do not appear, and the config file is therefore
shorter; while of course, reloading the configuration into C<$master>
and C<$overlay>, either through C<< $overlay->ReadConfig() >> or through
the same code as above (e.g. when application restarts), would yield
exactly the same result had the overlay object been saved in whole to
the file system.
The only problem with this delta technique is one cannot delete the
default values in the overlay configuration file, only change
them. This is solved by a file format extension, enabled by the
I<-negativedeltas> option to L</new>: if, say, one would delete
parameters like this,
$overlay->DeleteSection("section2");
$overlay->delval("section1", "arg0");
$overlay->WriteConfig('overlay.ini', -delta=>1);
The I<overlay.ini> file would now read:
; overlay.ini
[section1]
; arg0 is deleted
arg1=anotherval
; [section2] is deleted
[section3]
arg3=val3
Assuming C<$overlay> was later re-read with C<< -negativedeltas => 1 >>,
the parser would interpret the deletion comments to yield the correct
result, that is, [section2] and arg0 would cease to exist in the
C<$overlay> object.
=head1 DIAGNOSTICS
=head2 @Config::IniFiles::errors
Contains a list of errors encountered while parsing the configuration
file. If the I<new> method returns B<undef>, check the value of this
to find out what's wrong. This value is reset each time a config file
is read.
=head1 BUGS
=over 3
=item *
The output from [Re]WriteConfig/OutputConfig might not be as pretty as
it can be. Comments are tied to whatever was immediately below them.
And case is not preserved for Section and Parameter names if the -nocase
option was used.
=item *
No locking is done by [Re]WriteConfig. When writing servers, take
care that only the parent ever calls this, and consider making your
own backup.
=back
=head1 Data Structure
Note that this is only a reference for the package maintainers - one of the
upcoming revisions to this package will include a total clean up of the
data structure.
$iniconf->{cf} = "config_file_name"
->{startup_settings} = \%orginal_object_parameters
->{imported} = $object WHERE $object->isa("Config::IniFiles")
->{nocase} = 0
->{reloadwarn} = 0
->{sects} = \@sections
->{mysects} = \@sections
->{sCMT}{$sect} = \@comment_lines
->{group}{$group} = \@group_members
->{parms}{$sect} = \@section_parms
->{myparms}{$sect} = \@section_parms
->{EOT}{$sect}{$parm} = "end of text string"
->{pCMT}{$sect}{$parm} = \@comment_lines
->{v}{$sect}{$parm} = $value OR \@values
->{e}{$sect} = 1 OR does not exist
->{mye}{$sect} = 1 OR does not exists
=head1 AUTHOR and ACKNOWLEDGEMENTS
The original code was written by Scott Hutton.
Then handled for a time by Rich Bowen (thanks!),
and was later managed by Jeremy Wadsack (thanks!),
and now is managed by Shlomi Fish ( L<http://www.shlomifish.org/> )
with many contributions from various other people.
In particular, special thanks go to (in roughly chronological order):
Bernie Cosell, Alan Young, Alex Satrapa, Mike Blazer, Wilbert van de Pieterman,
Steve Campbell, Robert Konigsberg, Scott Dellinger, R. Bernstein,
Daniel Winkelmann, Pires Claudio, Adrian Phillips,
Marek Rouchal, Luc St Louis, Adam Fischler, Kay Röpke, Matt Wilson,
Raviraj Murdeshwar and Slaven Rezic, Florian Pfaff
Geez, that's a lot of people. And apologies to the folks who were missed.
If you want someone to bug about this, that would be:
Shlomi Fish <shlomif@cpan.org>
If you want more information, or want to participate, go to:
L<http://sourceforge.net/projects/config-inifiles/>
Please submit bug reports using the Request Tracker interface at
L<https://rt.cpan.org/Public/Dist/Display.html?Name=Config-IniFiles> .
Development discussion occurs on the mailing list
config-inifiles-dev@lists.sourceforge.net, which you can subscribe
to by going to the project web site (link above).
=head1 LICENSE
( run in 1.805 second using v1.01-cache-2.11-cpan-13bb782fe5a )