Apache2::Controller

A framework for Apache2 handler apps
Download

Apache2::Controller Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Mark Hedges
  • Publisher web site:
  • http://search.cpan.org/~markle/

Apache2::Controller Tags


Apache2::Controller Description

A framework for Apache2 handler apps Apache2::Controller is a lightweight controller framework for object-oriented applications designed to run only under mod_perl children in high-performance Apache2 handler modules.SYNOPSISFor Apache2 config file setup see Apache2::Controller::Dispatch, which pushes a PerlResponseHandler of Apache::Controller, which then instantiates your controller object and calls the chosen method for the uri. package MyApp::C::Foo; use strict; use warnings FATAL => 'all'; use base qw( Apache2::Controller ); use Apache2::Const -compile => qw( :http ); sub allowed_methods {qw( default bar baz )} # suppose '/foo' is the uri path dispatched to this controller # and your dispatch uses L # http://myapp.xyz/foo/ sub default { my ($self) = @_; $self->content_type('text/plain'); $self->print("Hello, world! "); return Apache2::Const::HTTP_OK; } # http://myapp.xyz/foo/bar/biz/schnozz sub bar { my ($self, @path_args) = @_; # @path_args is: # qw( biz schnozz ) # @{ $self->{path_args} } # @{ $self->pnotes->{path_args} } $self->content_type('text/html'); $self->print(q{ "WE ARE ALL KOSH" }); return Apache2::Const::HTTP_OK; } # http://myapp.xyz/foo/baz sub baz { my ($self) = @_; return Apache2::Const::HTTP_BAD_REQUEST if $self->param('goo'); # inherits Apache2::Request return Apache2::Const::HTTP_FORBIDDEN if $self->param('boz') ne 'noz'; $self->content_type('text/plain'); # inherits Apache2::RequestRec $self->sendfile('/etc/passwd'); # inherits Apache2::RequestIO return Apache2::Const::HTTP_OK; } 1;You could implement a pretty nice REST interface, or any other kind of HTTP-based API, by returning the appropriate HTTP status codes. See "status" in Apache2::Controller::Refcard for a list.See Apache2::Controller::Render::Template for an additional base for your controller class to render HTML with Template Toolkit.Apache2::Controller features URL dispatch with flexible configuration, auth plugins, a cookie tracker for Apache::Session, liberty for any storage models that work under mod_perl, rendering using Template Toolkit or direct printing with Apache, and base inheritance configuration allowing you to construct your applications as you need, without trying to be all things to all people or assimilate the world. It is intended as a framework for new applications specialized as Apache2 handlers, not as a means to absorb existing applications or to create portable code.Apache2::Controller subclasses Apache2::Request, and pulls in methods from Apache2::RequestRec, Apache2::RequestIO, Apache2::RequestUtil, Apache2::Log, Apache2::Module.For using other Apache2 request extension methods, use another base class like Apache2::Controller::Upload early in your use base list, which will add the methods from Apache2::Upload when the Apache2::Request object gets created. Apache2::Controller::Uploads is a second base module for controller modules to inherit from to allow file uploads and provide various handy file conversion routines, if you have the appropriate binaries installed.Apache2::Controller::Render::Template provides an easy way to use Template Toolkit by default to render pages, selecting templates from a directory structure that corresponds to your controller URI's.Individual controller methods can specify plain text or other content types and print directly through inherited Apache2::RequestIO methods.Instead of abstracting Rube Goldberg devices around the Apache2 mod_perl methods, it stays out of your way and lets you use any and all of them directly through $self as you see fit.Use Apache2::Controller::Dispatch from your Apache2 config file to send various URI requests to your page view modules. See the CONFIGURATION section below. This features a standard mechanism for uri dispatch in Apache2::Controller::Dispatch::Simple that does not try to figure out what modules are available, but simply requires you to provide a hash that maps from uri paths to controller modules. Or, dispatch plugins can be created to implement the dispatcher's find_controller() method in some other way, like with a TRIE for big sites or using other algorithms.Apache2::Controller is the base module for each controller module. Your controller modules then contain a list of the method names which are allowed as uri paths under the controller. Instead of implementing a complex scheme of subroutine attributes, you maintain a list, which also acts as your documentation in one place within the controller. This frees you to structure your controller module as you want to, with whatever other methods you choose to put in there. Requirements: · Perl


Apache2::Controller Related Software