]>
git.p6c8.net - devedit.git/blob - modules/Config/DevEdit.pm
8d9d50398f6eb7d19a388e25c66ea984edb608d1
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->{'hide_dot_files'} = $new_conf->{'hide_dot_files'} if(defined $new_conf->{'hide_dot_files'});
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