]>
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
11 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
12 # Copyright (C) 2003-2009 Patrick Canterino
13 # All Rights Reserved.
15 # This file can be distributed and/or modified under the terms of
16 # of the Artistic License 1.0 (see also the LICENSE file found at
17 # the top level of the Dev-Editor distribution).
29 use base
qw(Exporter);
31 @EXPORT = qw(read_config);
35 # Read the configuration files of Dev-Editor
37 # Params: Path to main configuration file
39 # Return: Configuration (Hash Reference)
45 my $config = parse_config
($file);
47 $config->{'errors'} = parse_config
($config->{'error_file'});
48 $config->{'templates'} = parse_config
($config->{'template_file'});
50 # Check if we have to parse the user config file
52 if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f
$config->{'userconf_file'})
54 my $userconf = parse_config
($config->{'userconf_file'});
56 # Parse aliases (we use references, so we won't get a memory
59 foreach my $user(keys(%$userconf))
61 if(my $aliases = $userconf->{$user}->{'aliases'})
63 foreach my $alias(parse_line
('\s+',0,$aliases))
65 $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias});
70 if($userconf->{$ENV{'REMOTE_USER'}})
72 # The current HTTP Auth user has got an individual configuration
73 # Overwrite the default values
75 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
77 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
78 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
80 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
82 $config->{'hide_dot_files'} = $new_conf->{'hide_dot_files'} if(defined $new_conf->{'hide_dot_files'});
84 $config->{'user_config'} = 1;
88 # Parse list of forbidden files
90 if($config->{'forbidden'})
94 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
98 $file = '/'.$file unless($file =~ m
!^/!);
104 $config->{'forbidden'} = \
@files;
108 $config->{'forbidden'} = [];
116 # Parse a configuration file
118 # Params: Path to configuration file
120 # Return: Configuration (Hash Reference)
127 open(CF
,'<'.$file) or croak
("Open $file: $!");
128 read(CF
, my $data, -s
$file);
131 my @lines = split(/\015\012|\012|\015/,$data);
136 foreach my $line(@lines)
140 next if($line =~ /^\s*#/);
142 if($line =~ /^\s*\[(\S+)\]\s*$/)
144 # Switch to new section
148 elsif($line =~ /^\s*\S+\s*=.*$/)
150 # A normal "key = value" line
152 my ($key,$value) = split(/=/,$line,2);
154 # Remove whitespaces at the beginning and at the end
163 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
165 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
167 $config->{$sect}->{$key} = $value;
171 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
173 $config->{$key} = $value;
181 # it's true, baby ;-)
patrick-canterino.de