]>
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);
29 # Read the configuration files of Dev-Editor
31 # Params: Path to main configuration file
33 # Return: Configuration (Hash Reference)
39 my $config = parse_config
($file);
41 $config->{'errors'} = parse_config
($config->{'error_file'});
42 $config->{'templates'} = parse_config
($config->{'template_file'});
44 # Check if we have to parse the user config file
46 if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f
$config->{'userconf_file'})
48 my $userconf = parse_config
($config->{'userconf_file'});
50 # Parse aliases (we use references, so we won't get a memory
53 foreach my $user(keys(%$userconf))
55 if(my $aliases = $userconf->{$user}->{'aliases'})
57 foreach my $alias(parse_line
('\s+',0,$aliases))
59 $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias});
64 if($userconf->{$ENV{'REMOTE_USER'}})
66 # The current HTTP Auth user has got an individual configuration
67 # Overwrite the default values
69 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
71 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
72 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
74 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
76 $config->{'user_config'} = 1;
80 # Parse list of forbidden files
82 if($config->{'forbidden'})
86 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
90 $file = '/'.$file unless($file =~ m
!^/!);
96 $config->{'forbidden'} = \
@files;
100 $config->{'forbidden'} = [];
108 # Parse a configuration file
110 # Params: Path to configuration file
112 # Return: Configuration (Hash Reference)
119 open(CF
,'<'.$file) or croak
("Open $file: $!");
120 read(CF
, my $data, -s
$file);
123 my @lines = split(/\015\012|\012|\015/,$data);
128 foreach my $line(@lines)
132 next if($line =~ /^\s*#/);
134 if($line =~ /^\s*\[(\S+)\]\s*$/)
136 # Switch to new section
140 elsif($line =~ /^\s*\S+\s*=.*$/)
142 # A normal "key = value" line
144 my ($key,$value) = split(/=/,$line,2);
146 # Remove whitespaces at the beginning and at the end
155 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
157 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
159 $config->{$sect}->{$key} = $value;
163 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
165 $config->{$key} = $value;
173 # it's true, baby ;-)
patrick-canterino.de