Skip to content

Instantly share code, notes, and snippets.

@warewolf
Created January 30, 2013 02:19
Show Gist options
  • Select an option

  • Save warewolf/4670028 to your computer and use it in GitHub Desktop.

Select an option

Save warewolf/4670028 to your computer and use it in GitHub Desktop.
@warewolf's apache mod_perl 1.x session handler that sends a static page in case of errors
package HTML::Mason::Exception;
use strict;
use warnings;
sub as_wrapped
{
my ($self) = @_;
my $r = Apache->request();
my $info = $self->analyze_error;
my $msg = $self->full_message;
my $doc_root = $r->document_root;
my $stack = join("\n", map { sprintf(" [%s:%d]", $_->filename, $_->line) } @{$info->{frames}});
my $body = sprintf("Request as string: %s\n\nError Message: %s\n\nStack: %s\n\n",$r->as_string,$msg,$stack);
$r->log_error($body);
open(ERROR_PAGE,"<","$doc_root/internal_server_error.html");
$/=undef;
my $ret = <ERROR_PAGE>;
$/="\n";
close ERROR_PAGE;
return $ret;
}
package MasonX::Request::WithCustomApacheSession;
use strict;
use warnings;
$MasonX::Request::WithCustomApacheSession::VERSION = '0.01';
use HTML::Mason::Exceptions ( abbr => ['error'] );
use HTML::Mason::ApacheHandler;
use base qw(MasonX::Request::WithApacheSession);
use Apache::Request;
sub new {
my $class = shift;
$class->alter_superclass("MasonX::Request::WithApacheSession");
# make ourselves a copy of our new superclass
return $class->SUPER::new(@_, error_format => 'wrapped');
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment