Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 30774
Status: rejected
Priority: 0/
Queue: CGI

People
Owner: MARKSTOS [...] cpan.org
Requestors: ldm [...] apartia.fr
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: CGI.pm with modperl resets $XHTML to 1 after first request
Date: Fri, 16 Nov 2007 10:57:53 +0100
To: bug-CGI.pm [...] rt.cpan.org
From: Louis-David Mitterrand <ldm [...] apartia.fr>
Hi, In my modperl startup file I have: use CGI qw(... -no_xhtml ...); and use: start_html( -dtd=>[ '-//W3C//DTD HTML 4.01//EN', 'http://www.w3.org/TR/html4/strict.dtd' ], ... etc. ) After restarting apache2, CGI.pm's start_html() function emits: <html lang="fr-FR"><head><title>My title</title> But after a 3/4 reloads it starts emitting: <html xmlns="http://www.w3.org/1999/xhtml" lang="fr-FR" xml:lang="fr-FR"> So I have to add: $CGI::XHTML = 0; in my startup file to keep xthml off. Somehow $XHTML goes back to 1 after the first request in the apache child.
On Fri Nov 16 04:58:50 2007, ldm@apartia.fr wrote: Show quoted text
> Hi, > > In my modperl startup file I have: > > use CGI qw(... -no_xhtml ...); > > and use: > > start_html( > -dtd=>[ '-//W3C//DTD HTML 4.01//EN', > 'http://www.w3.org/TR/html4/strict.dtd' ], > ... etc. > ) > > > After restarting apache2, CGI.pm's start_html() function emits: > > <html lang="fr-FR"><head><title>My title</title> > > But after a 3/4 reloads it starts emitting: > > <html xmlns="http://www.w3.org/1999/xhtml" lang="fr-FR" xml:lang="fr- > FR"> > > So I have to add: > > $CGI::XHTML = 0; > > in my startup file to keep xthml off. > > Somehow $XHTML goes back to 1 after the first request in the apache > child.
Thanks for the report. Do you find that this bug still exists with CGI.pm 3.43? Mark
Subject: Re: [rt.cpan.org #30774] Needs Confirmation: CGI.pm with modperl resets $XHTML to 1 after first request
Date: Sat, 25 Jul 2009 10:13:41 +0200
To: MARKSTOS via RT <bug-CGI.pm [...] rt.cpan.org>
From: Louis-David Mitterrand <ldm [...] apartia.fr>
On Fri, Jul 24, 2009 at 09:36:15PM -0400, MARKSTOS via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=30774 > > > On Fri Nov 16 04:58:50 2007, ldm@apartia.fr wrote:
> > Hi, > > > > In my modperl startup file I have: > > > > use CGI qw(... -no_xhtml ...); > > > > and use: > > > > start_html( > > -dtd=>[ '-//W3C//DTD HTML 4.01//EN', > > 'http://www.w3.org/TR/html4/strict.dtd' ], > > ... etc. > > ) > > > > > > After restarting apache2, CGI.pm's start_html() function emits: > > > > <html lang="fr-FR"><head><title>My title</title> > > > > But after a 3/4 reloads it starts emitting: > > > > <html xmlns="http://www.w3.org/1999/xhtml" lang="fr-FR" xml:lang="fr- > > FR"> > > > > So I have to add: > > > > $CGI::XHTML = 0; > > > > in my startup file to keep xthml off. > > > > Somehow $XHTML goes back to 1 after the first request in the apache > > child.
> > Thanks for the report. Do you find that this bug still exists with > CGI.pm 3.43?
Hi, I don't know since I use debian's version which is still at 3.29.
This happens because under mod_perl, CGI.pm registers a cleanup handler that calls _reset_globals() (which then calls initialize_globals()). So globals ($XHTML, $PARAM_UTF8 etc) that may have been changed will be wiped out at the end of the request. The only way I see around this is to reset the globals at the start of each request to what you want (e.g.: set $XHTML = 0).
On Thu Aug 27 16:07:57 2009, MSCHOUT wrote: Show quoted text
> This happens because under mod_perl, CGI.pm registers a cleanup handler > that calls _reset_globals() (which then calls initialize_globals()). > > So globals ($XHTML, $PARAM_UTF8 etc) that may have been changed will be > wiped out at the end of the request. > > The only way I see around this is to reset the globals at the start of > each request to what you want (e.g.: set $XHTML = 0).
Ok, this explanation sounds plausible. So maybe it would work to redefine _reset_globals() like this:? sub _reset_globals { initialize_globals(); CGI->_setup_symbols(@SAVED_SYMBOLS); } That's not been tested, but seems like it might do the right think to make changes to global variables persis in mod_perl. Mark
On Thu Aug 27 22:10:06 2009, MARKSTOS wrote: Show quoted text
> On Thu Aug 27 16:07:57 2009, MSCHOUT wrote:
> > This happens because under mod_perl, CGI.pm registers a cleanup handler > > that calls _reset_globals() (which then calls initialize_globals()). > > > > So globals ($XHTML, $PARAM_UTF8 etc) that may have been changed will be > > wiped out at the end of the request. > > > > The only way I see around this is to reset the globals at the start of > > each request to what you want (e.g.: set $XHTML = 0).
In CGI::new, we can see the related code. You mentioned using Apache2, so I assume you are using mod_perl2. In that code path, these two lines should be triggered: $r->pool->cleanup_register(\&CGI::_reset_globals); $self->_setup_symbols(@SAVED_SYMBOLS) if @SAVED_SYMBOLS; Calling _setup_symbols() like this is usually want preserves the pragmas in a persistent environment. Do you see a bug here? It's not clear to me what to change.
On Thu Sep 03 22:41:03 2009, MARKSTOS wrote: Show quoted text
> Calling _setup_symbols() like this is usually want preserves the
pragmas Show quoted text
> in a persistent environment. Do you see a bug here? It's not clear to
me Show quoted text
> what to change.
I've hit this and I'm pretty sure I know what the problem is. Try this: use Data::Dumper; CGI->compile(':unique_headers'); CGI->compile(':cgi'); print Dumper(\@CGI::SAVED_SYMBOLS); _setup_symbols needs to do push(@SAVED_SYMBOLS, @_) instead of doing =.
Subject: Re: [rt.cpan.org #30774] Needs Bug Hunting: mod_perl resets $XHTML to 1 after first request
Date: Wed, 02 Mar 2011 09:19:38 -0500
To: bug-CGI.pm [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> _setup_symbols needs to do push(@SAVED_SYMBOLS, @_) instead of doing =.
Thanks, Max! That sounds right. We'll look into it further. Mark
RT-Send-CC: lincoln.stein [...] gmail.com
I've looked into this some more, and my current opinion is this not clearly flexible. The pragma/symbol/global system dates to back to when CGI scripts were king, "applications" fit into a single file and name space, CGI.pm was loaded once, and mod_perl was not in use. Consider a modern web application which uses multiple packages. More than one might "use CGI", the below script: use v5.10; package First; use CGI '-xhtml'; sub first_foo { my $q = CGI->new; return $q->input(); } package Second; use CGI '-no_xhtml'; sub second_foo { my $q = CGI->new; return $q->input(); } package main; import First; say First::first_foo(); import Second; say Second::second_foo(); ### One package intends to set the "-no_xhtml" pragma, while another sets the opposite. The result is that silently one pragma "wins" in both cases. Setting these values by global variables also has problems, a truly global variable could affect another package at a distance that didn't what the setting. And with global variables the intent is not always clear or possible to express precisely. Did you intend to affect everything everywhere, just the current package, or just the current object? Because of this inherent lack of clarity, it's hard to change with confidence which controls how these are variables are managed. In the cases reported here, are we certain for instance that there is only one "use CGI" throughout the entire code-base... and only one "CGI->compile" ? Can we be certain that we are updating the behavior that correctly represents what people expect about per-object values being reset and how they related to global settings? Here are my thoughts on addressing this: - Using a framework like CGI::Application helps. It highly encourages the application and plugins to access CGI through $self->query(). So CGI.pm is "used" exactly once and any global changes can be declared with "local" just before calling CGI->new in cgiapp_get_query(). - The documentation can be updated to be clearer about the best practices for declaring global-scope and object-scope preferences, as well as how to do deal with gotchas. - CGI.pm could could consider adding object-scope pragmas something like this: $q->pragmas('-no_xhtml -no_sticky'); That may be a horrible name and interface, but the intent is there: a way to explicitly support settings that are per-object. Such a notion would be easy to manage the code for, and would provide explicit clarity fo users. If you still think there's some other global change to be made, I'd like to see a reduced case example that triggers so that we understand exactly which case is being proposed to be changed.
This issue has been copied to: https://github.com/leejo/CGI.pm/issues/51 please take all future correspondence there. This ticket will remain open but please do not reply here. This ticket will be closed when the github issue is dealt with.
Rejecting as "won't fix" (mod_perl)