forked from plack/Stream-Buffered
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signal success on buffer writing with PerlIO
As explained in GH#4, Catalyst is using the return value of the ->print call. This fails if the chunk is a falsy string. This patch makes the return value consistent with the File backend. Address plack#4
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ sub new { | |
sub print { | ||
my $self = shift; | ||
$self->{buffer} .= "@_"; | ||
return 1; | ||
} | ||
|
||
sub size { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
use Stream::Buffered; | ||
|
||
{ | ||
local $Stream::Buffered::MaxMemoryBufferSize = -1; | ||
my $b = Stream::Buffered->new; | ||
ok $b->print(0), "Writing returns true with PerlIO"; | ||
_is_zero($b); | ||
} | ||
|
||
{ | ||
local $Stream::Buffered::MaxMemoryBufferSize = 0; | ||
my $b = Stream::Buffered->new; | ||
ok $b->print(0), "Writing returns true with temp file"; | ||
_is_zero($b); | ||
} | ||
|
||
{ | ||
# auto | ||
my $b = Stream::Buffered->new; | ||
ok $b->print(0), "Writing returns true with auto"; | ||
_is_zero($b); | ||
} | ||
|
||
{ | ||
# auto with max | ||
local $Stream::Buffered::MaxMemoryBufferSize = 3; | ||
my $b = Stream::Buffered->new; | ||
for (1..4) { | ||
ok $b->print(0), "Writing returns true with auto"; | ||
} | ||
my $fh = $b->rewind; | ||
is do { local $/; <$fh> }, '0' x 4, "Buffer content OK"; | ||
} | ||
|
||
|
||
|
||
sub _is_zero { | ||
my $b = shift; | ||
my $fh = $b->rewind; | ||
is do { local $/; <$fh> }, '0', "Buffer content is zero"; | ||
} | ||
|
||
done_testing; |