pjs/tools/release/Bootstrap/Config.pm

75 строки
1.4 KiB
Perl
Исходник Обычный вид История

2006-12-05 22:58:38 +03:00
#
# Config object for release automation
#
package Bootstrap::Config;
use strict;
2006-12-05 22:58:38 +03:00
# shared static config
my %config;
# single shared instance
my $singleton = undef;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
return $singleton if defined $singleton;
my $this = {};
bless($this, $class);
$this->Parse();
$singleton = $this;
return $this;
}
sub Parse {
my $this = shift;
open (CONFIG, "< bootstrap.cfg")
|| die("Can't open config file bootstrap.cfg");
2006-12-05 22:58:38 +03:00
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
2006-12-05 22:58:38 +03:00
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
2006-12-05 22:58:38 +03:00
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$config{$var} = $value;
2006-12-05 22:58:38 +03:00
}
close CONFIG;
2006-12-05 22:58:38 +03:00
}
sub Get {
my $this = shift;
my %args = @_;
my $var = $args{'var'};
die "ASSERT: Bootstep::Config::Get(): null var requested" if (not
defined($args{'var'}));
if ($this->Exists(var => $var)) {
2006-12-05 22:58:38 +03:00
return $config{$var};
} else {
die("No such config variable: $var\n");
}
}
sub Exists {
my $this = shift;
my %args = @_;
die "ASSERT: Bootstep::Config::Exists(): null var requested" if (not
defined($args{'var'}));
my $var = $args{'var'};
return exists($config{$var});
2007-04-18 02:49:31 +04:00
}
2006-12-05 22:58:38 +03:00
1;