Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

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

I am facing the error "Undefined subroutine &main::header called at /opt/alu-rp/www/cgi/munin-cgi-html line 54." while opening the munin page(http://localhost/munin)

Perl version: v5.32.0 Munin version: v2.0.65

With the error, able to see the header is not initiated due to the new condition added in 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(@_); };
}

Adding a line in munin-cgi-html able to solve the issue.

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

But not sure what will be the impact of adding this line. Is there anything specific configuration or package needs to install for Munin to work?

question from:https://stackoverflow.com/questions/65672131/undefined-subroutine-mainheader-called-at-opt-alu-rp-www-cgi-munin-cgi-html

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The block on the bottom is importing symbols from CGI. Unfortunately, you are trying to use header before executing this block to import it. You need to execute the imports before all uses of header and such.


Note that

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

is better written as

*header = &CGI::header

as it avoids a needless extra sub call.


Note that you can ask CGI.pm to export those symbols for you. Instead of manually importing the symbols, you can simply use either of following:

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

No need to clunckily import the symbols yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...