IO-Callback
view release on metacpan or search on metacpan
t/error-handling.t view on Meta::CPAN
"truncate croaks";
is_deeply [stat $fh], [], "stat returns empty list";
my $stat = stat $fh;
ok !$stat, "stat returns false in a scalar context";
# getline/getlines should fail if there's a read error before the first eol
my @readcode = (
'$ret = <$fh>',
'local $/; $ret = <$fh>',
'local $/=""; $ret = <$fh>',
'($ret) = <$fh>',
'local $/; ($ret) = <$fh>',
'local $/=""; ($ret) = <$fh>',
);
foreach my $readcode (@readcode) {
my $block = "x" x 10240;
my @ret = ($block, $block, $block, IO::Callback::Error, $block, $block);
my $fh = IO::Callback->new('<', sub { shift @{$_[0]} }, \@ret);
my $ret;
eval $readcode; die $@ if $@;
ok ! defined $ret, "getline(s) ($readcode) failed on error";
t/iostring-para.t view on Meta::CPAN
c
a
b
c
d
EOT
$/ = "";
is(<$fh>, "a\n\n");
is(<$fh>, "a\nb\n\n");
is(<$fh>, "a\nb\nc\n\n");
is(<$fh>, "a\nb\nc\nd\n");
is(<$fh>, undef);
reset_test(<<EOT);
a
b
t/iostring-read.t view on Meta::CPAN
reset_test();
@lines = $io->getlines;
is_deeply( \@lines, [$str], "slurp got whole string" );
reset_test(index($str, "and"));
my $line = <$io>;
is( $line, "and a single line.\n\n", "slurp 2nd part of string" );
}
{
local $/ = ""; # paragraph mode
reset_test();
@lines = <$io>;
is_deeply( \@lines, ["This is an example\nof a paragraph\n\n", "and a single line.\n\n"], "para mode" );
}
{
local $/ = "is";
reset_test();
@lines = ();
while (<$io>) {
t/read-variations.inc view on Meta::CPAN
'$_ = $fh->getline; return unless defined; $$dest .= $_',
'$$dest .= join "", <$fh>; return',
'$$dest .= join "", $fh->getlines; return',
);
@readcode = map( { {SrcCode => $_} }
@linewise_readcode,
map ({'local $/; '.$_} @linewise_readcode),
map ({'local $/="oo"; '.$_} @linewise_readcode),
'$_ = $fh->getc; return unless defined; $$dest .= $_',
);
push @readcode, map { {SrcCode => "local \$/=''; $_", ParaMode => 1} } @linewise_readcode;
}
my $readcall_template = <<'ENDCODE';
my $got = __READCALL__;
unless (defined $got) {
$$dest = "*** FAIL: __READ__ returned undef ***";
return;
}
$got or return;
$$dest .= $_;
( run in 0.442 second using v1.01-cache-2.11-cpan-49f99fa48dc )