| 1 | #!perl | ||||||||||
| 2 | |||||||||||
| 3 | # ########################################################################## # | ||||||||||
| 4 | # Title: Data stream importer | ||||||||||
| 5 | # Creation date: 2007-03-05 | ||||||||||
| 6 | # Author: Michael Zedeler | ||||||||||
| 7 | # Description: Generates data stream data | ||||||||||
| 8 | # Data Stream class | ||||||||||
| 9 | # File: $Source: /data/cvs/lib/DSlib/lib/DS/Importer.pm,v $ | ||||||||||
| 10 | # Repository: kronhjorten | ||||||||||
| 11 | # State: $State: Exp $ | ||||||||||
| 12 | # Documentation: inline | ||||||||||
| 13 | # Recepient: - | ||||||||||
| 14 | # #TODO Importers should not by default be constructed with an explicit typespec, since this may be derived from the data source | ||||||||||
| 15 | # ########################################################################## # | ||||||||||
| 16 | |||||||||||
| 17 | package DS::Importer; | ||||||||||
| 18 | |||||||||||
| 19 | 5 | ▶ | use base qw{ DS::Source }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 5 | ▶ | use Carp qw{ croak cluck }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 5 | require Carp::Assert; | |||||||||
| 24 | |||||||||||
| 25 | 5 | our ($VERSION) = $DS::VERSION; | |||||||||
| 26 | 5 | our ($REVISION) = '$Revision: 1.2 $' =~ /(\d+\.\d+)/; | |||||||||
| 27 | |||||||||||
| 28 | #TODO Add $row to to constructor | ||||||||||
| 29 | |||||||||||
| 30 | # This method fetches | ||||||||||
| 31 | 18 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 32 | 18 | my( $self, $rows ) = @_; | |||||||||
| 33 | 18 | ▶ | $rows = -1 unless $rows; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 18 | ▶ | while( $rows-- != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 63 | my $result = $self->_fetch(); | |||||||||
| 36 | 62 | $self->pass_row( $result ); | |||||||||
| 37 | # Exit if we just passed end of stream. | ||||||||||
| 38 | 61 | ▶ | last if not defined( $result ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # Fetches one row from underlying data source and returns it to caller. | ||||||||||
| 43 | # When end of data source has been reached, this method MUST return undef on | ||||||||||
| 44 | # all subsequent calls. | ||||||||||
| 45 | # Note that this method doesn't pass anything on to any attached | ||||||||||
| 46 | # target. | ||||||||||
| 47 | # When writing importers, this is the method you will want to override. | ||||||||||
| 48 | # This method is private. | ||||||||||
| 49 | 1 | ▶ | sub _fetch { | ||||||||
|
Subroutine
_fetch: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 1 | croak("This method must be overridden."); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 5 | 1; | |||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||