【问题标题】:How can I configure all the Catalyst actions in a given controller using Config::General?如何使用 Config::General 在给定控制器中配置所有 Catalyst 操作?
【发布时间】:2011-04-30 09:15:48
【问题描述】:

我想使用我的应用程序的配置文件配置我的控制器中的所有操作。根据Catalyst::Controller,我可以在控制器本身中做到这一点:

__PACKAGE__->config(
    action => {
        '*' => { Chained => 'base', Args => 0  },
    },
 );

所以我在我的配置中尝试了这个:

<controller Foo>
    <action "*">                                                                
        Chained base
        Args 0
    </action>
</controller>

但我在启动时收到此错误:

Couldn't load class (MyApp) because: Action "*" is not available from 
controller MyApp::Controller::Foo at /usr/local/share/perl/5.10.1/Catalyst/
Controller.pm line 193

没有星号周围的引号也是如此。我该怎么做?

【问题讨论】:

    标签: perl model-view-controller configuration catalyst


    【解决方案1】:

    The Definitive Guide to Catalyst 对此进行了介绍

    从该页面获取可下载的源,解压缩,进入第 7 章中的 DwarfChains 应用程序,然后将以下内容添加到 dwarfchains.conf:

     <Controller People>
     <action get_ready>
      PathPart nama
     </action>
     </Controller>
    
     <Controller People::Info>
     <action get_info_ready>
      PathPart siapa
     </action >
     <action create>
      PathPart lagi
     </action >
     <action delete>
      PathPart mengusir
     </action >
     </Controller>
    

    这应该或多或少地展示了如何通过配置覆盖调度。

    【讨论】:

    • 我的意思是我如何使用通配符配置所有操作。在控制器配置中我可以做(来自search.cpan.org/~bobtfish/Catalyst-Runtime/lib/Catalyst/…):'*' => { Chained => 'base', Args => 0 },但是使用 Config::General 我得到上面的错误
    • 在您的情况下,我要做的是使用文档中的内联控制器配置制作一个最小的测试用例,然后使用以下命令序列化配置以查看 Config::General 期望看到的内容: perl -Ilib -e '使用我的应用程序;使用配置::常规; Config::General->new->save_file("myapp_testing.conf", MyApp->config);'
    • 听起来是个好主意,但不幸的是没有帮助。 Config::General 输出:Chained base*> 这是我所期望的。但是,将其放入我的应用程序配置中会在 Catalyst 中引发与上述相同的异常。似乎问题在于 Catalyst 对配置的解析。
    • 恭喜您发现 Stack Overflow 上报告的第二个错误!请在rt.cpan.org/Dist/Display.html?Name=Catalyst 举报
    • 抱歉,链接不正确。报告错误的正确位置是rt.cpan.org/Dist/Display.html?Name=Catalyst-Runtime
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 2012-08-23
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多