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