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