Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
leejo committed Mar 8, 2015
1 parent f00ce11 commit 8dd3c99
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 29 deletions.
8 changes: 8 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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
Expand All @@ -177,7 +181,7 @@ IO::Handle:
fcgi_error_file_handle => IO::Handle->new,
});

while (new CGI::Fast) {
while (CGI::Fast->new) {
..
}

Expand Down
34 changes: 19 additions & 15 deletions lib/CGI/Fast.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -258,26 +253,35 @@ 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 /
=head1 FILE HANDLES
FCGI defaults to using STDIN, STDOUT, and STDERR as its filehandles - this
Expand All @@ -292,7 +296,7 @@ IO::Handle:
fcgi_error_file_handle => IO::Handle->new,
});
while (new CGI::Fast) {
while (CGI::Fast->new) {
..
}
Expand Down
14 changes: 14 additions & 0 deletions t/008_gh_12.t
Original file line number Diff line number Diff line change
@@ -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' );
25 changes: 25 additions & 0 deletions t/009_imports.t
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 8dd3c99

Please sign in to comment.