Add explicit 1;
[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
a9e5f3d2 10our $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 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 );
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
431;
44
f168fa3e 45__END__
46
9a76221e 47=head1 NAME
48
49Catalyst::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 61This is a subclass of C<Catalyst::Request> that applies the
85aa4e18 62L<Catalyst::TraitFor::Request::REST> role to your request class. That trait
d6ece98c 63adds a few methods to the request object to facilitate writing REST-y code.
9a76221e 64
85aa4e18 65This class is only here for backwards compatibility with applications already
66subclassing this class. New code should use
67L<Catalyst::TraitFor::Request::REST> directly.
9a76221e 68
38e05ec4 69L<Catalyst::Action::REST> and L<Catalyst::Controller::REST> will arrange
70for the request trait to be applied if needed.
9a76221e 71
38e05ec4 72=head1 SEE ALSO
9a76221e 73
38e05ec4 74L<Catalyst::TraitFor::Request::REST>.
fec6d454 75
6e6e0bf9 76=head1 AUTHORS
9a76221e 77
6e6e0bf9 78See L<Catalyst::Action::REST> for authors.
fec6d454 79
9a76221e 80=head1 LICENSE
81
82You may distribute this code under the same terms as Perl itself.
83
84=cut