Commit | Line | Data |
256c894f |
1 | package Catalyst::Request::REST; |
930013e6 |
2 | use Moose; |
37694e6c |
3 | |
4 | use Catalyst::Utils; |
f168fa3e |
5 | use namespace::autoclean; |
6 | |
7 | extends 'Catalyst::Request'; |
e623bdf2 |
8 | with 'Catalyst::TraitFor::Request::REST'; |
f168fa3e |
9 | |
0745d6eb |
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.. |
5132f5e4 |
13 | sub _insert_self_into { |
37694e6c |
14 | my ($class, $app_class ) = @_; |
27beb190 |
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. |
2998eff6 |
17 | my $app = (blessed($app_class) && $app_class->can('_application')) |
18 | ? $app_class->_application : Catalyst::Utils::class2appclass( $app_class ) || $app_class; |
37694e6c |
19 | |
5132f5e4 |
20 | my $req_class = $app->request_class; |
21 | return if $req_class->isa($class); |
149182b3 |
22 | my $req_class_meta = Moose->init_meta( for_class => $req_class ); |
23 | return if $req_class_meta->does_role('Catalyst::TraitFor::Request::REST'); |
15f4af0e |
24 | my $meta = Moose::Meta::Class->create_anon_class( |
25 | superclasses => [$req_class], |
26 | roles => ['Catalyst::TraitFor::Request::REST'], |
27 | cache => 1 |
28 | ); |
29 | $meta->add_method(meta => sub { $meta }); |
30 | $app->request_class($meta->name); |
5132f5e4 |
31 | } |
256c894f |
32 | |
f168fa3e |
33 | __PACKAGE__->meta->make_immutable; |
34 | __END__ |
35 | |
9a76221e |
36 | =head1 NAME |
37 | |
38 | Catalyst::Request::REST - A REST-y subclass of Catalyst::Request |
39 | |
40 | =head1 SYNOPSIS |
41 | |
d6fb033c |
42 | if ( $c->request->accepts('application/json') ) { |
9a76221e |
43 | ... |
44 | } |
45 | |
46 | my $types = $c->request->accepted_content_types(); |
47 | |
48 | =head1 DESCRIPTION |
49 | |
38e05ec4 |
50 | This is a subclass of C<Catalyst::Request> that applies the |
85aa4e18 |
51 | L<Catalyst::TraitFor::Request::REST> role to your request class. That trait |
52 | adds a few methods to the request object to faciliate writing REST-y code. |
9a76221e |
53 | |
85aa4e18 |
54 | This class is only here for backwards compatibility with applications already |
55 | subclassing this class. New code should use |
56 | L<Catalyst::TraitFor::Request::REST> directly. |
9a76221e |
57 | |
38e05ec4 |
58 | L<Catalyst::Action::REST> and L<Catalyst::Controller::REST> will arrange |
59 | for the request trait to be applied if needed. |
9a76221e |
60 | |
38e05ec4 |
61 | =head1 SEE ALSO |
9a76221e |
62 | |
38e05ec4 |
63 | L<Catalyst::TraitFor::Request::REST>. |
fec6d454 |
64 | |
6e6e0bf9 |
65 | =head1 AUTHORS |
9a76221e |
66 | |
6e6e0bf9 |
67 | See L<Catalyst::Action::REST> for authors. |
fec6d454 |
68 | |
9a76221e |
69 | =head1 LICENSE |
70 | |
71 | You may distribute this code under the same terms as Perl itself. |
72 | |
73 | =cut |