| 1 | #!perl | ||
| 2 | |||
| 3 | # ########################################################################## # | ||
| 4 | # Title: Tabular file to datastream importer | ||
| 5 | # Creation date: 2007-03-05 | ||
| 6 | # Author: Michael Zedeler | ||
| 7 | # Description: Produces a datastream from a tab separated file (filename) | ||
| 8 | # Data Stream class | ||
| 9 | # Data importer | ||
| 10 | # File: $Source: /data/cvs/lib/DSlib/lib/DS/Importer/TabFile.pm,v $ | ||
| 11 | # Repository: kronhjorten | ||
| 12 | # State: $State: Exp $ | ||
| 13 | # Documentation: inline | ||
| 14 | # Recepient: - | ||
| 15 | # ########################################################################## # | ||
| 16 | |||
| 17 | package DS::Importer::TabFile; | ||
| 18 | |||
| 19 | use base qw{ DS::Importer::TabStream }; | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use Carp::Assert; | ||
| 23 | use IO::File; | ||
| 24 | |||
| 25 | our ($VERSION) = $DS::VERSION; | ||
| 26 | our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/; | ||
| 27 | |||
| 28 | sub new { | ||
| 29 | my( $class, $filename, $target, $typespec, $row ) = @_; | ||
| 30 | |||
| 31 | my $self = undef; | ||
| 32 | |||
| 33 | assert(ref($filename) eq ''); | ||
| 34 | |||
| 35 | if( my $fh = new IO::File ) { | ||
| 36 | if( $fh->open($filename) ) { | ||
| 37 | $self = $class->SUPER::new( $fh, $target, $typespec, $row ); | ||
| 38 | $self->{filename} = $filename; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return $self; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub _fetch { | ||
| 46 | my($self) = @_; | ||
| 47 | |||
| 48 | my $result = $self->SUPER::_fetch(); | ||
| 49 | |||
| 50 | $self->{fh}->close() unless $result; | ||
| 51 | |||
| 52 | return $result; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; |