BEGIN { __PACKAGE__->load_config('path/to/my.conf') } #### 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 $conf_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" }