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