Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why cgi_error() is not available with 'use CGI::Fast;'? #11

Closed
ache opened this issue Feb 28, 2015 · 7 comments
Closed

Why cgi_error() is not available with 'use CGI::Fast;'? #11

ache opened this issue Feb 28, 2015 · 7 comments

Comments

@ache
Copy link

ache commented Feb 28, 2015

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?

@leejo
Copy link
Owner

leejo commented Feb 28, 2015

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.

@ache
Copy link
Author

ache commented Feb 28, 2015

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.

@ache
Copy link
Author

ache commented Feb 28, 2015

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();

@leejo
Copy link
Owner

leejo commented Feb 28, 2015

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.

@ache
Copy link
Author

ache commented Feb 28, 2015

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; 

@leejo
Copy link
Owner

leejo commented Feb 28, 2015

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.

@ache
Copy link
Author

ache commented Feb 28, 2015

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.

@ache ache closed this as completed Feb 28, 2015
leejo added a commit that referenced this issue Mar 8, 2015
commit 73226ad8b5d36749f197581754be862506810325
Author: Lee Johnson <[email protected]>
Date:   Sun Mar 8 16:59:09 2015 +0100

    ref #11, #12 - perldoc and testing tweaks

    make it clear that CGI::Fast can be a drop in replacement for CGI
    but if using it with an explicit call to use CGI then the call to
    use CGI must happen after the call to use CGI::Fast to prevent any
    CGI import pragmas being overwritten

commit dcdec7d
Author: Lee Johnson <[email protected]>
Date:   Sun Mar 8 10:05:18 2015 +0100

    ref #12 - failing test case

    load order of CGI and CGI::Fast can cause import pragmas in CGI to
    be overwritten, which is probably not good behaviour. bisect shows
    this was introduced in 53651f2. the fix maybe just do document this
    behaviour given its age

    squash this commit with the fix (or remove the test if the fix is
    just documentation)
leejo added a commit to leejo/CGI.pm that referenced this issue Mar 8, 2015
CGI::Fast used to be a drop in replacement for CGI up until i broke
this behaviour by adding an explicit import sub in CGI::Fast which
means the caller stack needs to be shifted down by one to make sure
the functions are imported into the correct namespace[1]

[1] i'm not so sure this is the "right thing" to do, but from a
back compat point of view it needs to remain
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Apr 3, 2015
4.14 2015-04-01

    [ RELEASE NOTES ]
    - This release removes the AUTOLOAD and compile optimisations from CGI.pm
      that were introduced into CGI.pm twenty (20) years ago as a response to
      its large size, which meant there was a significant compile time penalty.

    - This optimisation is no longer relevant and makes the code difficult to
      deal with as well as making test coverage metrics incorrect. Benchmarks
      show that advantages of AUTOLOAD / lazy loading / deferred compile are
      less than 0.05s, which will be dwarfed by just about any meaningful code
      in a cgi script. If this is an issue for you then you should look at
      running CGI.pm in a persistent environment (FCGI, etc)

    - To offset some of the time added by removing the AUTOLOAD functionality
      the dependencies have been made runtime rather than compile time. The
      POD has also been split into its own file. CGI.pm now contains around
      4000 lines of code, which compared to some modules on CPAN isn't really
      that much

    - This essentially deprecates the -compile pragma and ->compile method. The
      -compile pragma will no longer do anything, whereas the ->compile method
      will raise a deprecation warning. More importantly this also REMOVES the
      -any pragma because as per the documentation this pragma needed to be
      "used with care or not at all" and allowing arbitrary HTML tags is almost
      certainly a bad idea. If you are using the -any pragma and using arbitrary
      tags (or have typo's in your code) your code will *BREAK*

    - Although this release should be back compatible (with the exception of any
      code using the -any pragma) you are encouraged to test it throughly as if
      you are doing anything out of the ordinary with CGI.pm (i.e. have bugs
      that may have been masked by the AUTOLOAD feature) you may see some issues.

    - References: GH #162, GH #137, GH #164

    [ FEATURES ]
    - CGI::Carp now has $CGI::Carp::FULL_PATH for displaying the full path to the
      offending script in error messages

    - CGI now has env_query_string() for getting the value of QUERY_STRING from the
      environment and not that fiddled with by CGI.pm (which is what query_string()
      does) (GH #161)

    - CGI::ENCODE_ENTITIES var added to control which chracters are encoded by the
      call to the HTML::Entities module - defaults to &<>"\x8b\x9b' (GH #157)

    [ SPEC / BUG FIXES ]
    - Add the multi_param method to :cgi export (thanks to xblitz for the patch
      and tests. GH #167)

    - Fix warning for lack of HTTP_USER_AGENT in CGI::Carp (GH #168)

    - Fix imports when called from CGI::Fast, restores the import of CGI functions
      into the callers namespace for users of CGI::Fast (GH leejo/cgi-fast#11 and
      GH leejo/cgi-fast#12)

    [ INTERNALS ]
    - Remove dependency on constant - internal DEBUG, XHTML_DTD and EBCDIC
      constants changes to $_DEBUG, $_XHTML_DTD, and $_EBCDIC

    [ DOCUMENTATION ]
    - Add missing documentation for env variable fetching routines (GH #163)
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Apr 22, 2015
4.15 2015-04-20

    [ RELEASE NOTES ]
    - This release removes the AUTOLOAD and compile optimisations from CGI.pm
      that were introduced into CGI.pm twenty (20) years ago as a response to
      its large size, which meant there was a significant compile time penalty.

    - This optimisation is no longer relevant and makes the code difficult to
      deal with as well as making test coverage metrics incorrect. Benchmarks
      show that advantages of AUTOLOAD / lazy loading / deferred compile are
      less than 0.05s, which will be dwarfed by just about any meaningful code
      in a cgi script. If this is an issue for you then you should look at
      running CGI.pm in a persistent environment (FCGI, etc)

    - To offset some of the time added by removing the AUTOLOAD functionality
      the dependencies have been made runtime rather than compile time. The
      POD has also been split into its own file. CGI.pm now contains around
      4000 lines of code, which compared to some modules on CPAN isn't really
      that much

    - This essentially deprecates the -compile pragma and ->compile method. The
      -compile pragma will no longer do anything, whereas the ->compile method
      will raise a deprecation warning. More importantly this also REMOVES the
      -any pragma because as per the documentation this pragma needed to be
      "used with care or not at all" and allowing arbitrary HTML tags is almost
      certainly a bad idea. If you are using the -any pragma and using arbitrary
      tags (or have typo's in your code) your code will *BREAK*

    - Although this release should be back compatible (with the exception of any
      code using the -any pragma) you are encouraged to test it throughly as if
      you are doing anything out of the ordinary with CGI.pm (i.e. have bugs
      that may have been masked by the AUTOLOAD feature) you may see some issues.

    - References: GH #162, GH #137, GH #164

    [ SPEC / BUG FIXES ]
    - make the list context warning in param show the filename rather than
      the package so we have more information on exactly where the warning
      has been raised from (GH #171)
    - correct self_url when PATH_INFO and SCRIPT_NAME are the same but we
      are not running under IIS (GH #176)
    - Add the multi_param method to :cgi export (thanks to xblitz for the patch
      and tests. GH #167)
    - Fix warning for lack of HTTP_USER_AGENT in CGI::Carp (GH #168)
    - Fix imports when called from CGI::Fast, restores the import of CGI functions
      into the callers namespace for users of CGI::Fast (GH leejo/cgi-fast#11 and
      GH leejo/cgi-fast#12)

    [ FEATURES ]
    - CGI::Carp now has $CGI::Carp::FULL_PATH for displaying the full path to the
      offending script in error messages
    - CGI now has env_query_string() for getting the value of QUERY_STRING from the
      environment and not that fiddled with by CGI.pm (which is what query_string()
      does) (GH #161)
    - CGI::ENCODE_ENTITIES var added to control which chracters are encoded by the
      call to the HTML::Entities module - defaults to &<>"\x8b\x9b' (GH #157)

    [ DOCUMENTATION ]
    - Fix some typos (GH #173, GH #174)
    - All *documentation* for HTML functionality in CGI has been moved into
      its own namespace: CGI::HTML::Functions - although the functionality
      continues to exist within CGI.pm so there are no code changes required
      (GH #142)
    - Add missing documentation for env variable fetching routines (GH #163)

    [ TESTING ]
    - Increase test coverage (GH #3)

    [ INTERNALS ]
    - Cwd made a TEST_REQUIRES rather than a BUILD_REQUIRES in Makefile.PL
      (GH #170)
    - AutoloadClass variables have been removed as AUTOLOAD was removed in
      v4.14 so these are no longer necessary (GH #172 thanks to alexmv)
    - Remove dependency on constant - internal DEBUG, XHTML_DTD and EBCDIC
      constants changes to $_DEBUG, $_XHTML_DTD, and $_EBCDIC
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue May 31, 2015
4.20 2015-05-29

    [ RELEASE NOTES ]
    - CGI.pm is now considered "done". See also "mature" and "legacy"
      Features requests and none critical issues will be outright rejected.
      The module is now in maintenance mode for critical issues only.

    - This release removes the AUTOLOAD and compile optimisations from CGI.pm
      that were introduced into CGI.pm twenty (20) years ago as a response to
      its large size, which meant there was a significant compile time penalty.

    - This optimisation is no longer relevant and makes the code difficult to
      deal with as well as making test coverage metrics incorrect. Benchmarks
      show that advantages of AUTOLOAD / lazy loading / deferred compile are
      less than 0.05s, which will be dwarfed by just about any meaningful code
      in a cgi script. If this is an issue for you then you should look at
      running CGI.pm in a persistent environment (FCGI, etc)

    - To offset some of the time added by removing the AUTOLOAD functionality
      the dependencies have been made runtime rather than compile time. The
      POD has also been split into its own file. CGI.pm now contains around
      4000 lines of code, which compared to some modules on CPAN isn't really
      that much

    - This essentially deprecates the -compile pragma and ->compile method. The
      -compile pragma will no longer do anything, whereas the ->compile method
      will raise a deprecation warning. More importantly this also REMOVES the
      -any pragma because as per the documentation this pragma needed to be
      "used with care or not at all" and allowing arbitrary HTML tags is almost
      certainly a bad idea. If you are using the -any pragma and using arbitrary
      tags (or have typo's in your code) your code will *BREAK*

    - Although this release should be back compatible (with the exception of any
      code using the -any pragma) you are encouraged to test it throughly as if
      you are doing anything out of the ordinary with CGI.pm (i.e. have bugs
      that may have been masked by the AUTOLOAD feature) you may see some issues.

    - References: GH #162, GH #137, GH #164

    [ SPEC / BUG FIXES ]
    - make the list context warning in param show the filename rather than
      the package so we have more information on exactly where the warning
      has been raised from (GH #171)
    - correct self_url when PATH_INFO and SCRIPT_NAME are the same but we
      are not running under IIS (GH #176)
    - Add the multi_param method to :cgi export (thanks to xblitz for the patch
      and tests. GH #167)
    - Fix warning for lack of HTTP_USER_AGENT in CGI::Carp (GH #168)
    - Fix imports when called from CGI::Fast, restores the import of CGI functions
      into the callers namespace for users of CGI::Fast (GH leejo/cgi-fast#11 and
      GH leejo/cgi-fast#12)

    [ FEATURES ]
    - CGI::Carp now has $CGI::Carp::FULL_PATH for displaying the full path to the
      offending script in error messages
    - CGI now has env_query_string() for getting the value of QUERY_STRING from
      the environment and not that fiddled with by CGI.pm (which is what
      query_string() does) (GH #161)
    - CGI::ENCODE_ENTITIES var added to control which chracters are encoded by
      the call to the HTML::Entities module - defaults to &<>"' (GH #157 - the
      \x8b and \x9b chars have been removed from this list as we are concerned
      more about unicode compat these days than old browser support.)

    [ DOCUMENTATION ]
    - Fix some typos (GH #173, GH #174)
    - All *documentation* for HTML functionality in CGI has been moved into
      its own namespace: CGI::HTML::Functions - although the functionality
      continues to exist within CGI.pm so there are no code changes required
      (GH #142)
    - Add missing documentation for env variable fetching routines (GH #163)

    [ TESTING ]
    - Increase test coverage (GH #3)

    [ INTERNALS ]
    - Cwd made a TEST_REQUIRES rather than a BUILD_REQUIRES in Makefile.PL
      (GH #170)
    - AutoloadClass variables have been removed as AUTOLOAD was removed in
      v4.14 so these are no longer necessary (GH #172 thanks to alexmv)
    - Remove dependency on constant - internal DEBUG, XHTML_DTD and EBCDIC
      constants changes to $_DEBUG, $_XHTML_DTD, and $_EBCDIC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants