Apache2-Controller
view release on metacpan or search on metacpan
lib/Apache2/Controller.pm view on Meta::CPAN
$self->print("Take this job and shove it!\n", "\n", $X, "\n");
if ($X->isa('Apache2::Controller::X')) {
# usually you wouldn't show gory details to the user...
$self->print(Dump($X->dump)) if $X->dump;
$self->print($X->trace) if $X->trace;
}
}
For instance
L<Apache2::Controller::Render::Template> implements
C<< error() >> for you, which looks for
the appropriately named error template as
F<template_dir/errors/###.html>.
Of course, all exceptions are sent to the error log using
L<Log::Log4perl> DEBUG() before the handler completes, and
any refusal status greater or equal to 400 (HTTP_BAD_REQUEST)
will be written to the access log with L<Apache2::Log> log_reason()
using the first few characters of the error.
See L<Apache2::Controller::Session/ERRORS> for how to control
lib/Apache2/Controller.pm view on Meta::CPAN
use base qw( Apache2::Controller::Methods );
use Readonly;
use Scalar::Util qw( blessed );
use Log::Log4perl qw(:easy);
use YAML::Syck;
use Digest::SHA qw( sha224_base64 );
use URI;
use HTTP::Status qw( status_message );
use Scalar::Util qw( looks_like_number );
use Apache2::Controller::X;
use Apache2::Controller::Funk qw( log_bad_request_reason );
use Apache2::Request;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
use Apache2::Log;
use Apache2::Const -compile => qw( :common :http );
lib/Apache2/Controller.pm view on Meta::CPAN
See L<Apache2::Controller::Methods>.
=head2 handler
# called from Apache, your subclass pushed to PerlResponseHandler
# by your A2C dispatch handler:
MyApp::Controller::Foo->handler( Apache2::RequestRec object )
The handler is pushed from an Apache2::Controller::Dispatch
subclass and via your dispatched subclass of Apache2::Controller.
It should not be set in the config file. It looks
for the controller module name in C<< $r->pnotes->{a2c}{controller} >>
and for the method name in C<< $r->pnotes->{a2c}{method} >>.
Errors are intercepted and if the handler object was created
and implements an C<< $handler->error($exception) >> method
then the exception will be passed as the argument.
An HTTP status code of HTTP_BAD_REQUEST or greater will
cause log_reason to be called with a truncated error string
and the uri for recording in the access log.
lib/Apache2/Controller.pm view on Meta::CPAN
$handler = $class->a2c_new($r);
$method = $handler->{method};
DEBUG("executing $class -> $method()");
my $args = $pnotes_a2c->{path_args} || [];
$status = $handler->$method(@{$args});
$status = $r->status() if !defined $status;
if (defined $status) {
if (ref $status || !looks_like_number($status)) {
a2cx message => "Controller returned or set non-numeric status",
status => Apache2::Const::SERVER_ERROR,
dump => { controller_set_status => $status };
}
elsif ($status < 0) {
a2cx message => "controller must set http status >= 0",
status => Apache2::Const::SERVER_ERROR,
dump => { controller_set_status => $status };
}
}
lib/Apache2/Controller/Dispatch/RenderTemplate.pm view on Meta::CPAN
You do not need to subclass this A2C dispatch class. It assumes
controller library structure from the structure of html template files
and renders them with L<Apache2::Controller::Render::Template>.
# virtualhost.conf:
PerlSwitches -I/myapp/lib
<Location '/'>
# primary path looks like a web site; secondary 'cmp' = component templates:
A2C_Render_Template_Path /myapp/html /myapp/cmp
# what lib name do we prefix to the ucfirst()ed primary html files?
A2CControllerLibs MyApp::C
# set and go:
SetHandler modperl
PerlInitHandler Apache2::Controller::Dispatch::RenderTemplate
</Location>
lib/Apache2/Controller/Render/Template.pm view on Meta::CPAN
}
=head2 detect_template
This is called internally by the render methods, but you can use
it to figure out the default template from where you are.
To override the auto-select template, just set $self->{template}
before you call C<<render()>>.
It looks for templates in a computed directory. The directory where it
looks will always be the directory set with the A2C_Render_Template_Path
directive in the config file, appended with the current request location,
i.e. the directory of the Location directive in the config file,
appended with relative_uri, appended with method name and '.html'.
A2C_Render_Template_Path + location + relative_uri + method.html
For example, the sequence in SYNOPSIS above renders the file
C</var/myapp/templates/foo/default.html> .
Suppose the dispatch class above dispatches sub-path uris starting
( run in 0.507 second using v1.01-cache-2.11-cpan-64827b87656 )