08c7c6547a0d679d39c5798f09af3521543c5c02
[catagits/Catalyst-Runtime.git] / t / lib / TestApp / Controller / Action / Streaming.pm
1 package TestApp::Controller::Action::Streaming;
2
3 use strict;
4 use base 'TestApp::Controller::Action';
5
6 sub streaming : Global {
7     my ( $self, $c ) = @_;
8     for my $line ( split "\n", <<'EOF' ) {
9 foo
10 bar
11 baz
12 EOF
13         $c->res->write("$line\n");
14     }
15 }
16
17 sub body : Local {
18     my ( $self, $c ) = @_;
19
20     my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
21     my $fh = IO::File->new( $file, 'r' );
22     if ( defined $fh ) {
23         $c->res->body( $fh );
24     }
25     else {
26         $c->res->body( "Unable to read $file" );
27     }
28 }
29
30 sub body_large : Local {
31     my ($self, $c) = @_;
32
33     # more than one write with the default chunksize
34     my $size = 128 * 1024;
35
36     my $data = "\0" x $size;
37     open my $fh, '<', \$data;
38     $c->res->content_length($size);
39     $c->res->body($fh);
40 }
41
42 1;