我目前在lib文件夹中拥有一个具有以下结构的Mojolicious应用:
/my_app.conf - contains secrets, perldoc = 1 and app_mode = (0 or 1)
/lib/MyApp.pm (config is loaded here my $config = $self->plugin('Config');)
/lib/MyApp/Controller/Home.pm
/lib/MyApp/Queries/Main_Queries.pm
在/lib/MyApp/Queries/Main_Queries.pm中,我有类似
的查询our $query1 = "Select * FROM $TBL_ONE";
我如何使用以下方法从my_app.conf中将app_mode获取到
sub get_config {
my $self = shift;
my $config = $self->app->config->{app_mode}
return $config;
}
我正在尝试类似的事情:
#/lib/MyApp/Queries/Main_Queries.pm
package MyApp.. etc
use MOJO::Base
use strict;
use warnings;
use Exporter;
etc
my $config = app->config->{app_mode}; #no success
my $TBL_ONE;
# what i want to do next
if ($config == 0) {
$TBL_ONE = 'blabla';
} else {
$TBL_ONE = 'blabla_test';
}
our $query1 = "Select * FROM $TBL_ONE";