File: Streaming.pm

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (55 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package TestApp::Controller::Action::Streaming;

use strict;
use base 'TestApp::Controller::Action';

sub streaming : Global {
    my ( $self, $c ) = @_;
    for my $line ( split "\n", <<'EOF' ) {
foo
bar
baz
EOF
        $c->res->write("$line\n");
    }
}

sub body : Local {
    my ( $self, $c ) = @_;

    my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
    my $fh = IO::File->new( $file, 'r' );
    if ( defined $fh ) {
        $c->res->body( $fh );
    }
    else {
        $c->res->body( "Unable to read $file" );
    }
}

sub body_glob : Local {
    my ( $self, $c ) = @_;

    my $file = "$FindBin::Bin/../lib/TestApp/Controller/Action/Streaming.pm";
    open my $fh, '<', $file;
    if ( defined $fh ) {
        $c->res->body( $fh );
    }
    else {
        $c->res->body( "Unable to read $file" );
    }
}

sub body_large : Local {
    my ($self, $c) = @_;

    # more than one write with the default chunksize
    my $size = 128 * 1024;

    my $data = "\0" x $size;
    open my $fh, '<', \$data;
    $c->res->content_length($size);
    $c->res->body($fh);
}

1;