Apache2::Controller::X - Exception::Class hierarchy for Apache2::Controller
Version 1.000.111
package MyApp::C::Foo; use base qw( Apache2::Controller MyApp::Blabber ); use Apache2::Controller::X; # ... sub some_page_controller_method { my ($self, @path_args) = @_; $self->print( $self->blabber() || a2cx "Cannot blabber: $OS_ERROR" ); } # or subclass and extend the errors... package MyApp::X; use base qw( Apache2::Controller::X ); use Exception::Class ( 'MyApp::X' => { isa => 'Apache2::Controller::X', fields => [qw( message status dump action )], }, alias => 'myx', ); package MyApp::C::Bar; use base qw( Apache2::Controller ); use Apache2::Const -compile => qw( :http ); use MyApp::X; # ... sub page_controller_method { myx message => q{ You're not supposed to be here. }, status => Apache2::Const::FORBIDDEN, action => sub {"not sure how you'd implement this actually"}, dump => { this => q{structure will get YAML::Syck::Dump'd}, that => [qw( to the error log )], }; }
TODO: when $X is intercepted by handler() in each of the controller layers, attach it to pnotes.
Hierarchy of Exception::Class objects for Apache2::Controller. All are subclasses of Apache2::Controller::X.
All Apache2::Controller::X exceptions implement three fields:
Required. The standard Exception::Class message field. If you call throw() or the alias a2cx() with only one argument, a string, then this gets set as the message field, which is displayed when the object is referred to in string context.
throw()
a2cx()
eval { a2cx "booyeah" }; if (my $X = Exception::Class->caught('Apache2::Controller::X')) { warn "my exception 'message' was '$X'\n"; warn $X->trace; }
This can be set to an ":http" in Apache2::Const constant, which will then be set as the status for the request.
a2cx message => "oh no!", status => Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
Combined with status, when intercepted by "handler" in Apache2::Controller this sets a custom message with "status_line" in Apache2::RequestRec.
a2cx message => "Warp injection coil failure in unit 3-A-73", status => Apache2::Const::HTTP_INTERNAL_SERVER_ERROR, status_line => "Turbulence ahead. Please buckle your safety belts.";
This differentiation can be used to display technical information in the log while giving a nice message to the user.
If "error" in Apache2::Controller::Render::Template is used, status_line is preferentially used to translate the error code, otherwise it uses "status_message" in HTTP::Status.
An arbitrary data structure which Apache2::Controller will send through YAML::Syck Dump() when printing to the error log.
The basic exception object that implements the three basic fields.
After abandoning redirects, I have no use for any subclasses. Should not re-invent the wheel, after all. Just set the outgoing location header and return REDIRECT from a controller if you want to do that. Or other actions should be done.
This is the Fields() method provided by Exception::Class. For some reason the pod test wants this method enumerated.
Exception::Class
Apache2::Controller
Apache2::Controller::NonResponseBase
Apache2::Controller::NonResponseRequest
Mark Hedges, <hedges ||at formdata.biz>
<hedges ||at formdata.biz>
Copyright 2008-2010 Mark Hedges, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This software is provided as-is, with no warranty and no guarantee of fitness for any particular purpose.
To install Apache2::Controller, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache2::Controller
CPAN shell
perl -MCPAN -e shell install Apache2::Controller
For more information on module installation, please visit the detailed CPAN module installation guide.