Browse files

file handling fixes. It actually works now =D

  • Loading branch information...
1 parent 381e881 commit 01df9fe2ede50b1178097d7f4c4f50404271fb3c @garu committed Jul 9, 2011
Showing with 9 additions and 8 deletions.
  1. +9 −8 lib/DataFlow/Proc/DBF.pm
View
17 lib/DataFlow/Proc/DBF.pm
@@ -12,6 +12,7 @@ extends 'DataFlow::Proc::Converter';
use XBase;
use File::Temp qw(:seekable);
use File::Spec ();
+use autodie;
use namespace::autoclean;
has '+converter' => (
@@ -58,7 +59,7 @@ sub _build_subs {
return {
'CONVERT_TO' => sub {
my $data = $_;
- my $dir = File::Temp->newdir();
+ my $dir = File::Temp->newdir( CLEANUP => 1 );
my $filename = File::Spec->catfile($dir, 'tmp.dbf');
# header is mandatory, so we either
@@ -71,7 +72,7 @@ sub _build_subs {
}
else {
push @$field_names, "item$_"
- foreach ( 0 .. $#{$data} );
+ foreach ( 0 .. $#{ $data->[0] } );
}
my $table = $self->converter->create(
@@ -97,7 +98,6 @@ sub _build_subs {
'CONVERT_FROM' => sub {
my $string = $_;
-
my $options = $self->has_converter_opts
? $self->converter_opts : {}
;
@@ -109,17 +109,18 @@ sub _build_subs {
# assume the DBF is in a binary string
# (the "flow") and make our interface with
# XBase using a temp file
+ my $fh;
unless (exists $options->{'name'} or exists $options->{'fh'}) {
- my $fh = File::Temp->new( UNLINK => 1 );
+ $fh = File::Temp->new( UNLINK => 1 );
binmode $fh;
print $fh $string;
- $fh->seek(0, SEEK_SET);
+ close $fh;
- $options->{name} = '-';
- $options->{fh} = $fh;
+ $options->{name} = $fh->filename;
}
- $dbf = $self->converter->open( %$options )
+ $dbf = $self->converter;
+ $dbf->open( %$options )
or die XBase->errstr;
my $records = $dbf->get_all_records;

0 comments on commit 01df9fe

Please sign in to comment.