Integrate REST::ForBrowsers. Update docs to point at traits. Update tests to test...
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Request / REST.pm
1 package Catalyst::Request::REST;
2 use Moose;
3
4 use Catalyst::Utils;
5 use namespace::autoclean;
6
7 extends 'Catalyst::Request';
8 with 'Catalyst::TraitFor::Request::REST';
9
10 # Please don't take this as a recommended way to do things.
11 # The code below is grotty, badly factored and mostly here for back
12 # compat..
13 sub _insert_self_into {
14   my ($class, $app_class ) = @_;
15   # the fallback to $app_class is for the (rare and deprecated) case when
16   # people are defining actions in MyApp.pm instead of in a controller.
17   my $app = (blessed($app_class) && $app_class->can('_application'))
18         ? $app_class->_application : Catalyst::Utils::class2appclass( $app_class ) || $app_class;
19
20   my $req_class = $app->request_class;
21   return if $req_class->isa($class);
22   my $req_class_meta = Moose->init_meta( for_class => $req_class );
23   return if $req_class_meta->does_role('Catalyst::TraitFor::Request::REST');
24   if ($req_class eq 'Catalyst::Request') {
25     $app->request_class($class);
26   }
27   else {
28       my $meta = Moose::Meta::Class->create_anon_class(
29           superclasses => [$req_class],
30           roles => ['Catalyst::TraitFor::Request::REST'],
31           cache => 1
32       );
33       $meta->add_method(meta => sub { $meta });
34       $app->request_class($meta->name);
35   }
36 }
37
38 __PACKAGE__->meta->make_immutable;
39 __END__
40
41 =head1 NAME
42
43 Catalyst::Request::REST - A REST-y subclass of Catalyst::Request
44
45 =head1 SYNOPSIS
46
47      if ( $c->request->accepts('application/json') ) {
48          ...
49      }
50
51      my $types = $c->request->accepted_content_types();
52
53 =head1 DESCRIPTION
54
55 This is a subclass of C<Catalyst::Request> that applies the
56 L<Catalyst::TraitFor::Request::REST> role to your request class. That trait
57 adds a few methods to the request object to faciliate writing REST-y code.
58
59 This class is only here for backwards compatibility with applications already
60 subclassing this class. New code should use
61 L<Catalyst::TraitFor::Request::REST> directly.
62
63 L<Catalyst::Action::REST> and L<Catalyst::Controller::REST> will arrange
64 for the request trait to be applied if needed.
65
66 =head1 SEE ALSO
67
68 L<Catalyst::TraitFor::Request::REST>.
69
70 =head1 AUTHORS
71
72 See L<Catalyst::Action::REST> for authors.
73
74 =head1 LICENSE
75
76 You may distribute this code under the same terms as Perl itself.
77
78 =cut