我正在为 Apache 中的各种登录相关功能编写一系列相关的 mod_perl 处理程序,因此我的 Apache 配置文件如下所示(例如)
PerlAccessHandler MyApache::MyAccess
PerlAuthenHandler MyApache::MyAuthen
PerlAuthzHandler MyApache::MyAuthz
每个模块 (MyAccess
, MyAuthen< /code>, MyAuthz
) 定义了
sub handler() {}
在请求处理过程中的相关点调用的 mod_perl
。
我想知道是否有一种方法可以使用一个 Perl 模块而不是三个来完成此操作(用户安装一个模块而不是三个模块会更整洁、工作量更少)?
也许有某种方法可以定义处理程序方法的名称。 或者是否有一种方法可以从 handler()
代码中检测我应该执行哪种处理?
I'm writing a series of related mod_perl handlers for various login-related functions in Apache, so my Apache config file looks like this (for example)
PerlAccessHandler MyApache::MyAccess
PerlAuthenHandler MyApache::MyAuthen
PerlAuthzHandler MyApache::MyAuthz
Each of the modules (MyAccess
, MyAuthen
, MyAuthz
) defines a
sub handler() {}
Which mod_perl
calls at the relevant point in the processing of the request.
What I'd like to know is whether there is a way of doing this with one Perl module rather than three (it's just tidier and less work for users to install one module instead of 3)?
Is there some way to define the name of the handler method, perhaps. Or is there a way of detecting from within the handler()
code which sort of handling I'm supposed to be doing?
发布评论
评论(2)
从mod_perl 2.0 docs中可以看到,您可以使用“方法”语法来执行您想要的操作(我没有对此进行测试):
我相信这将导致 mod_perl 在您的
MyApache::MyLoginModule
类。如果您愿意,您还可以创建一个在调用
handler
方法时使用的对象:此方法将允许您拥有一个可以基于不同行为的
handler
方法。对象创建时设置的对象属性。免责声明:自从我使用 mod_perl 配置的这一部分以来已经有一段时间了,因此您的结果可能会有所不同!
It appears from the mod_perl 2.0 docs that you can use the "method" syntax to do what you're wanting (I've not tested this):
I believe this will cause mod_perl to call each of the named methods in a static way on your
MyApache::MyLoginModule
class.You can also create an object to be used when calling a
handler
method if you want to:This approach would allow you to have a single
handler
method that could have different behavior based on the properties of the object set up upon object creation.Disclaimer: It's been a while since I've worked with this part of mod_perl configuration so your results may vary!
看起来一种可能性可能是使用
push_handlers()
调用并在代码中而不是在 apache conf 文件中设置处理程序请参阅此处:http://tinyurl.com/bwdeew
Looks like one possibility might be using the
push_handlers()
call and setting up the handlers in code rather than in the apache conf fileSee here: http://tinyurl.com/bwdeew