Apache2-REST

 view release on metacpan or  search on metacpan

lib/Apache2/REST/Handler.pm  view on Meta::CPAN

package Apache2::REST::Handler ;

use strict ;
use warnings ;

use Data::Dumper ;
use Apache2::Const qw( 
                       :common :http 
                       );

use Apache2::REST::Conf ;
use Apache2::REST::ErrorOutputRegistry ;

use base qw/Class::AutoAccess/ ;

=head1 NAME

Apache2::REST::Handler - Base class for a resource handler.

=head1 SYNOPSIS

A Handler object is build for each fragment of the URI, and objects are chained via the attibute parent.

You _must_ implement at list one Handler class to handle the root URI of your application and set it in your
apache conf by : PerlSetVar Apache2RESTHandlerRootClass "MyApp::REST::API" (for instance).

You _must_ implement at least one HTTP method (GET,POST,PUT,DELETE ...).

They will be called by the framework like this (for instance):

 $this->GET($request,$response) ;

$request is an Apache2::REST::Request (which is a subclass of Apache2::Request).
$response is an Apache2::REST::Response 


Each method must return a valid Apache2::Const::HTTP_* code. 
Typically Apache2::Const::HTTP_OK when everything went smoothly.

See http://search.cpan.org/dist/Apache2-Controller/lib/Apache2/Controller/Refcard.pm for a list.

You _must_ implement at least one isAuth method along the URI. Typically if you want to allow GET by default:

    sub isAuth{ my ( $self , $method , $req  ) = @ _; return $method eq 'GET' ;}


See L<Apache2::REST> for a full working handler example.


=head2 class

Helper to get the class of this (or this class).

=cut

sub class{
    my ( $self ) = @ _;
    return ref $self || $self ;
}

=head2 handle

Handles a request and does the framework magic.
Override at your own risks.

=cut



( run in 1.850 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )