| 1 | #!perl | ||
| 2 | |||
| 3 | # ########################################################################## # | ||
| 4 | # Title: Data stream importer factory | ||
| 5 | # Creation date: 2007-03-05 | ||
| 6 | # Author: Michael Zedeler | ||
| 7 | # Description: | ||
| 8 | # File: $Source: /data/cvs/lib/DSlib/lib/DS/Importer/Factory.pm,v $ | ||
| 9 | # Repository: kronhjorten | ||
| 10 | # State: $State: Exp $ | ||
| 11 | # Documentation: inline | ||
| 12 | # Recepient: - | ||
| 13 | # #TODO Importers should not by default be constructed with an explicit typespec, since this may be derived from the data source | ||
| 14 | # ########################################################################## # | ||
| 15 | |||
| 16 | package DS::Importer::Factory; | ||
| 17 | |||
| 18 | use base qw{ DS }; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use Carp::Assert; | ||
| 22 | |||
| 23 | our ($VERSION) = $DS::VERSION; | ||
| 24 | our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/; | ||
| 25 | |||
| 26 | require DS::Transformer; | ||
| 27 | require DS::Importer::Hash; | ||
| 28 | require DS::Importer::Sub; | ||
| 29 | require DS::Importer::TabStream; | ||
| 30 | require DS::Importer::Sth; | ||
| 31 | |||
| 32 | |||
| 33 | sub factory { | ||
| 34 | my($class, $data_source) = @_; | ||
| 35 | |||
| 36 | if(ref($data_source) eq 'HASH') { | ||
| 37 | return new DS::Importer::Hash(@_); | ||
| 38 | } elsif(ref($data_source) eq 'CODE') { | ||
| 39 | return new DS::Importer::Sub( @_ ); | ||
| 40 | } elsif($data_source->isa('IO::handle')) { | ||
| 41 | return new DS::Importer::TabStream( @_ ); | ||
| 42 | } elsif($data_source->isa('DBI::st')) { | ||
| 43 | return new DS::Importer::Sth( @_ ); | ||
| 44 | } | ||
| 45 | # TODO This wouldn't work: Needs some kind of IOC-component. A subclass of Transformer::Buffer could do the trick. | ||
| 46 | # elsif($data_source->isa('DS::Source')) { | ||
| 47 | # return new DS::Transformer( @_ ); | ||
| 48 | # } | ||
| 49 | |||
| 50 | return; | ||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | 1; |