4 # Test case to check that we now send scalar and filehandle like
5 # bodys directly to the PSGI engine, rather than call $writer->write
6 # or unroll the filehandle ourselves.
9 package MyApp::Controller::User;
11 use base 'Catalyst::Controller';
20 sub get_user :Chained(/) PathPrefix CaptureArgs(0)
22 pop->stash(user=>\%user);
25 sub show :GET Chained(get_user) PathPart('') Args(0) {
27 my $user = $c->stash->{user};
29 'application/json' => sub { encode_json $user },
30 'text/html' => sub { "<p>Hi I'm $user->{name} and my age is $user->{age}</p>" }
34 sub post_user :POST Chained(root) PathPart('') Args(0) Consumes(HTMLForm,JSON)
37 %user = (%user, %{$c->req->body_data});
39 $c->res->location($c->uri_for( $self->action_for('show')));
42 $INC{'MyApp/Controller/User.pm'} = '1';
47 use HTTP::Headers::ActionPack;
49 my $cn = HTTP::Headers::ActionPack->new
50 ->get_content_negotiator;
52 sub Catalyst::Response::format
56 my @formats = keys %formats;
58 my $accept = $self->_context->req->header('Accept') ||
62 $self->headers->header('Vary' => 'Accept');
63 $self->headers->header('Accepts' => (join ',', @formats));
65 if(my $which = $cn->choose_media_type(\@formats, $accept)) {
66 $self->content_type($which);
67 if(my $possible_body = $formats{$which}->($self)) {
68 $self->body($possible_body) unless $self->has_body || $self->has_write_fh;
72 $self->body("Method Not Acceptable");
84 use HTTP::Request::Common;
85 use Catalyst::Test 'MyApp';
87 ok my($res, $c) = ctx_request('/');
92 Dwarn(MyApp->dispatcher);