Closed ache closed 9 years ago
Can you give me more information on the versions of CGI and CGI::Fast were this was/is working? Trying with older version shows this not working, and it may well be down to "Use of inherited AUTOLOAD for non-method" (which has been deprecated for a long time):
/Volumes/code_partition/CGI.pm > perl -V | head -n1
Summary of my perl5 (revision 5 version 18 subversion 1) configuration:
/Volumes/code_partition/CGI.pm > perl -Ilib -MCGI::Fast -E'say $CGI::VERSION; say $CGI::Fast::VERSION; say CGI::Fast::cgi_error("foo")';
defined(@array) is deprecated at lib/CGI.pm line 528.
(Maybe you should just omit the defined()?)
3.51
1.08
Use of inherited AUTOLOAD for non-method CGI::Fast::cgi_error() is deprecated at -e line 1.
Undefined subroutine CGI::Fast::cgi_error
at -e line 1.
/Volumes/code_partition/CGI.pm > perl -Ilib -MCGI::Fast -E'say $CGI::VERSION; say $CGI::Fast::VERSION; say cgi_error("foo")';
defined(@array) is deprecated at lib/CGI.pm line 528.
(Maybe you should just omit the defined()?)
3.51
1.08
Undefined subroutine &main::cgi_error called at -e line 1.
It works with old CGI.pm 3.63 which installs its own CGI/Fast.pm along with other submodules f.e. CGI/Carp.pm etc. Now I upgrade to CGI.pm 4.13 + separate CGI::Fast 2.07 and feel a bit disoriented, which way is proper now to bring cgi_error() to life.
BTW, I don't call it like this CGI::Fast::cgi_error("foo") (it have no arguments). I use sample from CGI.pm manpage:
my $error = cgi_error();
Can you show me the all the code you are using? I cannot get this behaviour with CGI v3.63:
/Volumes/code_partition/CGI.pm > perl -Ilib -MCGI::Fast -E'say $CGI::VERSION; say $CGI::Fast::VERSION; say cgi_error()';
3.63
1.09
Undefined subroutine &main::cgi_error called at -e line 1.
Initially it was big script, so I try to cut it down but maybe not to absolute minimum. I just restore old CGI.pm 3.63 and check it works without 'Undefined subroutine &main::cgi_error'
#!/usr/local/bin/perl -w
use strict;
use POSIX qw(_exit);
use CGI::Fast qw/ :standard -no_xhtml -nosticky /;
$CGI::POST_MAX = 0;
$CGI::DISABLE_UPLOADS = 1;
my $exit_requested = 0;
my $exitcode = 0;
my $handling_request = 0;
sub sig_handler {
_exit(0) if !$handling_request;
_exit(1) if $exit_requested;
$exit_requested = 1;
}
$SIG{TERM} = \&sig_handler;
$SIG{PIPE} = 'IGNORE';
sub pipe_handler {die "SIGPIPE\n";}
sub abort_request() {
if (!$exit_requested) {
$exit_requested = 1;
}
$exitcode = 1;
warn("[$$] fatal error, request aborted, shutting down: $@\n");
}
sub outit($) {
my $err = shift;
print header(-status=>200, -type=>"text/plain"),
$err, "\n";
}
sub do_request() {
local $SIG{PIPE} = \&pipe_handler;
my $error = cgi_error();
if ($error) {
outit("CGI error $error");
return;
}
outit("Ok");
}
while ($handling_request = !!(new CGI::Fast)) {
abort_request() if (!eval {do_request(); 1;} && $@ ne "SIGPIPE\n");
$handling_request = 0;
last if $exit_requested;
}
exit $exitcode;
OK, this is the offending line:
use CGI::Fast qw/ :standard -no_xhtml -nosticky /;
You need to import those using CGI not CGI::Fast, so change it to the following:
use CGI qw/ :standard -no_xhtml -nosticky /;
use CGI::Fast
And that works:
/Volumes/code_partition/CGI.pm > perl -Ilib -I../cgi-fast/lib -E'use CGI::Fast; use CGI qw/ :standard -no_xhtml -nosticky /; say $CGI::VERSION; say $CGI::Fast::VERSION; say cgi_error("foo")';
4.13_02
2.04
foo
The fact that you could get at CGI's imports via CGI::Fast is an accident and probably not by design, and even though the old CGI::Fast SYNOPSIS has use CGI::Fast qw/ :standard /
i'd also suggest this was an accident.
Thanx for explanation. v3.63 CGI::Fast SYNOPSIS have 'use CGI::Fast qw(:standard);' making false impression that CGI::Fast is just drop-in replacement of CGI.
Hi. Perl 5.18 can't find cgi_error() when just 'use CGI::Fast;' line used alone. This function is from main CGI.pm module which CGI:Fast uses so I don't understand why it is unavailable. It works for ages with the single line above with old versions of CGI::Fast and CGI.pm installed. Is new way suppose to include both 'use CGI;' and 'use CGI::Fast;' in the same time?