no need for OurPkgVersion with modern dzil
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Controller / REST.pm
index bc480f0..428d749 100644 (file)
@@ -1,10 +1,8 @@
 package Catalyst::Controller::REST;
+
 use Moose;
 use namespace::autoclean;
 
-our $VERSION = '0.96';
-$VERSION = eval $VERSION;
-
 =head1 NAME
 
 Catalyst::Controller::REST - A RESTful controller
@@ -175,14 +173,6 @@ Uses the L<Data::Serializer> module to generate L<Data::Denter> output.
 
 Uses the L<Data::Serializer> module to generate L<Data::Taxi> output.
 
-=item * C<application/x-storable> => C<Data::Serializer>
-
-Uses the L<Data::Serializer> module to generate L<Storable> output.
-
-=item * C<application/x-freezethaw> => C<Data::Serializer>
-
-Uses the L<Data::Serializer> module to generate L<FreezeThaw> output.
-
 =item * C<text/x-config-general> => C<Data::Serializer>
 
 Uses the L<Data::Serializer> module to generate L<Config::General> output.
@@ -299,18 +289,9 @@ __PACKAGE__->mk_accessors(qw(serialize));
 __PACKAGE__->config(
     'stash_key' => 'rest',
     'map'       => {
-        'text/html'          => 'YAML::HTML',
         'text/xml'           => 'XML::Simple',
-        'text/x-yaml'        => 'YAML',
         'application/json'   => 'JSON',
         'text/x-json'        => 'JSON',
-        'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
-        'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],
-        'text/x-data-taxi'   => [ 'Data::Serializer', 'Data::Taxi'   ],
-        'application/x-storable'   => [ 'Data::Serializer', 'Storable' ],
-        'application/x-freezethaw' => [ 'Data::Serializer', 'FreezeThaw' ],
-        'text/x-config-general'    => [ 'Data::Serializer', 'Config::General' ],
-        'text/x-php-serialization' => [ 'Data::Serializer', 'PHP::Serialization' ],
     },
 );
 
@@ -579,6 +560,79 @@ sub status_gone {
     return 1;
 }
 
+=item status_see_other
+
+Returns a "303 See Other" response.  Takes an optional "entity" to serialize,
+and a "location" where the client should redirect to.
+
+Example:
+
+  $self->status_see_other(
+    $c,
+    location => $some_other_url,
+    entity => {
+        radiohead => "Is a good band!",
+    }
+  );
+
+=cut
+
+sub status_see_other {
+    my $self = shift;
+    my $c    = shift;
+    my %p    = Params::Validate::validate(
+        @_,
+        {
+            location => { type     => SCALAR | OBJECT },
+            entity   => { optional => 1 },
+        },
+    );
+
+    $c->response->status(303);
+    $c->response->header( 'Location' => $p{location} );
+    $self->_set_entity( $c, $p{'entity'} );
+    return 1;
+}
+
+=item status_moved
+
+Returns a "301 MOVED" response.  Takes an "entity" to serialize, and a
+"location" where the created object can be found.
+
+Example:
+
+ $self->status_moved(
+   $c,
+   location => '/somewhere/else',
+   entity => {
+     radiohead => "Is a good band!",
+   },
+ );
+
+=cut
+
+sub status_moved {
+   my $self = shift;
+   my $c    = shift;
+   my %p    = Params::Validate::validate(
+      @_,
+      {
+         location => { type     => SCALAR | OBJECT },
+         entity   => { optional => 1 },
+      },
+   );
+
+   my $location = ref $p{location}
+      ? $p{location}->as_string
+      : $p{location}
+   ;
+
+   $c->response->status(301);
+   $c->response->header( Location => $location );
+   $self->_set_entity($c, $p{entity});
+   return 1;
+}
+
 sub _set_entity {
     my $self   = shift;
     my $c      = shift;