Web-MREST
view release on metacpan or search on metacpan
lib/Web/MREST.pm view on Meta::CPAN
=head3 C<malformed_request> (B9)
A true return value from this method triggers a "400 Bad Request" response
status. RFC2616 does not stipulate exactly what constitutes a bad request.
We already (in allowed_methods) took care of the case when the URI
fails to match a known resource, and that includes applying any C<validations>
properties from the resource definition.
So, in this method (or your overlay) we take the "next step" (whatever that is)
in vetting the request. Keep in mind that this method is called before
the resource handler. If you have any sanity checks you wish to apply _after_
the URI is matched to a resource but _before_ the resource handler fires, this
is the place to put them.
If you would like to keep L<Web::MREST>'s implementation of this method
(which, for example, pushes the Content-Length and Content-Type information
onto the context) and add your own logic, you can put it in
C<mrest_malformed_request> instead of overriding C<malformed_request> itself.
lib/Web/MREST.pm view on Meta::CPAN
=item 2. do not retain
This approach is more simple because no C<mrest_init_router> need be written.
The application should have its own distro sharedir C<config/> and therein a
file C<dispatch_MetaConfig.pm>. Inside that file, the application puts its own
resource definitions in the C<MREST_RESOURCE_DEFINITIONS> and
C<MREST_ROOT_RESOURCE> parameters (refer to C<config/dispatch_MetaConfig.pm> in
the L<Web::MREST> distribution for syntax and semantics).
The application's definitions will overlay (i.e. replace) those of
L<Web::MREST>. Even in this scenario, some or all of L<Web::MREST>'s resources
could be used in the application, but only by copy-pasting the definitions and
their respective handlers into the application's source code.
=back
=head3 Tree structure
L<Web::MFILE> allows resources to be defined in a tree structure. It is
lib/Web/MREST.pm view on Meta::CPAN
=head2 Customized URI parsing
While L<Web::MREST> provides for URI parsing using L<Path::Router>, if this is
not desired the application developer can parse URIs herself by simply
substituting her own C<init_router> and C<match> methods for the ones provided
by L<Path::Router> and L<Path::Router::Route::Match>, respectively.
When request processing enters C<resource_exists>,
Alternatively, the application developer can overlay the C<init_router> routine
with one that returns an arbitrary object (stored in C<$router>) that has a
C<match> method. After that, L<Web::MREST> does
my $match = $router->match( $path );
where C<$path> is the relative portion of the URI (i.e. everything left after
the C<http://myapp.example.com/> part is cut off).
The C<$match> object should provide a C<route> method, which should return the
definition of the matched resource. See L<"RESOURCE DEFINITIONS">.
lib/Web/MREST/Resource.pm view on Meta::CPAN
'request' => $self->request,
'uri_path' => $path,
'method' => $self->request->method,
} );
return $self->mrest_service_available;
}
=head3 mrest_service_available
Hook. If you overlay this and intend to return false, you should call
C<< $self->mrest_declare_status >> !!
=cut
sub mrest_service_available {
my $self = shift;
$log->debug( "Entering " . __PACKAGE__ . "::mrest_service_available" ) unless $muffle{1};
return 1;
}
( run in 0.396 second using v1.01-cache-2.11-cpan-65fba6d93b7 )