分类:
2008-08-15 22:48:27
package HWTAG::Config;
# default configurations
my %config_default = (
category => {},
);
# config file should operate on this variable
our %config;
sub load($$) {
my ($config_file, $config) = @_;
%config = %config_default;
unless (my $return = do $config_file) {
die "couldn't parse config file: $@" if $@;
die "couldn't do config file: $!" unless defined $return;
die "couldn't run config file" unless $return;
}
# copy instead of reference for multiple instances of objects having
# different configurations.
%$config = %config;
}
$config_file ||= $ENV{HWTAG_CONFIG};将里面的 HWTAG 换成其他就可以了,配置文件为 perl 代码,以修改 %config 变量来对程序进行配置,比如:
$config_file ||= catfile($ENV{HOME}, '.hwtag.pl');
HWTAG::Config::load($config_file, $self->{config});
|