The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache2::Controller::X - Exception::Class hierarchy for Apache2::Controller

SYNOPSIS

 package MyApp::C::Foo;
 use base qw( Apache2::Controller ); 
 use Apache2::Controller::X;
 # ...
 sub page_controller_method {
    Apache2::Controller::X::Redirect->throw('http://foo.bar');
 }

 # or subclass and extend the errors...
 
 package MyApp::X;
 use base qw( Apache2::Controller::X );
 use Exception::Class (
     'MyApp::X' => { 
         isa => 'Apache2::Controller::X',
     },
     'MyApp::X::Redirect' => { 
         isa => 'Apache2::Controller::X::Redirect',
     },
 );

 package MyApp::C::Bar;
 use base qw( Apache2::Controller );
 use Apache2::Const -compile => qw( :http );
 use MyApp::X;
 # ...
 sub page_controller_method {
     MyApp::X->throw(
          message => q{ You're not supposed to be here. },
          http_status => Apache2::Const::FORBIDDEN,
          dump => {
            this    => q{structure will get YAML::Syck::Dump'd},
            that    => [qw( to the error log )],
          },
     );
 }

DESCRIPTION

Hierarchy of Exception::Class objects for Apache2::Controller. All are subclasses of Apache2::Controller::X.

FIELDS

All Apache2::Controller::X exceptions implement three fields:

message

Required. The standard Exception::Class message field. If you call throw() 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.

 eval { Apache2::Controller::X->throw("booyeah") };
 if (my $X = Exception::Class->caught('Apache2::Controller::X')) {
     warn "my exception 'message' was '$X'\n";
     warn $X->trace;
 }

http_status

This can be set to an ":http" in Apache2::Const constant, which will then be set as the http_status for the request.

 Apache2::Controller::X->throw(
     message => "oh no!",
     http_status => Apache2::Const::HTTP_INTERNAL_SERVER_ERROR,
 );

dump

An arbitrary data structure which Apache2::Controller will send through YAML::Syck Dump() when printing to the error log.

SUBCLASSES

Apache2::Controller::X

The basic exception object that implements the three basic fields.

Apache2::Controller::X::Redirect

If thrown back to the handler, the message will be used as a url to redirect the browser.

 Apache2::Controller::X::Redirect->throw('http://foo.bar');

This works by setting $r->location(), not through an internal redirect. If you want to do an internal redirect, just do it with $self->internal_redirect() inherited from Apache2::SubRequest.

SEE ALSO

Exception::Class, Apache2::Controller

AUTHOR

Mark Hedges, <hedges at scriptdolphin.org>

COPYRIGHT & LICENSE

Copyright 2008 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.