]>
git.p6c8.net - devedit.git/blob - modules/Config/DevEdit.pm
1 package Config
::DevEdit
;
4 # Dev-Editor - Module Config::DevEdit
6 # Read and parse the configuration files
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-08-24
21 use base
qw(Exporter);
23 @EXPORT = qw(read_config);
27 # Read the configuration files of Dev-Editor
29 # Params: Path to main configuration file
31 # Return: Configuration (Hash Reference)
37 my $config = parse_config
($file);
39 $config->{'errors'} = parse_config
($config->{'error_file'});
40 $config->{'templates'} = parse_config
($config->{'template_file'});
42 # Check if we have to parse the user config file
44 if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f
$config->{'userconf_file'})
46 my $userconf = parse_config
($config->{'userconf_file'});
48 if($userconf->{$ENV{'REMOTE_USER'}})
50 # The current HTTP Auth user has got an individual configuration
51 # Overwrite the default values
53 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
55 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
56 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
58 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
60 $config->{'user_config'} = 1;
64 # Parse list of forbidden files
66 if($config->{'forbidden'})
70 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
74 $file = '/'.$file unless($file =~ m
!^/!);
80 $config->{'forbidden'} = \
@files;
84 $config->{'forbidden'} = [];
92 # Parse a configuration file
94 # Params: Path to configuration file
96 # Return: Configuration (Hash Reference)
103 open(CF
,'<'.$file) or croak
("Open $file: $!");
104 read(CF
, my $data, -s
$file);
107 my @lines = split(/\015\012|\012|\015/,$data);
112 foreach my $line(@lines)
116 next if($line =~ /^\s*#/);
118 if($line =~ /^\s*\[(\S+)\]\s*$/)
120 # Switch to new section
124 elsif($line =~ /^\s*\S+\s*=.*$/)
126 # A normal "key = value" line
128 my ($key,$value) = split(/=/,$line,2);
130 # Remove whitespaces at the beginning and at the end
139 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
141 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
143 $config->{$sect}->{$key} = $value;
147 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
149 $config->{$key} = $value;
157 # it's true, baby ;-)
patrick-canterino.de