CGI-Application-Plugin-Stream

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

    requires => {
        'Test::More'        =>  0,
        'File::Basename'	=>	1.0,
        'CGI::Application'	=>	3.21,
        'File::MMagic'      =>  0,
        'FileHandle'        =>  1.22,
    },
    create_makefile_pl => 'traditional',
    create_readme => 1,
    dist_author => 'Jason Purdy <Jason@Purdy.INFO>',
    dist_abstract => 'Plugin that adds file streaming support to CGI::Application',
)->create_build_script;

META.json  view on Meta::CPAN

{
   "abstract" : "Plugin that adds file streaming support to CGI::Application",
   "author" : [
      "Jason Purdy <Jason@Purdy.INFO>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "Module::Build version 0.421",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Plugin that adds file streaming support to CGI::Application'
author:
  - 'Jason Purdy <Jason@Purdy.INFO>'
build_requires: {}
configure_requires:
  Module::Build: '0.42'
dynamic_config: 1
generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.142690'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

README  view on Meta::CPAN

NAME
    CGI::Application::Plugin::Stream - CGI::Application Plugin for streaming
    files

SYNOPSIS
      use CGI::Application::Plugin::Stream (qw/stream_file/);

      sub runmode {
        # ...

        # Set up any headers you want to set explicitly
        # using header_props() or header_add() as usual

README  view on Meta::CPAN


    The file is read and printed in small chunks to keep memory consumption
    down.

    This plugin is a consumer, as in your runmode shouldn't try to do any
    output or anything afterwards. This plugin affects the HTTP response
    headers, so anything you do afterwards will probably not work. If you
    pass along a filehandle, we'll make sure to close it for you.

    It's recommended that you increment $| (or set it to 1), which will
    autoflush the buffer as your application is streaming out the file.

METHODS
  stream_file()
      $self->stream_file($fh);
      $self->stream_file( '/path/to/file',2048);

    This method can take two parameters, the first the path to the file or a
    filehandle and the second, an optional number of bytes to determine the
    chunk size of the stream. It defaults to 1024.

lib/CGI/Application/Plugin/Stream.pm  view on Meta::CPAN


    print '' unless $ENV{'CGI_APP_RETURN_ONLY'}; # print a null string at the end
    close ( $fh );
    return $ENV{'CGI_APP_RETURN_ONLY'} ? \$output : 1;
}

1;
__END__
=head1 NAME

CGI::Application::Plugin::Stream - CGI::Application Plugin for streaming files

=head1 SYNOPSIS

  use CGI::Application::Plugin::Stream (qw/stream_file/);

  sub runmode {
    # ...

    # Set up any headers you want to set explicitly
    # using header_props() or header_add() as usual

lib/CGI/Application/Plugin/Stream.pm  view on Meta::CPAN

deliver to the user.

The file is read and printed in small chunks to keep memory consumption down.

This plugin is a consumer, as in your runmode shouldn't try to do any output or
anything afterwards.  This plugin affects the HTTP response headers, so
anything you do afterwards will probably not work.  If you pass along a
filehandle, we'll make sure to close it for you.

It's recommended that you increment $| (or set it to 1), which will
autoflush the buffer as your application is streaming out the file.

=head1 METHODS

=head2 stream_file()

  $self->stream_file($fh);
  $self->stream_file( '/path/to/file',2048);

This method can take two parameters, the first the path to the file
or a filehandle and the second, an optional number of bytes to determine

t/01-basic.t  view on Meta::CPAN

  use_ok('CGI::Application::Plugin::Stream');

  unshift @INC, 't/lib';
}

use strict;
use TieOut;



# Useless here, since the point is to test streaming directly.
#$ENV{CGI_APP_RETURN_ONLY} = 1;

#####


my $stdout = tie *STDOUT, 'TieOut' or die;
my ($content_sent, $test_name);

##############



( run in 0.272 second using v1.01-cache-2.11-cpan-a5abf4f5562 )