如何在 Catalyst 中请求结束时进行清理?
我试图使用 Catalyst 在每个请求完成后调用一些代码。 基本上,我想运行一些代码作为 finalize
的一部分。 据说 Catalyst::Plugin::Observe 会执行此操作,但它似乎完全损坏(仅加载插件就会损坏 Catalyst)。
我正在尝试修复 Observe 插件,但事实证明这很顽固。
那么,是否有更好的方法来在每个请求结束时调用一些清理代码?
(注意:这是在模型中,而不是在控制器中,所以我不能只使用 sub end { ... }
)
I'm trying to get some code called after each request completes using Catalyst. Basically, I want to run some code as part of finalize
. Supposedly Catalyst::Plugin::Observe will do this, but it appears completely broken (just loading the plugin breaks Catalyst).
I'm trying to fix the Observe plugin, but that's proving stubborn.
So, is there a better way to do get some cleanup code called at the end of each request?
(Note: This is in a model, not a controller, so I can't just use sub end { ... }
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您可以直接将代码添加到“MyApp”类中:
这就是所有插件的工作方式; 它们只是成为您应用程序一部分的方法。
我确实同意让“finalize”生成一个事件来观察更干净......但这就是我们现在必须处理的:) 加入 irc.perl.org 上的 #catalyst,我们可以进一步讨论。 (你可能猜到了,我是jrockway。)
编辑回复:
您确实知道
end
中有$c
代码>,对吗?或者您可以从
MyApp::finalize
执行此操作,正如我上面建议的那样。真正的问题是,为什么您的模型需要了解请求周期? 这听起来耦合非常紧密。
You can actually just add the code directly to your "MyApp" class:
This is how all plugins work; they are just methods that become part of your app.
I do agree that making "finalize" generate an event to observe is cleaner... but this is what we have to work with for now :) Join #catalyst on irc.perl.org, and we can discuss further. (I am jrockway, as you may guess.)
Edited to reply to:
You do know that you have
$c
inend
, right?Or you can do it from
MyApp::finalize
, as I suggested above.The real question is, why does your model need to know about the request cycle? That sounds like awfully tight coupling.