【问题标题】:How to detect if web script in Perl is run using ModPerl::Registry (mod_perl handler)?如何检测 Perl 中的 Web 脚本是否使用 ModPerl::Registry(mod_perl 处理程序)运行?
【发布时间】:2010-07-10 22:27:31
【问题描述】:

如果使用ModPerl::Registry运行,是否可以检测在mod_perl下运行的Web应用程序?

我想编写可以在 ModPerl::Registry(或类似处理程序)下运行的脚本,但也可以用作 mod_perl 响应处理程序。

【问题讨论】:

    标签: perl web-applications mod-perl


    【解决方案1】:

    ModPerl::Registry 进行了精心设计,以将您的代码与系统中的其他所有内容隔离开来,其中一部分是将其编译到 ModPerl::ROOT 下的一个包中。

    当在列表上下文中使用指定要返回的帧数的参数调用时,caller 返回

    #  0         1          2      3            4
    ($package, $filename, $line, $subroutine, $hasargs,
    #  5          6          7            8       9         10
    $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
     = caller($i); 
    

    $subroutine 值是完全限定名称。

    ModPerl::Registry 将您的整个程序包装在上述人工包中名为 handler 的子程序中,因此在您的主程序中,使用类似于

    的测试
    my $name = (caller 0)[3];
    if ($name =~ /^ModPerl::ROOT::/) {
      # run using ModPerl::Registry
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-30
      • 2012-01-07
      • 2012-03-28
      • 2021-06-01
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 2011-02-05
      • 2020-01-16
      相关资源
      最近更新 更多