Web-MREST
view release on metacpan or search on metacpan
lib/Web/MREST/Resource.pm view on Meta::CPAN
=cut
sub declared_status {
my $self = shift;
return $self->status_declared;
}
=head2 nullify_declared_status
This method nullifies any declared status that might be pending.
=cut
sub nullify_declared_status {
my $self = shift;
$log->debug( "Nullifying declared status: " . Dumper( $self->context->{'declared_status'} ) );
delete $self->context->{'declared_status'};
return;
}
=head2 FSM Part One
The following methods override methods defined by L<Web::Machine::Resource>.
They correspond to what the L<Web::MREST> calls "Part One" of the FSM. To muffle
debug-level log messages from this part of the FSM, set $muffle{1} = 1 (above).
=head3 service_available (B13)
This is the first method called on every incoming request.
=cut
sub service_available {
my $self = shift;
$log->debug( "Entering " . __PACKAGE__ . "::service_available (B13)" ) unless $muffle{1};
$self->init_router unless ref( $router ) and $router->can( 'match' );
my $path = $self->request->path_info;
$path =~ s{^\/}{};
my $reported_path = ( $path eq '' )
? 'the root resource'
: $path;
$log->info( "Incoming " . $self->request->method . " request for $reported_path" );
$log->info( "Self is a " . ref( $self ) );
$self->push_onto_context( {
'headers' => $self->request->headers,
'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;
}
=head3 known_methods (B12)
Returns the value of C<MREST_SUPPORTED_HTTP_METHODS> site parameter
=cut
sub known_methods {
my $self = shift;
$log->debug( "Entering " . __PACKAGE__ . "::known_methods (B12)" ) unless $muffle{1};
my $method = $self->context->{'method'};
my $known_methods = $site->MREST_SUPPORTED_HTTP_METHODS || [ qw( GET POST PUT DELETE ) ];
$log->debug( "The known methods are " . Dumper( $known_methods ) ) unless $muffle{1};
if ( ! grep { $method eq $_; } @$known_methods ) {
$log->debug( "$method is not among the known methods" ) unless $muffle{1};
$self->mrest_declare_status( explanation => "The request method $method is not one of the supported methods " . join( ', ', @$known_methods ) );
}
return $known_methods;
}
=head3 uri_too_long (B11)
Is the URI too long?
=cut
sub uri_too_long {
my ( $self, $uri ) = @_;
$log->debug( "Entering " . __PACKAGE__ . "::uri_too_long (B11)" ) unless $muffle{1};
my $max_len = $site->MREST_MAX_LENGTH_URI || 100;
$max_len += 0;
if ( length $uri > $max_len ) {
$self->mrest_declare_status;
return 1;
}
$self->push_onto_context( { 'uri' => $uri } );
return 0;
}
=head3 allowed_methods (B10)
Determines which HTTP methods we recognize for this resource. We return these
( run in 0.653 second using v1.01-cache-2.11-cpan-39bf76dae61 )