| 1 | #!perl | ||||||||||
| 2 | |||||||||||
| 3 | # ########################################################################## # | ||||||||||
| 4 | # Title: Data stream generator | ||||||||||
| 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/Source.pm,v $ | ||||||||||
| 10 | # Repository: kronhjorten | ||||||||||
| 11 | # State: $State: Exp $ | ||||||||||
| 12 | # Documentation: inline | ||||||||||
| 13 | # Recepient: - | ||||||||||
| 14 | # ########################################################################## # | ||||||||||
| 15 | |||||||||||
| 16 | package DS::Source; | ||||||||||
| 17 | |||||||||||
| 18 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 10 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 10 | ▶ | use Carp::Assert; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 10 | our ($VERSION) = $DS::VERSION; | |||||||||
| 23 | 10 | our ($REVISION) = '$Revision: 1.2 $' =~ /(\d+\.\d+)/; | |||||||||
| 24 | 10 | our ($STATE) = '$State: Exp $' =~ /:\s+(.+\S)\s+\$$/; | |||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | 17 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 28 | 17 | my( $class, $out_type, $target ) = @_; | |||||||||
| 29 | |||||||||||
| 30 | 17 | my $self = { | |||||||||
| 31 | row => {} | ||||||||||
| 32 | }; | ||||||||||
| 33 | 17 | bless $self, $class; | |||||||||
| 34 | |||||||||||
| 35 | 17 | ▶ | if( defined( $out_type ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 9 | $self->out_type( $out_type ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 17 | ▶ | if( defined( $target ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | $self->attach_target( $target ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 17 | return $self; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 22 | ▶ | sub attach_target { | ||||||||
|
Subroutine
attach_target: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 47 | 22 | my( $self, $target ) = @_; | |||||||||
| 48 | |||||||||||
| 49 | 22 | assert( $target->isa('DS::Target') ); | |||||||||
| 50 | # First break link with old target, if any | ||||||||||
| 51 | 21 | ▶ | if( $self->{target} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 2 | $self->{target}->{source} = undef; | |||||||||
| 53 | } | ||||||||||
| 54 | 21 | ▶ | if( $target->source( $self ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 19 | $self->target( $target ); | |||||||||
| 56 | } | ||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # This is a primarily private method | ||||||||||
| 60 | # Important caveat: this method is just a field accessor method. | ||||||||||
| 61 | # Maintaining consistent links with target is handled by attach_target | ||||||||||
| 62 | 395 | ▶ | sub target { | ||||||||
|
Subroutine
target: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 63 | 395 | my( $self, $target ) = @_; | |||||||||
| 64 | |||||||||||
| 65 | 395 | my $result; | |||||||||
| 66 | 395 | ▶ | if( $target ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 29 | assert($target->isa('DS::Target')); | |||||||||
| 68 | 29 | $self->{target} = $target; | |||||||||
| 69 | 29 | $result = 1; | |||||||||
| 70 | } else { | ||||||||||
| 71 | 366 | $result = $self->{target}; | |||||||||
| 72 | } | ||||||||||
| 73 | 395 | return $result; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | # Send row to target | ||||||||||
| 77 | 168 | ▶ | sub pass_row { | ||||||||
|
Subroutine
pass_row: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 168 | my( $self, $row ) = @_; | |||||||||
| 79 | 168 | ▶ | confess("Can't pass rows since no target has been set") unless $self->target; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 166 | $self->target()->receive_row( $row ); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 62 | ▶ | sub out_type { | ||||||||
|
Subroutine
out_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 84 | 62 | my( $self, $type ) = @_; | |||||||||
| 85 | |||||||||||
| 86 | 62 | my $result; | |||||||||
| 87 | 62 | ▶ | if( $type ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 21 | assert($type->isa('DS::TypeSpec')); | |||||||||
| 89 | 21 | $self->{out_type} = $type; | |||||||||
| 90 | } else { | ||||||||||
| 91 | 41 | $result = $self->{out_type}; | |||||||||
| 92 | } | ||||||||||
| 93 | 62 | return $result; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 10 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||