[tpm] 'use CGI::Carp' being calling in an 'if' block when condition not met
Madison Kelly
linux at alteeve.com
Thu Jan 8 14:21:10 PST 2009
Hi all,
I've got a program that can either be printed to a browser or shell.
To this end, I have a simple function that determines how the program is
running. When it detects a browser, it loads 'CGI::Carp
qw(fatalsToBrowser);'.
The problem is that this module is being loaded regardless of whether
The containing 'if' block's condition is met.
Here's the function
------------------------------------------------------------------------
sub detect_calling_method
{
my ($conf)=@_;
# Now determine if we are being called via the command line or a
# browser and update the 'conf' value.
if ($ENV{HTTP_USER_AGENT})
{
# HTML, load CGI.
$conf->{'system'}{display}{mode}="html";
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html; charset=utf-8\n\n";
}
elsif ($ENV{SHELL})
{
$conf->{'system'}{display}{mode}="text";
STDOUT->autoflush(1);
}
print "$THIS_FILE ".__LINE__.": system::display::mode:
[$conf->{'system'}{display}{mode}]\n";
# Not detecting a mode is no longer fatal, it simply remains the
# default value set in the config file.
return(1);
}
------------------------------------------------------------------------
So even if '$ENV{HTTP_USER_AGENT}' is empty and
'$conf->{'system'}{display}{mode}' is set to 'text' (showing that it was
the condition matched), calling 'die' shows an HTML'ized error like:
------------------------------------------------------------------------
common.lib 238: system::display::mode: [text]
<h1>Software error:</h1>
<pre>Looping in common.lib at line 665 on string: [Opening log file on:
[#!var!0!#] at: [#!var!1!#] from file: [#!var!2!#].]. Exiting.
</pre>
<p>
For help, please send mail to this site's webmaster, giving this error
message
and the time and date of the error.
</p>
------------------------------------------------------------------------
Any tips?
More information about the toronto-pm
mailing list