Last change
on this file since 29577 was 29577, checked in by Jeremy Symon, 9 years ago |
Lots of changes to get edit mode working. Changed variable marker to %var% instead of @var@ in order to differentiate from greenstone build variables, which allows variables to be used in patch files now. Added wget dependency. Enabled cgi scripts. Added patches to set correct settings in global.properties, gsdl3site.cfg.
|
File size:
1.6 KB
|
Line | |
---|
1 | package Greenstone::Config;
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 | use utf8;
|
---|
6 | use Greenstone::Helpers;
|
---|
7 |
|
---|
8 | # Formats an array
|
---|
9 | sub replacement_array {
|
---|
10 | die "Array handling must be defined by implementation";
|
---|
11 | }
|
---|
12 |
|
---|
13 | # Determines the value to replace a variable with
|
---|
14 | sub replacement {
|
---|
15 | my ($self, $var) = @_;
|
---|
16 | my $val = $self->{config}->{$var};
|
---|
17 | die "'$var' was not defined!" unless (defined $val);
|
---|
18 | if (ref $val eq 'ARRAY') {
|
---|
19 | return $self->replacement_array ($val);
|
---|
20 | } else {
|
---|
21 | return $val;
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | # Substitutes variables with their value
|
---|
26 | sub subst {
|
---|
27 | my $self = shift;
|
---|
28 | for (@_) {
|
---|
29 | s/%([\w]+)%/$self->replacement($1)/ge;
|
---|
30 | }
|
---|
31 | return @_;
|
---|
32 | }
|
---|
33 |
|
---|
34 | # Reads a config file into the config hashmap
|
---|
35 | sub readconf {
|
---|
36 | my ($self, $conf) = @_;
|
---|
37 | $self->{config} = {} unless exists $self->{config};
|
---|
38 | open CONF, '<', $conf
|
---|
39 | or die "Failed to open '$conf' for reading: $!";
|
---|
40 | my $var;
|
---|
41 | while (my $line = <CONF>) {
|
---|
42 | if (empty $line or comment $line) {
|
---|
43 | $var = undef;
|
---|
44 | } elsif (defined $var and $line =~ /^\s/) {
|
---|
45 | trim $line;
|
---|
46 | $self->subst ($line);
|
---|
47 | escape $line;
|
---|
48 | push @{$self->{config}->{$var}}, $line;
|
---|
49 | } else {
|
---|
50 | ($var, my $val) = trim (split ":", $line, 2);
|
---|
51 | defined $var and defined $val or die "Invalid variable assignment: '$line'";
|
---|
52 | if (empty $val) {
|
---|
53 | $self->{config}->{$var} = [];
|
---|
54 | } else {
|
---|
55 | $self->subst ($val);
|
---|
56 | escape $val;
|
---|
57 | $self->{config}->{$var} = $val;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | close CONF;
|
---|
62 | }
|
---|
63 |
|
---|
64 | 1;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.