thewebsi has asked for the wisdom of the Perl Monks concerning the following question:

According to http://search.cpan.org/~markstos/CGI.pm-3.51/lib/CGI.pm#AUTOESCAPING_HTML I should be able to get the current state of CGI::autoEscape(). However, when I try this, it seems to change the state to false (quantum mechanics?):

perl -e 'use CGI; print $CGI::VERSION . "\n" . ( CGI::autoEscape() || 0 ) . ( CGI::autoEscape() || 0 ) . "\n";'

Result:

3.51 10

Am I not doing it right, or is this a CGI bug?

Replies are listed 'Best First'.
Re: Get CGI::autoEscape() state
by wind (Priest) on May 10, 2011 at 21:53 UTC
    Looking at the source for CGI::autoEscape shows this:
    #### Method: autoescape # If you want to turn off the autoescaping features, # call this method with undef as the argument 'autoEscape' => <<'END_OF_FUNC', sub autoEscape { my($self,$escape) = self_or_default(@_); my $d = $self->{'escape'}; $self->{'escape'} = $escape; $d; }

    Basically, the accessor always mutates the value. So I'd suggest just treating it like a mutator only.