Add set of Todd Larason plugins to general.
[blosxom-plugins.git] / general / seeerror
bloba6d357de4f697ceabbf58908a6d999b8fb581128
1 # Blosxom Plugin: seeerror                                         -*- perl -*-
2 # Author: Todd Larason (jtl@molehill.org)
3 # Version: 0+1i
4 # Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom
5 # Categories plugin Home/Docs/Licensing:
6 #   http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/SeeError/
8 package seeerror;
10 # ------------------------- Configuration Variables --------------------------
11 # Directory to create the temporary files in.
12 # Criteria:
13 # *  It MUST exist
14 # *  It MUST be writable
15 # *  It SHOULD be readable outside Blosxom
16 $tmp_dir ||= "/tmp";
18 # Attempt to deal with fatal errors?  Should only be enabled if you need it.
19 $handle_die = 0
20   unless defined $handle_die;
21 # ----------------------------------------------------------------------------
23 use FileHandle;
24 use CGI;
26 my $tmp_file = sprintf "$tmp_dir/bloserr-$$-$^T-%s.txt", CGI::remote_host();
27 open STDERR,"> $tmp_file";
29 if ($handle_die) {
30     $SIG{__DIE__} = sub {
31         print "content-type: text/html\n\n<h1>Possibly-Fatal Error</h1>$@";
32     };
35 sub start {1;}
36 sub end {
37     close STDERR;  # force a flush
38     my $fh = new FileHandle;
39     $fh->open("< $tmp_file");
40     my $errors = join '',<$fh>;
41     $fh->close;
42     if ($errors) {
43         $errors =~ s:&:&amp;:g;
44         $errors =~ s:<:&lt;:g;
45         print "<h1>Error Output</h1><pre>$errors</pre>";
46     }
47     unlink($tmp_file);
48     return 1;