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: 38061
Status: resolved
Priority: 0/
Queue: CGI

People
Owner: Nobody in particular
Requestors: kbaucom [...] schizoid.com
Cc:
AdminCc:

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



Subject: -nosticky does not work as documented
The documentation for the -nosticky pragma says that it prevents the state preserving behavior of fields. In fact, it does two things: 1) Makes the default name for submit buttons an empty string if no label is supplied 2) suppresses the .cgifields hidden field The documented behavior of -nosticky can be achieved by setting override or force to 1 when calling any method that supports it. To avoid breaking the current -nosticky functionality (assuming that is a concern), this patch adds a new global variable called $OVERRIDE that acts as a default value for override. The patch is on version 3.39. It includes documentation for the override pragma, but does not update the docs otherwise. I have also attached a small test script to demonstrate the new pragma.
Subject: cgi_override.patch
--- CGI.pm 2008-07-31 00:10:35.000000000 -0400 +++ CGI_override.pm 2008-07-31 00:07:24.000000000 -0400 @@ -65,6 +65,11 @@ # 2) $CGI::nosticky(1) $NOSTICKY = 0; + # global default for override + # 1) use CGI qw(-override) + # 2) CGI::override(1) + $OVERRIDE = 0; + # Set this to 1 to enable NPH scripts # or: # 1) use CGI qw(-nph) @@ -903,6 +908,7 @@ $HEADERS_ONCE++, next if /^[:-]unique_headers$/; $NPH++, next if /^[:-]nph$/; $NOSTICKY++, next if /^[:-]nosticky$/; + $OVERRIDE++, next if /^[:-]override$/; $DEBUG=0, next if /^[:-]no_?[Dd]ebug$/; $DEBUG=2, next if /^[:-][Dd]ebug$/; $USE_PARAM_SEMICOLONS++, next if /^[:-]newstyle_urls$/; @@ -1916,6 +1922,8 @@ my($name,$default,$size,$maxlength,$override,$tabindex,@other) = rearrange([NAME,[DEFAULT,VALUE,VALUES],SIZE,MAXLENGTH,[OVERRIDE,FORCE],TABINDEX],@p); + $override = defined($override) ? $override : $OVERRIDE; + my $current = $override ? $default : (defined($self->param($name)) ? $self->param($name) : $default); @@ -2001,6 +2009,8 @@ my($name,$default,$rows,$cols,$override,$tabindex,@other) = rearrange([NAME,[DEFAULT,VALUE],ROWS,[COLS,COLUMNS],[OVERRIDE,FORCE],TABINDEX],@p); + $override = defined($override) ? $override : $OVERRIDE; + my($current)= $override ? $default : (defined($self->param($name)) ? $self->param($name) : $default); @@ -2165,6 +2175,8 @@ rearrange([NAME,[CHECKED,SELECTED,ON],VALUE,LABEL,LABELATTRIBUTES, [OVERRIDE,FORCE],TABINDEX],@p); + $override = defined($override) ? $override : $OVERRIDE; + $value = defined $value ? $value : 'on'; if (!$override && ($self->{'.fieldnames'}->{$name} || @@ -2354,6 +2366,8 @@ ],@_); + $override = defined($override) ? $override : $OVERRIDE; + my($result,$checked,@elements,@values); @values = $self->_set_values_and_labels($values,\$labels,$name); @@ -2449,6 +2463,8 @@ ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p); my($result,%selected); + $override = defined($override) ? $override : $OVERRIDE; + if (!$override && defined($self->param($name))) { $selected{$self->param($name)}++; } elsif ($default) { @@ -2577,6 +2593,8 @@ = rearrange([NAME,[VALUES,VALUE],[DEFAULTS,DEFAULT], SIZE,MULTIPLE,LABELS,ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p); + $override = defined($override) ? $override : $OVERRIDE; + my($result,@values); @values = $self->_set_values_and_labels($values,\$labels,$name); @@ -2626,6 +2644,8 @@ my($name,$default,$override,@other) = rearrange([NAME,[DEFAULT,VALUE,VALUES],[OVERRIDE,FORCE]],@p); + $override = defined($override) ? $override : $OVERRIDE; + my $do_override = 0; if ( ref($p[0]) || substr($p[0],0,1) eq '-') { @value = ref($default) ? @{$default} : $default; @@ -3255,6 +3275,17 @@ } END_OF_FUNC +#### Method: override +# Set or return the OVERRIDE global flag +#### +'override' => <<'END_OF_FUNC', +sub override { + my ($self,$param) = self_or_CGI(@_); + $CGI::OVERRIDE = $param if defined($param); + return $CGI::OVERRIDE; +} +END_OF_FUNC + #### Method: nph # Set or return the NPH global flag #### @@ -4832,6 +4863,13 @@ this behavior. You can also selectively change the sticky behavior in each element that you generate. +=item -override + +Controls the default value for the B<-override> parameter for methods +that accept it. If set, all fields will be nonsticky by default, and +will only retain their value from the query string if B<-override> +is set to true for that element. + =item -tabindex Automatically add tab index attributes to each form field. With this
Subject: nosticky.pl
#!/usr/bin/env perl use strict; use warnings; use CGI qw/:standard/; # read in this script so we can print it seek(DATA, 0, 0); my $self = join('', <DATA>); # check to see if global override is requested if(param('global_override')) { CGI::override(1); } print header, html( start_form, "This script is to demonstrate the global override option for CGI.pm", br, "The boxes below should behave as indicated when checked. The only checkbox", br, "that has any effect is the first one.", br, br, checkbox( -name => "global_override", -label => "Enable default override?", -checked => param('global_override') ), br, checkbox( -override => 1, -name => "checkbox1", -label => "This box should always uncheck itself", -checked => 0 ), br, checkbox( -override => 0, -name => "checkbox2", -label => "This box should never uncheck itself", -checked => 0 ), br, checkbox( -name => "checkbox3", -label => "This box should only uncheck itself when global override is on", -checked => 0 ), br, submit, hr, "This script:", br, pre($self), end_form ); __DATA__
Lincoln, What do you think about this patch? I'm indecisive about how to triage it. Mark On Thu Jul 31 00:19:37 2008, KBAUCOM wrote: Show quoted text
> The documentation for the -nosticky pragma says that it prevents the > state preserving behavior of fields. In fact, it does two things: > 1) Makes the default name for submit buttons an empty string if no > label is supplied > 2) suppresses the .cgifields hidden field > > The documented behavior of -nosticky can be achieved by setting > override or force to 1 when calling any method that supports it. To > avoid breaking the current -nosticky functionality (assuming that is a > concern), this patch adds a new global variable called $OVERRIDE that > acts as a default value for override. The patch is on version 3.39. It > includes documentation for the override pragma, but does not update > the docs otherwise. > > I have also attached a small test script to demonstrate the new > pragma.
Not a single person has spoken up in support of this change since 2008, so I'm just going to consider this resolved.