use Moose;
use namespace::autoclean;
-our $VERSION = '0.86';
+our $VERSION = '0.93';
$VERSION = eval $VERSION;
=head1 NAME
# Answer PUT requests to "thing"
sub thing_PUT {
- $radiohead = $req->data->{radiohead};
+ my ( $self, $c ) = @_;
+
+ $radiohead = $c->req->data->{radiohead};
$self->status_created(
$c,
return $serialized;
}
+=item * Callback
+
+For infinite flexibility, you can provide a callback for the
+deserialization/serialization steps.
+
+ __PACKAGE__->config(
+ map => {
+ 'text/xml' => [ 'Callback', { deserialize => \&parse_xml, serialize => \&render_xml } ],
+ }
+ );
+
+The C<deserialize> callback is passed a string that is the body of the
+request and is expected to return a scalar value that results from
+the deserialization. The C<serialize> callback is passed the data
+structure that needs to be serialized and must return a string suitable
+for returning in the HTTP response. In addition to receiving the scalar
+to act on, both callbacks are passed the controller object and the context
+(i.e. C<$c>) as the second and third arguments.
+
=back
By default, L<Catalyst::Controller::REST> will return a
my $c = shift;
$c->response->status(204);
$self->_set_entity( $c, undef );
- return 1.;
+ return 1;
}
=item status_multiple_choices
return 1;
}
+=item status_forbidden
+
+Returns a "403 FORBIDDEN" response. Takes a "message" argument
+as a scalar, which will become the value of "error" in the serialized
+response.
+
+Example:
+
+ $self->status_forbidden(
+ $c,
+ message => "access denied",
+ );
+
+=cut
+
+sub status_forbidden {
+ my $self = shift;
+ my $c = shift;
+ my %p = Params::Validate::validate( @_, { message => { type => SCALAR }, }, );
+
+ $c->response->status(403);
+ $c->log->debug( "Status Forbidden: " . $p{'message'} ) if $c->debug;
+ $self->_set_entity( $c, { error => $p{'message'} } );
+ return 1;
+}
+
=item status_not_found
Returns a "404 NOT FOUND" response. Takes a "message" argument
The C<begin> method uses L<Catalyst::Action::Deserialize>. The C<end>
method uses L<Catalyst::Action::Serialize>. If you want to override
either behavior, simply implement your own C<begin> and C<end> actions
-and use MRO::Compat:
+and forward to another action with the Serialize and/or Deserialize
+action classes:
package Foo::Controller::Monkey;
use Moose;
use namespace::autoclean;
-
+
BEGIN { extends 'Catalyst::Controller::REST' }
- sub begin :Private {
+ sub begin : Private {
my ($self, $c) = @_;
... do things before Deserializing ...
- $self->maybe::next::method($c);
+ $c->forward('deserialize');
... do things after Deserializing ...
}
+ sub deserialize : ActionClass('Deserialize') {}
+
sub end :Private {
my ($self, $c) = @_;
... do things before Serializing ...
- $self->maybe::next::method($c);
+ $c->forward('serialize');
... do things after Serializing ...
}
+ sub serialize : ActionClass('Serialize') {}
+
+If you need to deserialize multipart requests (i.e. REST data in
+one part and file uploads in others) you can do so by using the
+L<Catalyst::Action::DeserializeMultiPart> action class.
+
=back
=head1 A MILD WARNING
=cut
+__PACKAGE__->meta->make_immutable;
+
1;