Action::REST::ForBrowsers works, with tests
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / lib / Catalyst / Action / REST / ForBrowsers.pm
CommitLineData
83273f94 1package Catalyst::Action::REST::ForBrowsers;
2
3use Moose;
4use namespace::autoclean;
5
6our $VERSION = '0.88';
7$VERSION = eval $VERSION;
8
9extends 'Catalyst::Action::REST';
10use Catalyst::Request::REST::ForBrowsers;
11
12sub BUILDARGS {
13 my $class = shift;
14 my $config = shift;
15 Catalyst::Request::REST::ForBrowsers->_insert_self_into( $config->{class} );
16 return $class->SUPER::BUILDARGS( $config, @_ );
17}
18
19override dispatch => sub {
20 my $self = shift;
21 my $c = shift;
22
23 my $req = $c->request();
24
25 return super()
26 unless $req->can('looks_like_browser')
27 && $req->looks_like_browser()
28 && uc $c->request()->method() eq 'GET';
29
30 my $controller = $c->component( $self->class );
31 my $rest_method = $self->name() . '_GET_html';
32
33 if ( $controller->action_for($rest_method)
34 || $controller->can($rest_method) ) {
35
36 return $self->_dispatch_rest_method( $c, $rest_method );
37 }
38
39 return super();
40};
41
42__PACKAGE__->meta->make_immutable;
43
441;