summaryrefslogtreecommitdiff
path: root/fml
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-07-14 14:15:05 +0000
committerfukachan <fukachan>2001-07-14 14:15:05 +0000
commit27f8eda25c6ec2f18681cf0e8f3bf9f593095f8f (patch)
tree267ac5d45ae7c8ddcbab93c4751a50e5c121d972 /fml
parentdf696638a0d564c217eeee4e575e29147a5effc5 (diff)
downloadfml8-27f8eda25c6ec2f18681cf0e8f3bf9f593095f8f.tar.gz
fml8-27f8eda25c6ec2f18681cf0e8f3bf9f593095f8f.tar.bz2
fml8-27f8eda25c6ec2f18681cf0e8f3bf9f593095f8f.zip
define _read_file() split from load_file() for further extension
Diffstat (limited to 'fml')
-rw-r--r--fml/lib/FML/Config.pm61
1 files changed, 47 insertions, 14 deletions
diff --git a/fml/lib/FML/Config.pm b/fml/lib/FML/Config.pm
index 688ac32a..4ac6f4cd 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.29 2001/05/18 17:30:09 fukachan Exp $
+# $FML: Config.pm,v 1.30 2001/05/27 14:27:53 fukachan Exp $
#
package FML::Config;
@@ -165,6 +165,41 @@ sub load_file
my ($self, $file) = @_;
my $config = \%_fml_config;
+ # read configuration file
+ $self->_read_file({
+ file => $file,
+ config => $config,
+ });
+
+ # At the first time, save $config to another hash, which is used
+ # as a default value at variable comparison.
+ unless (%_default_fml_config) {
+ %_default_fml_config = %_fml_config;
+ }
+
+ # flag on: we need $config->{ key } needs variable expansion
+ $need_expansion_variables = 1;
+}
+
+
+# Descriptions: read configuration file and the keys and values to
+# $config (REF HASH).
+#
+# XXX we should not reset $config since we permit
+# XXX $config can be overwritten.
+#
+# Arguments: $self $file $config $options
+# $file = configuration file
+# $config = area to store {key => value } hash
+# $options = REFHASH to describe a hash for options
+# Side Effects: $config changes
+# Return Value: none
+sub _read_file
+{
+ my ($self, $args) = @_;
+ my $file = $args->{ 'file' };
+ my $config = $args->{ 'config' };
+
# open the $file by using FileHandle.pm
use FileHandle;
my $fh = new FileHandle $file;
@@ -172,21 +207,27 @@ sub load_file
if (defined $fh) {
my ($key, $value, $curkey);
+ # For example
+ # var = key1 (case 1.)
+ # var = key1 key2 (case 1.)
+ # var = key1 (case 1.)
+ # key2 (case 2.)
+ #
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"
- # here we go
- chop;
-
+ # case 1.
if (/^([A-Za-z0-9_]+)\s+=\s*(.*)/) {
my ($key, $value) = ($1, $2);
- $value =~ s/\s*$//o;
+ $value =~ s/\s*$//o;
$curkey = $key;
$config->{$key} = $value;
}
- if (/^\s+(.*)/) {
+ # case 2.
+ elsif (/^\s+(.*)/) {
my $value = $1;
$value =~ s/\s*$//o;
$config->{ $curkey } .= " ". $value;
@@ -197,14 +238,6 @@ sub load_file
else {
$self->error_set("Error: cannot open $file");
}
-
- # first time
- unless (%_default_fml_config) {
- %_default_fml_config = %_fml_config;
- }
-
- # flag on: we need $config->{ key } needs variable expansion
- $need_expansion_variables = 1;
}