]>
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-09-30
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 # Parse aliases (we use references, so we won't get a memory
51 foreach my $user(keys(%$userconf))
53 if(my $aliases = $userconf->{$user}->{'aliases'})
55 foreach my $alias(parse_line
('\s+',0,$aliases))
57 $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias});
62 if($userconf->{$ENV{'REMOTE_USER'}})
64 # The current HTTP Auth user has got an individual configuration
65 # Overwrite the default values
67 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
69 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
70 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
72 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
74 $config->{'user_config'} = 1;
78 # Parse list of forbidden files
80 if($config->{'forbidden'})
84 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
88 $file = '/'.$file unless($file =~ m
!^/!);
94 $config->{'forbidden'} = \
@files;
98 $config->{'forbidden'} = [];
106 # Parse a configuration file
108 # Params: Path to configuration file
110 # Return: Configuration (Hash Reference)
117 open(CF
,'<'.$file) or croak
("Open $file: $!");
118 read(CF
, my $data, -s
$file);
121 my @lines = split(/\015\012|\012|\015/,$data);
126 foreach my $line(@lines)
130 next if($line =~ /^\s*#/);
132 if($line =~ /^\s*\[(\S+)\]\s*$/)
134 # Switch to new section
138 elsif($line =~ /^\s*\S+\s*=.*$/)
140 # A normal "key = value" line
142 my ($key,$value) = split(/=/,$line,2);
144 # Remove whitespaces at the beginning and at the end
153 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
155 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
157 $config->{$sect}->{$key} = $value;
161 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
163 $config->{$key} = $value;
171 # it's true, baby ;-)
patrick-canterino.de