1 package Catalyst::Action::REST::ForBrowsers;
4 use namespace::autoclean;
7 $VERSION = eval $VERSION;
9 extends 'Catalyst::Action::REST';
10 use Catalyst::Request::REST::ForBrowsers;
15 Catalyst::Request::REST::ForBrowsers->_insert_self_into( $config->{class} );
16 return $class->SUPER::BUILDARGS( $config, @_ );
19 override dispatch => sub {
23 my $req = $c->request();
26 unless $req->can('looks_like_browser')
27 && $req->looks_like_browser()
28 && uc $c->request()->method() eq 'GET';
30 my $controller = $c->component( $self->class );
31 my $rest_method = $self->name() . '_GET_html';
33 if ( $controller->action_for($rest_method)
34 || $controller->can($rest_method) ) {
36 return $self->_dispatch_rest_method( $c, $rest_method );
42 __PACKAGE__->meta->make_immutable;
48 Catalyst::Action::REST::ForBrowsers - Automated REST Method Dispatching that Accommodates Browsers
52 sub foo :Local :ActionClass('REST::ForBrowsers') {
53 ... do setup for HTTP method specific handlers ...
56 sub foo_GET : Private {
57 ... do something for GET requests ...
60 sub foo_GET_html : Private {
61 ... do something for GET requests from browsers ...
64 sub foo_PUT : Private {
65 ... do something for PUT requests ...
70 This class subclasses L<Catalyst::Action::REST> to add an additional
71 dispatching hook. If the request is a GET request I<and> the request looks
72 like it comes from a browser, it tries to dispatch to a C<GET_html> method
73 before trying to the C<GET> method instead. All other HTTP methods are
74 dispatched in the same way.
76 For example, in the synopsis above, calling GET on "/foo" from a browser will
77 end up calling the C<foo_GET_html> method. If the request is I<not> from a
78 browser, it will call C<foo_GET>.
80 See L<Catalyst::Action::REST> for more details on dispatching details.
88 This method overrides the default dispatch mechanism to the re-dispatching
89 mechanism described above.
95 You likely want to look at L<Catalyst::Controller::REST>, which implements a
96 sensible set of defaults for a controller doing REST.
98 This class automatically adds the
99 L<Catalyst::TraitFor::Request::REST::ForBrowsers> role to your request class.
103 Dave Rolsky E<lt>autarch@urth.orgE<gt>
107 Copyright the above named AUTHOR and CONTRIBUTORS
111 You may distribute this code under the same terms as Perl itself.