Subject: | return code of the generated sub is inconsistent |
If the generated function returns without exception, that means the original CGI program simply ends after the last line of code without calling exit explicitly, the return value of the script is returned from the wrapping sub. For normal scripts that would be the exit code.
However, if the script calls C<exit> explicitly, the wrapping sub dies if the exit code passed this way is other than 0.
The generated code should read
return $rv unless $@;
die $@ if $@ and not (
ref($@) eq 'ARRAY' and
$@->[0] eq "EXIT\n"
);
return $@->[1];
instead of
return $rv unless $@;
die $@ if $@ and not (
ref($@) eq 'ARRAY' and
$@->[0] eq "EXIT\n"
);
die "exited nonzero: $@->[1]" if $@->[1] != 0;
return $rv;