package Maasha::XHTML;
-# Copyright (C) 2005 Martin A. Hansen.
+# Copyright (C) 2005-2010 Martin A. Hansen.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ISA = qw( Exporter );
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SIGNAL HANDLERS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+use sigtrap qw( die normal-signals stack-trace any error-signals );
+
+my $WARNINGS = 0;
+
+$SIG{ '__DIE__' } = \&sig_die;
+$SIG{ '__WARN__' } = \&sig_warn;
+
+
+sub sig_die
+{
+ my ( $sig, # signal from the %SIG
+ ) = @_;
+
+ my ( @html );
+
+ push @html, &cgi_header;
+ push @html, p( txt => "ERROR: $sig" );
+
+ $WARNINGS++;
+
+ print "$_" for @html;
+}
+
+
+sub sig_warn
+{
+ my ( $sig, # signal from the %SIG
+ ) = @_;
+
+ my ( @html );
+
+ push @html, &cgi_header if $WARNINGS == 0;
+ push @html, p( txt => "WARNING: $sig" );
+
+ $WARNINGS++;
+
+ print "$_" for @html;
+}
+
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> HEADERS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
my ( @html );
- push @html, &cgi_header if $args{ "cgi_header" };
+ push @html, &cgi_header if $args{ "cgi_header" } and $WARNINGS == 0;
push @html, &doc_type;
push @html, &head_beg;
push @html, &title( $args{ "title" } ) if $args{ "title" };