Subject: | passing anonymous or File::Temp filehandle results in empty file. |
in my perl code i have a string with the content that i want to pass to DBIC::IC::FS.
if I get a anonymous fh to a temp array or if I use File::Temp the resulting file that is created by DBIC::IC::FS is empty.
here are 2 failing tests describing the issue.
Subject: | 20-scalar_fh.t |
#!perl
use warnings;
use strict;
use DBICx::TestDatabase;
use Test::More tests => 2;
use lib qw(t/lib);
my $schema = DBICx::TestDatabase->new('My::TestSchema');
my $rs = $schema->resultset('Book');
# we'll use a filehandle to a scalar as our content
my $string = "moo\nmee\nmaa";
open( my $string_fh, '<', \$string) or die "Could not open for reading.";
my $book = $rs->create({
name => 'Alice in Wonderland',
cover_image => $string_fh,
});
isa_ok( $book->cover_image, 'Path::Class::File' );
my $fh = $book->cover_image->open('r');
my @lines = <$fh>;
is( scalar @lines, 3, 'file has 3 lines' );
Subject: | 21-temp_file.t |
#!perl
use warnings;
use strict;
use DBICx::TestDatabase;
use Test::More tests => 2;
use File::Temp;
use lib qw(t/lib);
my $schema = DBICx::TestDatabase->new('My::TestSchema');
my $rs = $schema->resultset('Book');
# we'll use a temp file handle as our content
my $string = "moo\nmee\nmaa";
my $tmp_fh = File::Temp->new( UNLINK => 1 );
print $tmp_fh $string;
# test passes when the next two lines are executed
#$tmp_fh->close;
#open ($tmp_fh, "<", "$tmp_fh") or die "Cant open for reading: $!";
my $book = $rs->create({
name => 'Alice in Wonderland',
cover_image => $tmp_fh,
});
isa_ok( $book->cover_image, 'Path::Class::File' );
my $fh = $book->cover_image->open('r');
my @lines = <$fh>;
is( scalar @lines, 3, 'file has 3 lines' );