X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAction%2FREST.pm;h=10d7c32f2dbf1aba6fc5e6ee7a96942cc178a1db;hb=e527bba30dcea5108b0fb77416fcb4e8ee1e5a38;hp=7adc6b2d98c1249ed862007fe2682cbbd077df49;hpb=5cb5f6bb8bd7e95865e8e3eb238b482aa161aa0d;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index 7adc6b2..10d7c32 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -1,23 +1,16 @@ -# -# REST.pm -# Created by: Adam Jacob, Marchex, -# Created on: 10/12/2006 03:00:32 PM PDT -# -# $Id$ - package Catalyst::Action::REST; -use strict; -use warnings; +use Moose; +use namespace::autoclean; -use base 'Catalyst::Action'; +extends 'Catalyst::Action'; use Class::Inspector; use Catalyst::Request::REST; use Catalyst::Controller::REST; BEGIN { require 5.008001; } -our $VERSION = '0.78'; +our $VERSION = '0.87'; $VERSION = eval $VERSION; sub new { @@ -74,8 +67,8 @@ It is likely that you really want to look at L, which brings this class together with automatic Serialization of requests and responses. -When you use this module, the request class will be changed to -L. +When you use this module, it adds the L +role to your request class. =head1 METHODS @@ -99,12 +92,13 @@ sub dispatch { # Common case, for foo_GET etc if ( $code = $controller->action_for($rest_method) ) { - $c->execute( $self->class, $self, @{ $c->req->args } ); - return $c->forward( $code, $c->req->args ); - } elsif ($code = $controller->can($rest_method)) { + $c->execute( $self->class, $self, @{ $c->req->args } ); # Execute normal 'foo' action. + return $c->forward( $code, $c->req->args ); # Forward to foo_GET if it's an action + } + elsif ($code = $controller->can($rest_method)) { # Exceute normal action $c->execute( $self->class, $self, @{ $c->req->args } ); - $name = $rest_method; + $name = $rest_method; # Stash name and code to run 'foo_GET' like an action below. } # Generic handling for foo_OPTIONS @@ -132,14 +126,8 @@ sub dispatch { sub _get_allowed_methods { my ( $self, $controller, $c, $name ) = @_; my $class = ref($controller) ? ref($controller) : $controller; - my $methods = Class::Inspector->methods($class); - my @allowed; - foreach my $method ( @{$methods} ) { - if ( $method =~ /^$name\_(.+)$/ ) { - push( @allowed, $1 ); - } - } - return @allowed; + my $methods = Class::Inspector->methods($class); + return map { /^$name\_(.+)$/ } @$methods; }; sub _return_options { @@ -169,8 +157,13 @@ sub _return_not_implemented { =head1 SEE ALSO -You likely want to look at L, which implements -a sensible set of defaults for a controller doing REST. +You likely want to look at L, which implements a +sensible set of defaults for a controller doing REST. + +This class automatically adds the L role to +your request class. If you're writing a webapp which provides RESTful +responses and still needs to accommodate web browsers, you may prefer to use +L instead. L, L @@ -185,35 +178,37 @@ one of the accepted return formats. You can do this by setting it in your query accepted return formats. You can do this by setting it in your query string thusly: C<< ?content-type=application%2Fjson (where %2F == / uri escaped). >> -B Apache will refuse %2F unless configured otherise. -Make sure C<< AllowEncodedSlashes On >> is in your httpd.conf file in orde +B Apache will refuse %2F unless configured otherwise. +Make sure C is in your httpd.conf file in order for this to run smoothly. =back =head1 AUTHOR -Adam Jacob , with lots of help from mst and jrockway +Adam Jacob Eadam@stalecoffee.orgE, with lots of help from mst and jrockway Marchex, Inc. paid me while I developed this module. (L) =head1 CONTRIBUTORS -Arthur Axel "fREW" Schmidt +Tomas Doran (t0m) Ebobtfish@bobtfish.netE + +John Goulah Christopher Laco -Luke Saunders +Daisuke Maki Edaisuke@endeworks.jpE -John Goulah +Hans Dieter Pearcey -Daisuke Maki +Dave Rolsky Eautarch@urth.orgE -J. Shirley +Luke Saunders -Hans Dieter Pearcey +Arthur Axel "fREW" Schmidt Efrioux@gmail.comE -Tomas Doran (t0m) +J. Shirley Ejshirley@gmail.comE =head1 COPYRIGHT