簡體   English   中英

未定義的子程序 &main::header 在 /opt/alu-rp/www/cgi/munin-cgi-html 調用

[英]Undefined subroutine &main::header called at /opt/alu-rp/www/cgi/munin-cgi-html

我面臨錯誤“在 /opt/alu-rp/www/cgi/munin-cgi-html 第 54 行調用的未定義子例程 &main::header。” 打開 munin 頁面時(http://localhost/munin)

Perl 版本:v5.32.0 穆寧版本:v2.0.65

出現錯誤后,可以看到 header 由於 munin-cgi-html 中添加的新條件而未啟動

# grab config
html_startup(\@params);
while(new CGI::Fast){
    print header("text/html");
    $config = get_config(1);
    show_page();
}
:
:
# CGI in perl 5.20 is now seriously broken as it doesn't import into the namespace.
# So we have to delegate explicitly. It's easier than prefixing with CGI:: each use.
# This workaround is applied only if "header" is undefined (i.e. for perl >= 5.20).
if(!defined &header){
        *header = sub { return CGI::header(@_); };
        *path_info = sub { return CGI::path_info(@_); };
        *url = sub { return CGI::url(@_); };
        *script_name = sub { return CGI::script_name(@_); };
}

在 munin-cgi-html 中添加一行可以解決問題。

sub header { return CGI::header(@_); }

但不確定添加這條線會有什么影響。 是否需要安裝任何特定配置或 package 才能使 Munin 工作?

底部的塊是從 CGI 導入符號。 不幸的是,您在執行此塊以導入它之前嘗試使用header 您需要在所有使用header等之前執行導入。


注意

*header = sub { return CGI::header(@_); };

最好寫成

*header = \&CGI::header

因為它避免了不必要的額外子調用。


請注意,您可以要求 CGI.pm 為您導出這些符號。 您可以簡單地使用以下任一方法,而不是手動導入符號:

use CGI qw( header path_info url script_name );
use CGI qw( :cgi );

無需自己笨拙地導入符號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM