pax_global_header00006660000000000000000000000064120321612720014506gustar00rootroot0000000000000052 comment=985f03d682903ec51e102ba0a674fe79cb3a868a perl-Stream-Buffered-0.02/000075500000000000000000000000001203216127200153405ustar00rootroot00000000000000perl-Stream-Buffered-0.02/.gitignore000064400000000000000000000001021203216127200173210ustar00rootroot00000000000000META.yml Makefile inc/ pm_to_blib blib *~ .* !.gitignore !.shipit perl-Stream-Buffered-0.02/.shipit000064400000000000000000000001711203216127200166400ustar00rootroot00000000000000steps = FindVersion, ChangeAllVersions, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN git.push_to = origin perl-Stream-Buffered-0.02/Changes000064400000000000000000000002501203216127200166300ustar00rootroot000000000000000.02 Sun Sep 30 19:24:00 CST 2012 - fix subclassing (so that Plack::TempBuffer continues to work) 0.01 Sun Sep 30 15:44:11 CST 2012 - original version perl-Stream-Buffered-0.02/Makefile.PL000064400000000000000000000007551203216127200173210ustar00rootroot00000000000000# install Module::Install Module::Install::AuthorTests Module::Install::ReadmeFromPod Module::Install::Repository sub author_tests { } sub readme_from { } sub auto_set_repository { } use inc::Module::Install; name 'Stream-Buffered'; all_from 'lib/Stream/Buffered.pm'; readme_from 'lib/Stream/Buffered.pm'; tests 't/*.t'; author_tests 'xt'; auto_set_repository; resources homepage => "http://plackperl.org", bugtracker => "https://github.com/plack/Plack/issues"; WriteAll; perl-Stream-Buffered-0.02/lib/000075500000000000000000000000001203216127200161065ustar00rootroot00000000000000perl-Stream-Buffered-0.02/lib/Stream/000075500000000000000000000000001203216127200173415ustar00rootroot00000000000000perl-Stream-Buffered-0.02/lib/Stream/Buffered.pm000064400000000000000000000035321203216127200214240ustar00rootroot00000000000000package Stream::Buffered; use strict; use warnings; use FileHandle; # for seek etc. use Stream::Buffered::Auto; use Stream::Buffered::File; use Stream::Buffered::PerlIO; our $VERSION = 0.02; our $MaxMemoryBufferSize = 1024 * 1024; sub new { my($class, $length) = @_; # $MaxMemoryBufferSize = 0 -> Always temp file # $MaxMemoryBufferSize = -1 -> Always PerlIO my $backend; if ($MaxMemoryBufferSize < 0) { $backend = "PerlIO"; } elsif ($MaxMemoryBufferSize == 0) { $backend = "File"; } elsif (!$length) { $backend = "Auto"; } elsif ($length > $MaxMemoryBufferSize) { $backend = "File"; } else { $backend = "PerlIO"; } $class->create($backend, $length, $MaxMemoryBufferSize); } sub create { my($class, $backend, $length, $max) = @_; (__PACKAGE__ . "::$backend")->new($length, $max); } sub print; sub rewind; sub size; 1; __END__ =head1 NAME Stream::Buffered - temporary buffer to save bytes =head1 SYNOPSIS my $buf = Stream::Buffered->new($length); $buf->print($bytes); my $size = $buf->size; my $fh = $buf->rewind; =head1 DESCRIPTION Stream::Buffered is a buffer class to store arbitrary length of byte strings and then get a seekable filehandle once everything is buffered. It uses PerlIO and/or temporary file to save the buffer depending on the length of the size. =head1 SEE ALSO L =head1 AUTHOR Tatsuhiko Miyagawa This module is part of L, released as a separate distribution for easier reuse. =head1 COPYRIGHT The following copyright notice applies to all the files provided in this distribution, including binary files, unless explicitly noted otherwise. Copyright 2009-2011 Tatsuhiko Miyagawa =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut perl-Stream-Buffered-0.02/lib/Stream/Buffered/000075500000000000000000000000001203216127200210635ustar00rootroot00000000000000perl-Stream-Buffered-0.02/lib/Stream/Buffered/Auto.pm000064400000000000000000000013161203216127200223320ustar00rootroot00000000000000package Stream::Buffered::Auto; use strict; use warnings; use base 'Stream::Buffered'; sub new { my($class, undef, $max_memory_size) = @_; bless { _buffer => Stream::Buffered->create('PerlIO'), _max => $max_memory_size, }, $class; } sub print { my $self = shift; $self->{_buffer}->print(@_); if ($self->{_max} && $self->{_buffer}->size > $self->{_max}) { my $buf = $self->{_buffer}->{buffer}; $self->{_buffer} = Stream::Buffered->create('File'), $self->{_buffer}->print($buf); delete $self->{_max}; } } sub size { my $self = shift; $self->{_buffer}->size; } sub rewind { my $self = shift; $self->{_buffer}->rewind; } 1; perl-Stream-Buffered-0.02/lib/Stream/Buffered/File.pm000064400000000000000000000007141203216127200223020ustar00rootroot00000000000000package Stream::Buffered::File; use strict; use warnings; use base 'Stream::Buffered'; use IO::File; sub new { my $class = shift; my $fh = IO::File->new_tmpfile; $fh->binmode; bless { fh => $fh }, $class; } sub print { my $self = shift; $self->{fh}->print(@_); } sub size { my $self = shift; $self->{fh}->flush; -s $self->{fh}; } sub rewind { my $self = shift; $self->{fh}->seek(0, 0); $self->{fh}; } 1; perl-Stream-Buffered-0.02/lib/Stream/Buffered/PerlIO.pm000064400000000000000000000007721203216127200225610ustar00rootroot00000000000000package Stream::Buffered::PerlIO; use strict; use warnings; use base 'Stream::Buffered'; sub new { my $class = shift; bless { buffer => '' }, $class; } sub print { my $self = shift; $self->{buffer} .= "@_"; } sub size { my $self = shift; length $self->{buffer}; } sub rewind { my $self = shift; my $buffer = $self->{buffer}; open my $io, "<", \$buffer; bless $io, 'FileHandle'; # This makes $io work as FileHandle under 5.8, .10 and .11 :/ return $io; } 1; perl-Stream-Buffered-0.02/t/000075500000000000000000000000001203216127200156035ustar00rootroot00000000000000perl-Stream-Buffered-0.02/t/print.t000064400000000000000000000014001203216127200171170ustar00rootroot00000000000000#!/usr/bin/env perl use strict; use warnings; use Test::More; use Stream::Buffered; { my $b = Stream::Buffered->new(-1); $b->print("foo"); is $b->size, 3; my $fh = $b->rewind; is do { local $/; <$fh> }, 'foo'; $fh->seek(0, 0); } { local $Stream::Buffered::MaxMemoryBufferSize = 12; my $b = Stream::Buffered->new; is $b->size, 0; $b->print("foo") for 1..5; is $b->size, 15; my $fh = $b->rewind; isa_ok $fh, 'IO::File'; is do { local $/; <$fh> }, ('foo' x 5); } { local $Stream::Buffered::MaxMemoryBufferSize = 0; my $b = Stream::Buffered->new(3); $b->print("foo\n"); is $b->size, 4; my $fh = $b->rewind; isa_ok $fh, 'IO::File'; is do { local $/; <$fh> }, "foo\n"; } done_testing; perl-Stream-Buffered-0.02/t/subclass.t000064400000000000000000000015011203216127200176040ustar00rootroot00000000000000#!/usr/bin/env perl use strict; use warnings; use Test::More; { package Stream::Buffered::Sub; use base 'Stream::Buffered'; } { my $b = Stream::Buffered::Sub->new(-1); $b->print("foo"); is $b->size, 3; my $fh = $b->rewind; is do { local $/; <$fh> }, 'foo'; $fh->seek(0, 0); } { local $Stream::Buffered::MaxMemoryBufferSize = 12; my $b = Stream::Buffered::Sub->new; is $b->size, 0; $b->print("foo") for 1..5; is $b->size, 15; my $fh = $b->rewind; isa_ok $fh, 'IO::File'; is do { local $/; <$fh> }, ('foo' x 5); } { local $Stream::Buffered::MaxMemoryBufferSize = 0; my $b = Stream::Buffered::Sub->new(3); $b->print("foo\n"); is $b->size, 4; my $fh = $b->rewind; isa_ok $fh, 'IO::File'; is do { local $/; <$fh> }, "foo\n"; } done_testing;