[Xitami] Re: ActivePerl & Xitami - CGI problems Continued

Francis Turner xitami@lists.xitami.org
Wed, 25 Sep 2002 18:23:28 +0200


Paul Reid wrote:

>  
>
>>******************* Lesson Learned! ********************
>>    
>>
>
>NEVER, NEVER TEST Perl CGI SCRIPTS WITHOUT:
> 1) use CGI::Carp qw(fatalsToBrowser);
> 2) running with the " -w" option
> 3) use Strict;
>  
>
I have also found that the environment is rather useful when testing 
(e.g. paramters passed tend to be called FORM_XXXX so you can easily 
spot any typos) thus I tend to have the following at the top of my 
scripts (note that the environment is only printed out when the remote 
address is 127.0.0.1 I.e. localhost)

use CGI::Carp qw(fatalsToBrowser set_message);
BEGIN {
  sub handle_errors {
    my $msg = shift;
    print "<h1>Script Error</h1> running".$ENV{'SCRIPT_NAME'}."<p><pre>";
    $msg =~ s/ (of )*\Q$0//g;
    print "$msg</pre><A HREF='mailto:XXXXX'>Email me this page</a>";
    return unless ($ENV{'REMOTE_ADDR'} eq "127.0.0.1");
    print '<p><B>Environment Variables:</B><PRE>';
    foreach (sort keys %ENV) {
    print "$_: [$ENV{$_}]\n";
    }
    }
  set_message(\&handle_errors);
}


-- 
...if the US Government were ever to get really serious about Internet 
security, the top players in Microsoft's management hierarchy would find 
themselves handcuffed, blindfolded, led onto a tarmac within some obscure 
Air Force base, and shot.
-- Thomas C Greene (http://www.theregister.co.uk/content/55/23223.html)