DS::Importer - component that retrieves data from outside DS and passes it


DSlib documentation Contained in the DSlib distribution.

Index


Code Index:

NAME

Top

DS::Importer - component that retrieves data from outside DS and passes it down a processing chain.

DESCRIPTION

Top

This is the base class of any component that is supposed to retrieve data from outside a processing chain and pass it on as rows. The name refers to a component that imports data into a chain.

SUPER CLASSES

Top

DS::Source

METHODS

Top

execute( $num_rows )

Will call fetch pass the results on by calling pass_row with the result, stopping after fetching $num_rows or passing on end of stream (whichever comes first).

fetch

This method is supposed to retrieve a row from the underlying data source and return it. Must return undef to indicate end of stream. Multiple calls after end of stream should still result in returning undef.

new( $class, $out_type, $target )

Constructor. Instantiates an object of class $class, returning the type $out_type, attaced to the target $target. Besides $class, any of the parameters can be left out.

INHERITED METHODS

Methods inherited from DS::Source:

attach_target( $target )
target( $target )
pass_row( $row )
out_type( $type )

SEE ALSO

Top

DS::Importer, DS::Transformer, DS::Target.

AUTHOR

Top

Written by Michael Zedeler.


DSlib documentation Contained in the DSlib distribution.

#!perl

# ########################################################################## #
# Title:         Data stream importer
# Creation date: 2007-03-05
# Author:        Michael Zedeler
# Description:   Generates data stream data
#                Data Stream class
# File:          $Source: /data/cvs/lib/DSlib/lib/DS/Importer.pm,v $
# Repository:    kronhjorten
# State:         $State: Exp $
# Documentation: inline
# Recepient:     -
# #TODO Importers should not by default be constructed with an explicit typespec, since this may be derived from the data source
# ########################################################################## #

package DS::Importer;

use base qw{ DS::Source };

use strict;
use Carp qw{ croak cluck };
require Carp::Assert;

our ($VERSION) = $DS::VERSION;
our ($REVISION) = '$Revision: 1.2 $' =~ /(\d+\.\d+)/;

#TODO Add $row to to constructor

# This method fetches 
sub execute {
    my( $self, $rows ) = @_;
    $rows = -1 unless $rows;
    while( $rows-- != 0 ) {
        my $result = $self->_fetch();
        $self->pass_row( $result );
        # Exit if we just passed end of stream.
        last if not defined( $result );
    }
}

# Fetches one row from underlying data source and returns it to caller.
# When end of data source has been reached, this method MUST return undef on
# all subsequent calls.
# Note that this method doesn't pass anything on to any attached
# target.
# When writing importers, this is the method you will want to override.
# This method is private.
sub _fetch {
    croak("This method must be overridden.");
}

1;

__END__