i see. in that case, i could just have the following line in my subclass:
BEGIN { __PACKAGE__->load_config('path/to/my.conf') }
i prefer to not knowing that kind of detail in the parent class. another way that may look cleaner is
package BaseConf;
sub config_file_path { croak "must implemeted in subclass" }
sub load_config {
my $self = shift;
my $conf_file = $self->config_file_path;
croak "unable to find $conf_file" unless -e $conf_file and -r $con
+f_file;
my $cfg = Config::Tiny->read( $conf_file );
croak "read config file '$conf_file' failed: $Config::Tiny::errstr
+" unless $cfg;
return $cfg;
}
ub get {
my $self = shift;
my $cfg = $self->load_config;
croak "invalid method called $_[0]" if not exists $cfg->{_}->{ $_[
+0] };
return $cfg->{_}->{ $_[0] };
}
sub import { ... }
sub AUTOLOAD { .. }
package MyConf;
use base 'BaseConf';
sub config_file_path { return "path/to/my.conf" }
in plain CGI, Config::Tiny object is created for every config directive in sub import {}. maybe bad for performance. i am not sure if the same C::T object gets shared under mod_perl env.
|