CGI ponderings
Tom Christiansen (tchrist@mox.perl.com)
Fri, 16 Jun 95 09:29:03 MDT
I was wondering whether a couple other CGI modules should be
supplied. One would capture errors and warnings. Here's
what I've been putting at the top of my scripts:
use CGI::Base;
use CGI::Request;
BEGIN {
CGI::Base::LogFile("/usr/local/etc/httpd/logs/mxperl.log");
$ADMIN = 'tchrist@mox.perl.com';
$SIG{__DIE__} = sub {
print "<HR><STRONG>";
print "<H1>FATAL ERROR</H1>\n";
print "Unexpected Fatal Error in $0:";
print "<PRE>@_</PRE></STRONG>\n";
print "<HR>Please send mail to $ADMIN for help.\n";
die "FATAL!! @_";
};
$SIG{__WARN__} = sub {
print "<HR><STRONG>";
print "<PRE>WARNING: @_</PRE></STRONG>\n";
warn "WARNING!! @_";
};
SendHeaders();
}
The other would save punctation, allowing you to write things
like this:
if (@user_query) {
H2 "User Query";
DLstart;
DT;
print "You want me to execute the following query:";
DD;
P;
start("CODE");
print join " and ", @user_query;
end("CODE");
DLend;
} else {
print "What don't you want a user query?";
}
Here's a trivial partial implementation :
sub bracket { print "<$_[0]>\n" }
sub HR { bracket "HR"; }
sub P { bracket "P"; }
sub BR { bracket "BR"; }
sub LI { bracket "LI"; }
sub DD { bracket "DD"; }
sub DT { bracket "DT"; }
sub start { bracket ($_[0]) }
sub end { bracket ("/$_[0]") }
sub bracket_pair {
my($name, $value) = @_;
start($name);
print $value, "\n";
end($name);
}
sub H1 { bracket_pair("H1", "@_") }
sub H2 { HR(); bracket_pair("H2", "@_") }
sub ULstart { start("UL") }
sub ULend { end("UL") }
sub DLstart { start("DL") }
sub DLend { end("DL") }
sub OLstart { start("OL") }
sub OLend { end("OL") }
Have these two things been done before and did I just miss it?
Should they be? What should the modules be named?
--tom