From 8dd3c9942c27c9eacadc6d9407a929747b5f5fd2 Mon Sep 17 00:00:00 2001 From: Lee Johnson Date: Sun, 8 Mar 2015 17:03:32 +0100 Subject: [PATCH] Squashed commit of the following: commit 73226ad8b5d36749f197581754be862506810325 Author: Lee Johnson 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 dcdec7d27a5ab8fead1d201b04bfb83126cf86a9 Author: Lee Johnson 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) --- Changes | 8 ++++++++ README.md | 32 ++++++++++++++++++-------------- lib/CGI/Fast.pm | 34 +++++++++++++++++++--------------- t/008_gh_12.t | 14 ++++++++++++++ t/009_imports.t | 25 +++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 t/008_gh_12.t create mode 100644 t/009_imports.t diff --git a/Changes b/Changes index e9e3753..d169cb2 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ Revision history for CGI::Fast +2.08 2015-03-08 + [DOCUMENTATION] + - Clarify order of use statements when using both CGI and CGI::Fast + - Replace indirect object notation with ->new + + [TESTING] + - Tests for CGI imports and load order + 2.07 2015-02-23 [FIX] - test added in 2.06 should use File::Temp diff --git a/README.md b/README.md index 7f5bc0f..958e39e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ CGI::Fast - CGI Interface for Fast CGI socket_perm => 0777, listen_queue => 50; + use CGI qw/ :standard /; + $COUNTER = 0; # optional, will default to STDOUT, STDIN, STDERR @@ -24,15 +26,8 @@ CGI::Fast - CGI Interface for Fast CGI fcgi_error_file_handle => IO::Handle->new, }); - while (new CGI::Fast) { - print header; - print start_html("Fast CGI Rocks"); - print - h1("Fast CGI Rocks"), - "Invocation number ",b($COUNTER++), - " PID ",b($$),".", - hr; - print end_html; + while ($q = CGI::Fast->new) { + process_request($q); } # DESCRIPTION @@ -63,7 +58,7 @@ A typical FastCGI script will look like this: #!perl use CGI::Fast; do_some_initialization(); - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } @@ -79,7 +74,7 @@ scripts). CGI.pm's default CGI object mode also works. Just modify the loop this way: - while (new CGI::Fast) { + while (CGI::Fast->new) { process_request(); } @@ -144,25 +139,34 @@ For example: listen_queue => "50" ; + use CGI qw/ :standard /; + do_some_initialization(); - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } Or: use CGI::Fast; + use CGI qw/ :standard /; do_some_initialization(); $ENV{FCGI_SOCKET_PATH} = "sputnik:8888"; $ENV{FCGI_LISTEN_QUEUE} = 50; - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } +Note the importance of having use CGI after use CGI::Fast as this will +prevent any CGI import pragmas being overwritten by CGI::Fast. You can +use CGI::Fast as a drop in replacement like so: + + use CGI::Fast qw/ :standard / + # FILE HANDLES FCGI defaults to using STDIN, STDOUT, and STDERR as its filehandles - this @@ -177,7 +181,7 @@ IO::Handle: fcgi_error_file_handle => IO::Handle->new, }); - while (new CGI::Fast) { + while (CGI::Fast->new) { .. } diff --git a/lib/CGI/Fast.pm b/lib/CGI/Fast.pm index f4bac33..dc3fa40 100644 --- a/lib/CGI/Fast.pm +++ b/lib/CGI/Fast.pm @@ -13,7 +13,7 @@ local $^W = 1; # wish, but if you redistribute a modified version, please attach a note # listing the modifications you have made. -$CGI::Fast::VERSION='2.07'; +$CGI::Fast::VERSION='2.08'; use CGI; use FCGI; @@ -125,6 +125,8 @@ CGI::Fast - CGI Interface for Fast CGI socket_perm => 0777, listen_queue => 50; + use CGI qw/ :standard /; + $COUNTER = 0; # optional, will default to STDOUT, STDIN, STDERR @@ -134,15 +136,8 @@ CGI::Fast - CGI Interface for Fast CGI fcgi_error_file_handle => IO::Handle->new, }); - while (new CGI::Fast) { - print header; - print start_html("Fast CGI Rocks"); - print - h1("Fast CGI Rocks"), - "Invocation number ",b($COUNTER++), - " PID ",b($$),".", - hr; - print end_html; + while ($q = CGI::Fast->new) { + process_request($q); } =head1 DESCRIPTION @@ -173,7 +168,7 @@ A typical FastCGI script will look like this: #!perl use CGI::Fast; do_some_initialization(); - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } @@ -189,7 +184,7 @@ scripts). CGI.pm's default CGI object mode also works. Just modify the loop this way: - while (new CGI::Fast) { + while (CGI::Fast->new) { process_request(); } @@ -258,9 +253,11 @@ For example: listen_queue => "50" ; + use CGI qw/ :standard /; + do_some_initialization(); - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } @@ -268,16 +265,23 @@ For example: Or: use CGI::Fast; + use CGI qw/ :standard /; do_some_initialization(); $ENV{FCGI_SOCKET_PATH} = "sputnik:8888"; $ENV{FCGI_LISTEN_QUEUE} = 50; - while ($q = new CGI::Fast) { + while ($q = CGI::Fast->new) { process_request($q); } +Note the importance of having use CGI after use CGI::Fast as this will +prevent any CGI import pragmas being overwritten by CGI::Fast. You can +use CGI::Fast as a drop in replacement like so: + + use CGI::Fast qw/ :standard / + =head1 FILE HANDLES FCGI defaults to using STDIN, STDOUT, and STDERR as its filehandles - this @@ -292,7 +296,7 @@ IO::Handle: fcgi_error_file_handle => IO::Handle->new, }); - while (new CGI::Fast) { + while (CGI::Fast->new) { .. } diff --git a/t/008_gh_12.t b/t/008_gh_12.t new file mode 100644 index 0000000..cf42f2f --- /dev/null +++ b/t/008_gh_12.t @@ -0,0 +1,14 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# the order is important! (see GH #12) +use CGI::Fast; +use CGI qw/ :standard -no_xhtml -nosticky /; +use Test::More qw/ no_plan /; + +my $q = CGI::Fast->new; + +my $start_html = start_html(); +unlike( $start_html,qr/XHTML/,'CGI pragma not overriden by CGI::Fast' ); diff --git a/t/009_imports.t b/t/009_imports.t new file mode 100644 index 0000000..893a8bd --- /dev/null +++ b/t/009_imports.t @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; +use CGI::Fast qw/ :standard /; + +my $cgi_version = $CGI::VERSION; + +if ( ! $cgi_version ) { + plan skip_all => "Couldn't figure out CGI version"; +} else { + $cgi_version =~ s/\D.*$//; +} + +if ( $cgi_version < 4.14 ) { + plan skip_all => "CGI v4.14+ required for this test"; +} + +eval { cgi_error() }; +ok( ! $@,'imports' ); +$@ && diag( $@ ); + +done_testing();