如何在没有子例程的情况下将应用程序配置文件加载到模块中

时间:2018-10-08 14:43:33

标签: perl mojolicious

我目前在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获取到 MyApp / Queries / Main_Queries.pm 而无需

 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";    

0 个答案:

没有答案