diff options
| author | fukachan <fukachan> | 2001-07-15 08:14:44 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-07-15 08:14:44 +0000 |
| commit | 5065fcb82944a5b0cfcb88b100bf3f51666b5a51 (patch) | |
| tree | f17ee4e1e8697f75ab439a66bb47f97bd54b7990 | |
| parent | 376edbf156142beaee049f3348694e128a22fe6d (diff) | |
| download | fml8-5065fcb82944a5b0cfcb88b100bf3f51666b5a51.tar.gz fml8-5065fcb82944a5b0cfcb88b100bf3f51666b5a51.tar.bz2 fml8-5065fcb82944a5b0cfcb88b100bf3f51666b5a51.zip | |
enabled read and write back configuration file
| -rw-r--r-- | fml/lib/FML/Command/edit.pm | 7 | ||||
| -rw-r--r-- | fml/lib/FML/Config.pm | 45 |
2 files changed, 43 insertions, 9 deletions
diff --git a/fml/lib/FML/Command/edit.pm b/fml/lib/FML/Command/edit.pm index 852e3121..ee8745b3 100644 --- a/fml/lib/FML/Command/edit.pm +++ b/fml/lib/FML/Command/edit.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: subscribe.pm,v 1.9 2001/05/27 14:27:54 fukachan Exp $ +# $FML: edit.pm,v 1.1 2001/07/15 04:00:27 fukachan Exp $ # package FML::Command::edit; @@ -42,7 +42,12 @@ sub edit use FML::Config; my $c = new FML::Config; + $c->read( $config_cf ); + + # replace/ovewrite $config_cf + # old $config_cf is backup'ed to $config_cf.bak + $c->write( $config_cf ); } diff --git a/fml/lib/FML/Config.pm b/fml/lib/FML/Config.pm index 7377c45c..d59c71fe 100644 --- a/fml/lib/FML/Config.pm +++ b/fml/lib/FML/Config.pm @@ -1,7 +1,7 @@ #-*- perl -*- # Copyright (C) 2000-2001 Ken'ichi Fukamachi # -# $FML: Config.pm,v 1.31 2001/07/14 14:15:05 fukachan Exp $ +# $FML: Config.pm,v 1.32 2001/07/15 04:00:26 fukachan Exp $ # package FML::Config; @@ -233,10 +233,14 @@ sub _read_file $value =~ s/\s*$//o; $curkey = $key; $config->{ $key } = $value; - $comment->{ $key } = $comment_buffer; # save variable order for re-construction e.g. used in write() - if ($mode eq 'raw') { push(@$order, $key);} + if ($mode eq 'raw') { + $comment->{ $key } = $comment_buffer; + undef $comment_buffer; + + push(@$order, $key); + } } # case 2. elsif (/^\s+(.*)/ && defined($curkey)) { @@ -263,6 +267,9 @@ appearing order. =cut +# allocate space to hold +my $config_hold_space = {}; + # Descriptions: # Arguments: $self $args @@ -284,7 +291,7 @@ sub read }); # XXX debug: removed in the future - if (1) { + if (0) { my ($k, $v); while (($k, $v) = each %$config) { print STDERR "\n[$k]\n"; @@ -297,9 +304,9 @@ sub read } # save the value in the object - $self->{ _config_template }->{ config } = $config; - $self->{ _config_template }->{ comment } = $comment; - $self->{ _config_template }->{ order } = $order; + $config_hold_space->{ config } = $config; + $config_hold_space->{ comment } = $comment; + $config_hold_space->{ order } = $order; } @@ -309,8 +316,30 @@ sub read # Return Value: none sub write { - my ($self, $file, $config) = @_; + my ($self, $file) = @_; + my $config = $config_hold_space->{ config }; + my $comment = $config_hold_space->{ comment }; + my $order = $config_hold_space->{ order }; + + # get handle to update $file + my $fh = IO::File::Atomic->open($file); + if (defined $fh) { + $fh->autoflush(1); + for my $k (@$order) { + print $fh $comment->{$k} if defined $comment->{$k}; + print $fh "$k = "; + print $fh join("\n\t", split(/\s+/, $config->{$k})); + print $fh "\n"; + print $fh "\n"; + } + $fh->close; + } + else { + use Carp; + carp("cannot open > $file"); + Log("cannot open > $file"); + } } |
