File: Conf.pm

package info (click to toggle)
haci 0.97c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,816 kB
  • sloc: perl: 19,106; sh: 190; makefile: 8
file content (83 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package HaCi::Conf;

use strict;
use Config::General qw(ParseConfig);

require Exporter;
our @ISA        = qw(Exporter);
our @EXPORT_OK  = qw(getConfigValue);

our $conf	= {};

#------------------------------------------------
sub init($) {
	my $workDir	= shift;
	$conf				= {};

	$ENV{workdir}	= $workDir;

	my $internalConfFile	= $ENV{workdir} . '/etc/internal.conf';
	unless (open ICONF, $internalConfFile) {
		die "Cannot open internal Config File '$internalConfFile': $!\n";
	}
	my $data	= join('', <ICONF>);
	close ICONF;

	eval {
		my %config	= ParseConfig(
			-String							=> $data,
			-LowerCaseNames			=> 1,
			-UseApacheInclude		=> 1,
			-IncludeRelative		=> 1,
			-IncludeDirectories	=> 1,
			-IncludeGlob				=> 1,
			-AutoTrue						=> 1,
			-InterPolateVars		=> 1,
			-InterPolateEnv			=> 1,
			-FlagBits						=> {
				status													=> {},
				pluginDefaultOndemandMenu				=> [],
				pluginDefaultGlobRecurrentMenu	=> [],
				pluginDefaultRecurrentMenu			=> [],
				pluginDefaultGlobOndemandMenu		=> [],
			},
		);

		foreach (qw/plugindefaultglobondemandmenu plugindefaultglobrecurrentmenu plugindefaultrecurrentmenu plugindefaultondemandmenu/) {
			if (ref($config{static}{$_}) eq 'HASH') {
				if (keys %{$config{static}{$_}} == 0) {
					$config{static}{$_}  = [];
				} else {
					$config{static}{$_}  = [$config{static}{$_}];
				}
			}
		}

		%{$conf}	= %config;
		undef %config;
	};
	if ($@) {
		die "Error while reading Config String (Conf.pm): $@\n";
	}
}

sub getConfigValue {
	warn 'SUB: ' . (caller(0))[3] . ' (' . (caller(1))[3] . ")\n" if $conf->{var}->{showsubs};
	my @keys	= @_;

	return unless @keys;

	my $key		= '';
	foreach (@keys) {
		my $currKey	= lc($_);
		$key				.= "->{$currKey}";
	}
	my $userKey		= eval"\$conf->{user}$key";
	my $staticKey	= eval"\$conf->{static}$key";

	return (defined $userKey) ? $userKey : $staticKey;
}

1;

# vim:ts=2:sw=2:sws=2