Commit patch from Fabien Wernli
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Controller / REST.pm
index fe3d49f..87ee40c 100644 (file)
@@ -398,6 +398,36 @@ sub status_no_content {
     return 1.;
 }
 
+=item status_multiple_choices
+
+Returns a "300 MULTIPLE CHOICES" response. Takes an "entity" to serialize, which should
+provide list of possible locations. Also takes optional "location" for preferred choice.
+
+=cut
+
+sub status_multiple_choices {
+    my $self = shift;
+    my $c    = shift;
+    my %p    = Params::Validate::validate(
+        @_,
+        {
+            entity => 1,
+            location => { type     => SCALAR | OBJECT, optional => 1 },
+        },
+    );
+
+    my $location;
+    if ( ref( $p{'location'} ) ) {
+        $location = $p{'location'}->as_string;
+    } else {
+        $location = $p{'location'};
+    }
+    $c->response->status(300);
+    $c->response->header( 'Location' => $location ) if exists $p{'location'};
+    $self->_set_entity( $c, $p{'entity'} );
+    return 1;
+}
+
 =item status_bad_request
 
 Returns a "400 BAD REQUEST" response.  Takes a "message" argument