diff options
| author | fukachan <fukachan> | 2001-07-15 04:00:26 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-07-15 04:00:26 +0000 |
| commit | 376edbf156142beaee049f3348694e128a22fe6d (patch) | |
| tree | bd5f73e0126b32fdc082d06e579c0b80bd455b0a | |
| parent | 27f8eda25c6ec2f18681cf0e8f3bf9f593095f8f (diff) | |
| download | fml8-376edbf156142beaee049f3348694e128a22fe6d.tar.gz fml8-376edbf156142beaee049f3348694e128a22fe6d.tar.bz2 fml8-376edbf156142beaee049f3348694e128a22fe6d.zip | |
prepare "makefml edit $ml_name" command which provides methods to
read/write configuration file keeping the comment.
We can read one configuration file and holds the information in the
object. This is a prototype. We need to implement methods to write
and edit them.
| -rw-r--r-- | fml/lib/FML/Command/edit.pm | 68 | ||||
| -rw-r--r-- | fml/lib/FML/Config.pm | 95 |
2 files changed, 152 insertions, 11 deletions
diff --git a/fml/lib/FML/Command/edit.pm b/fml/lib/FML/Command/edit.pm new file mode 100644 index 00000000..852e3121 --- /dev/null +++ b/fml/lib/FML/Command/edit.pm @@ -0,0 +1,68 @@ +#-*- perl -*- +# +# Copyright (C) 2001 Ken'ichi Fukamachi +# 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 $ +# + +package FML::Command::edit; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + +=head1 NAME + +FML::Command::edit - edit a new member + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +See C<FML::Command> for more details. + +=head1 METHODS + +=head2 C<edit( $address )> + +=cut + + +sub edit +{ + my ($self, $curproc, $args) = @_; + my $config = $curproc->{ config }; + my $options = $args->{ options }; + my $address = $args->{ address } || $options->[ 0 ]; + + # ML's home directory + my $ml_home_dir = $args->{ 'args' }->{ 'ml_home_dir' }; + my $config_cf = $ml_home_dir."/config.cf"; + + use FML::Config; + my $c = new FML::Config; + $c->read( $config_cf ); +} + + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2001 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::edit appeared in fml5 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Config.pm b/fml/lib/FML/Config.pm index 4ac6f4cd..7377c45c 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.30 2001/05/27 14:27:53 fukachan Exp $ +# $FML: Config.pm,v 1.31 2001/07/14 14:15:05 fukachan Exp $ # package FML::Config; @@ -197,15 +197,18 @@ sub load_file sub _read_file { my ($self, $args) = @_; - my $file = $args->{ 'file' }; - my $config = $args->{ 'config' }; + my $file = $args->{ 'file' }; + my $config = $args->{ 'config' } || {}; + my $comment = $args->{ 'comment' } || {}; + my $order = $args->{ 'order' } || []; + my $mode = defined $args->{ 'mode' } ? $args->{ 'mode' } : 'default'; # open the $file by using FileHandle.pm use FileHandle; my $fh = new FileHandle $file; if (defined $fh) { - my ($key, $value, $curkey); + my ($key, $value, $curkey, $comment_buffer); # For example # var = key1 (case 1.) @@ -216,18 +219,27 @@ sub _read_file while (<$fh>) { last if /^=cut/; # end of postfix format next if /^=/; # ignore special keywords of pod formats - next if /^\#/; # ignore comments - chop; # nuke trailing "\n" + + if ($mode eq 'raw') { # save comment buffer + if (/^\s*\#/) { $comment_buffer .= $_;} + } + else { # in 'default' mode, nuke trailing "\n" + chop; + } # case 1. if (/^([A-Za-z0-9_]+)\s+=\s*(.*)/) { - my ($key, $value) = ($1, $2); - $value =~ s/\s*$//o; - $curkey = $key; - $config->{$key} = $value; + my ($key, $value) = ($1, $2); + $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);} } # case 2. - elsif (/^\s+(.*)/) { + elsif (/^\s+(.*)/ && defined($curkey)) { my $value = $1; $value =~ s/\s*$//o; $config->{ $curkey } .= " ". $value; @@ -241,6 +253,67 @@ sub _read_file } +=head2 C<read(file)> + +read configuration from the specified file. +Internally it holds configuration and comment information in +appearing order. + +=head2 C<write(file)> + +=cut + + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# Return Value: none +sub read +{ + my ($self, $file) = @_; + my $config = {}; + my $comment = {}; + my $order = []; + + $self->_read_file({ + file => $file, + config => $config, + comment => $comment, + order => $order, + mode => 'raw', + }); + + # XXX debug: removed in the future + if (1) { + my ($k, $v); + while (($k, $v) = each %$config) { + print STDERR "\n[$k]\n"; + print STDERR " value $v\n"; + if (defined $comment->{ $k }) { + my $comment = $comment->{ $k }; + print STDERR " comment\n{$comment}\n"; + } + } + } + + # save the value in the object + $self->{ _config_template }->{ config } = $config; + $self->{ _config_template }->{ comment } = $comment; + $self->{ _config_template }->{ order } = $order; +} + + +# Descriptions: +# Arguments: $self $args +# Side Effects: +# Return Value: none +sub write +{ + my ($self, $file, $config) = @_; + +} + + =head2 C<expand_variables()> expand all variables in C<%_default_fml_config> and C<%_fml_config>. |
