Version 0.99
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Request / REST.pm
CommitLineData
256c894f 1package Catalyst::Request::REST;
930013e6 2use Moose;
37694e6c 3
4use Catalyst::Utils;
f168fa3e 5use namespace::autoclean;
6
7extends 'Catalyst::Request';
e623bdf2 8with 'Catalyst::TraitFor::Request::REST';
f168fa3e 9
3ed677b1 10our $VERSION = '0.99';
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 16sub _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 );
bc06b9a3 26 my $role = $class->_related_role;
83273f94 27 return if $req_class_meta->does_role($role);
f560e0ae 28 if ($req_class eq 'Catalyst::Request') {
29 $app->request_class($class);
30 }
31 else {
32 my $meta = Moose::Meta::Class->create_anon_class(
33 superclasses => [$req_class],
83273f94 34 roles => [$role],
f560e0ae 35 cache => 1
36 );
d54b6460 37 $meta->_add_meta_method('meta');
f560e0ae 38 $app->request_class($meta->name);
39 }
5132f5e4 40}
256c894f 41
83273f94 42sub _related_role { 'Catalyst::TraitFor::Request::REST' }
43
f168fa3e 44__PACKAGE__->meta->make_immutable;
1212cee0 45
461;
47
f168fa3e 48__END__
49
9a76221e 50=head1 NAME
51
52Catalyst::Request::REST - A REST-y subclass of Catalyst::Request
53
54=head1 SYNOPSIS
55
d6fb033c 56 if ( $c->request->accepts('application/json') ) {
9a76221e 57 ...
58 }
59
60 my $types = $c->request->accepted_content_types();
61
62=head1 DESCRIPTION
63
38e05ec4 64This is a subclass of C<Catalyst::Request> that applies the
85aa4e18 65L<Catalyst::TraitFor::Request::REST> role to your request class. That trait
d6ece98c 66adds a few methods to the request object to facilitate writing REST-y code.
9a76221e 67
85aa4e18 68This class is only here for backwards compatibility with applications already
69subclassing this class. New code should use
70L<Catalyst::TraitFor::Request::REST> directly.
9a76221e 71
38e05ec4 72L<Catalyst::Action::REST> and L<Catalyst::Controller::REST> will arrange
73for the request trait to be applied if needed.
9a76221e 74
38e05ec4 75=head1 SEE ALSO
9a76221e 76
38e05ec4 77L<Catalyst::TraitFor::Request::REST>.
fec6d454 78
6e6e0bf9 79=head1 AUTHORS
9a76221e 80
6e6e0bf9 81See L<Catalyst::Action::REST> for authors.
fec6d454 82
9a76221e 83=head1 LICENSE
84
85You may distribute this code under the same terms as Perl itself.
86
87=cut