Created
January 30, 2013 02:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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