projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Order: mehr fehlende Sachen in Doku ergänzt
[kivitendo-erp.git]
/
SL
/
Inifile.pm
diff --git
a/SL/Inifile.pm
b/SL/Inifile.pm
index
eae4f49
..
6ecb41f
100644
(file)
--- a/
SL/Inifile.pm
+++ b/
SL/Inifile.pm
@@
-35,63
+35,76
@@
package Inifile;
package Inifile;
+use IO::File;
+
+use strict;
+
sub new {
sub new {
- $main::lxdebug->enter_sub();
+ $main::lxdebug->enter_sub(
2
);
- my ($type, $file,
$level
) = @_;
+ my ($type, $file,
%options
) = @_;
my $id = "";
my $id = "";
- my $skip;
-
- local *FH;
+ my $cur;
-
$type = ref($self) || $self
;
+
my $self = { FILE => $file, ORDER => [] }
;
- open
FH, "$file" or F
orm->error("$file : $!");
+ open
my $fh, "$file" or $::f
orm->error("$file : $!");
- while (<FH>) {
- next if /^(#|;|\s)/;
- last if /^\./;
+ for (<$fh>) {
+ chomp;
- chop;
+ if (!$options{verbatim}) {
+ # strip comments
+ # remove any trailing whitespace
+ s/\s*#.*$//;
+ s/^\s*//;
+ } else {
+ next if m/^\s*#/;
+ }
- # strip comments
- s/\s*(#|;).*//g;
+ next unless $_;
- # remove any trailing whitespace
- s/^\s*(.*?)\s*$/$1/;
+ if (m/^\[(.*)\]$/) {
+ $id = $1;
+ $cur = $self->{$1} ||= { };
- if (/^\[/) {
- s/(\[|\])//g;
+ push @{ $self->{ORDER} }, $1;
+ } else {
+ # add key=value to $id
+ my ($key, $value) = split m/=/, $_, 2;
- $id = $_;
+ $cur->{$key} = $value;
+ }
- # if there is a level skip
- if ($skip = ($id !~ /^$level/)) {
- next;
- }
+ }
+ close $fh;
-
push @{ $self->{ORDER} }, $_
;
+
$main::lxdebug->leave_sub(2)
;
- next;
+ return bless $self, $type;
+}
- }
+sub write {
+ $main::lxdebug->enter_sub();
- if (!$skip) {
+ my ($self) = @_;
- # add key=value to $id
-
my ($key, $value) = split /=/, $_, 2
;
+ my $file = $self->{FILE};
+
my $fh = IO::File->new($file, "w") || $::form->error("$file : $!")
;
- $self->{$id}{$key} = $value;
- }
+ foreach my $section_name (sort keys %{ $self }) {
+ next if $section_name =~ m/^[A-Z]+$/;
+ my $section = $self->{$section_name};
+ print $fh "[${section_name}]\n";
+ map { print $fh "${_}=$section->{$_}\n" } sort keys %{ $section };
+ print $fh "\n";
}
}
- close FH;
- $
main::lxdebug->leave_sub
();
+ $
fh->close
();
-
bless $self, $type
;
+
$main::lxdebug->leave_sub()
;
}
1;
}
1;
-