X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FInifile.pm;h=6ecb41f79ba9fcdfc2ec99f97945131ca5c73340;hb=c7241bf7c547d63999898dee7b5dd486e4d122d3;hp=f7fe27b3c60fd7afa3c0bdee0a6f616f97dc663b;hpb=db53dc8ab328b82c7af17896487674ad98f2af6b;p=kivitendo-erp.git diff --git a/SL/Inifile.pm b/SL/Inifile.pm index f7fe27b3c..6ecb41f79 100644 --- a/SL/Inifile.pm +++ b/SL/Inifile.pm @@ -37,56 +37,50 @@ package Inifile; use IO::File; +use strict; + sub new { - $main::lxdebug->enter_sub(); + $main::lxdebug->enter_sub(2); - my ($type, $file) = @_; + my ($type, $file, %options) = @_; my $id = ""; - my $skip; - - local *FH; - - my $self = { "FILE" => $file }; + my $cur; - open FH, "$file" or Form->error("$file : $!"); + my $self = { FILE => $file, ORDER => [] }; - while () { - next if m/^(#|;|\s)/; + open my $fh, "$file" or $::form->error("$file : $!"); + for (<$fh>) { chomp; - # strip comments - s/(#|;).*//g; - - # remove any trailing whitespace - s/^\s*//; - s/\s*$//; + if (!$options{verbatim}) { + # strip comments + # remove any trailing whitespace + s/\s*#.*$//; + s/^\s*//; + } else { + next if m/^\s*#/; + } next unless $_; - if (m/^\[/) { - s/(\[|\])//g; - - $id = $_; + if (m/^\[(.*)\]$/) { + $id = $1; + $cur = $self->{$1} ||= { }; - $self->{$id} ||= { }; - - push @{ $self->{ORDER} }, $_; - - next; + push @{ $self->{ORDER} }, $1; + } else { + # add key=value to $id + my ($key, $value) = split m/=/, $_, 2; + $cur->{$key} = $value; } - # add key=value to $id - my ($key, $value) = split m/=/, $_, 2; - - $self->{$id}->{$key} = $value; - } - close FH; + close $fh; - $main::lxdebug->leave_sub(); + $main::lxdebug->leave_sub(2); return bless $self, $type; } @@ -97,7 +91,7 @@ sub write { my ($self) = @_; my $file = $self->{FILE}; - my $fh = IO::File->new($file, "w") || Form->error("$file : $!"); + my $fh = IO::File->new($file, "w") || $::form->error("$file : $!"); foreach my $section_name (sort keys %{ $self }) { next if $section_name =~ m/^[A-Z]+$/; @@ -114,4 +108,3 @@ sub write { } 1; -