line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ########################################################################## #
|
4
|
|
|
|
|
|
|
# Title: Stack transformer
|
5
|
|
|
|
|
|
|
# Creation date: 2007-03-05
|
6
|
|
|
|
|
|
|
# Author: Michael Zedeler
|
7
|
|
|
|
|
|
|
# Description: Represents a stack of transformers
|
8
|
|
|
|
|
|
|
# Data Stream class
|
9
|
|
|
|
|
|
|
# Data transformer
|
10
|
|
|
|
|
|
|
# File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/Stack.pm,v $
|
11
|
|
|
|
|
|
|
# Repository: kronhjorten
|
12
|
|
|
|
|
|
|
# State: $State: Exp $
|
13
|
|
|
|
|
|
|
# Documentation: inline
|
14
|
|
|
|
|
|
|
# Recepient: -
|
15
|
|
|
|
|
|
|
# ########################################################################## #
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# TODO Make pass_row work again.
|
19
|
|
|
|
|
|
|
# TODO Make process work again (call internal stack)
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
package DS::Transformer::Stack;
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
826
|
use base qw{ DS::Transformer::Opaque };
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
645
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
26
|
1
|
|
|
1
|
|
3
|
use Carp qw{ croak cluck confess };
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
27
|
1
|
|
|
1
|
|
5
|
use Carp::Assert;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
28
|
1
|
|
|
1
|
|
670
|
use DS::Target::Proxy;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
511
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our ($VERSION) = $DS::VERSION;
|
31
|
|
|
|
|
|
|
our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new {
|
34
|
1
|
|
|
1
|
1
|
888
|
my( $class, $source, $stack ) = @_;
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
11
|
my $self = $class->SUPER::new( undef, undef, $source );
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
2
|
foreach my $transformer (@$stack) {
|
39
|
0
|
|
|
|
|
0
|
$self->push_transformer( $transformer );
|
40
|
|
|
|
|
|
|
}
|
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
3
|
return $self;
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub push_transformer {
|
46
|
1
|
|
|
1
|
0
|
413
|
my( $self, $transformer ) = @_;
|
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
6
|
assert( $transformer->isa('DS::Transformer') );
|
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
13
|
if( $self->target ) {
|
51
|
0
|
|
|
|
|
0
|
confess("Invalid use of stack. It is not possible to modify stack after target has been set.");
|
52
|
|
|
|
|
|
|
}
|
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
3
|
if( defined( $self->top() ) ) {
|
55
|
0
|
|
|
|
|
0
|
$transformer->attach_source( $self->top() );
|
56
|
|
|
|
|
|
|
} else {
|
57
|
1
|
|
|
|
|
3
|
$self->bottom( $transformer );
|
58
|
|
|
|
|
|
|
}
|
59
|
1
|
|
|
|
|
3
|
$self->top( $transformer );
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Set top transformer and check that no target has been set yet
|
63
|
|
|
|
|
|
|
# Do NOT try to maintain links with internal transformers in stack
|
64
|
|
|
|
|
|
|
sub top {
|
65
|
4
|
|
|
4
|
0
|
13
|
my( $self, $top ) = @_;
|
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
5
|
my $result;
|
68
|
4
|
100
|
|
|
|
7
|
if( defined( $top ) ) {
|
69
|
1
|
50
|
|
|
|
3
|
if( $self->target ) {
|
70
|
0
|
|
|
|
|
0
|
confess("Invalid use of stack. It is not possible to modify stack after target has been set.");
|
71
|
|
|
|
|
|
|
}
|
72
|
1
|
|
|
|
|
2
|
$self->{top} = $top;
|
73
|
1
|
|
|
|
|
2
|
$result = 1;
|
74
|
|
|
|
|
|
|
} else {
|
75
|
3
|
|
|
|
|
6
|
$result = $self->{top};
|
76
|
|
|
|
|
|
|
}
|
77
|
4
|
|
|
|
|
15
|
return $result;
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Set bottom transformer and maintain links with source transformer (outside stack)
|
81
|
|
|
|
|
|
|
# Do NOT try to maintain links with internal transformers in stack
|
82
|
|
|
|
|
|
|
sub bottom {
|
83
|
17
|
|
|
17
|
0
|
21
|
my( $self, $bottom ) = @_;
|
84
|
|
|
|
|
|
|
|
85
|
17
|
|
|
|
|
15
|
my $result;
|
86
|
17
|
100
|
|
|
|
31
|
if( defined( $bottom ) ) {
|
87
|
1
|
50
|
|
|
|
6
|
if( defined( $self->source ) ) {
|
88
|
0
|
|
|
|
|
0
|
$bottom->attach_source( $self->source );
|
89
|
|
|
|
|
|
|
}
|
90
|
1
|
|
|
|
|
2
|
$self->{bottom} = $bottom;
|
91
|
|
|
|
|
|
|
} else {
|
92
|
16
|
|
|
|
|
21
|
$result = $self->{bottom};
|
93
|
|
|
|
|
|
|
}
|
94
|
17
|
|
|
|
|
49
|
return $result;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub in_type {
|
98
|
2
|
|
|
2
|
1
|
2
|
my( $self, $in_type ) = @_;
|
99
|
2
|
|
|
|
|
4
|
return $self->bottom()->in_type( $in_type );
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub out_type {
|
103
|
1
|
|
|
1
|
1
|
3
|
my( $self, $out_type ) = @_;
|
104
|
1
|
|
|
|
|
3
|
return $self->top()->out_type( $out_type );
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub receive_row {
|
108
|
13
|
|
|
13
|
1
|
2252
|
my( $self, $row ) = @_;
|
109
|
13
|
|
|
|
|
23
|
return $self->bottom()->receive_row( $row );
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub attach_source_internal {
|
113
|
1
|
|
|
1
|
0
|
1
|
my( $self, $source ) = @_;
|
114
|
1
|
|
|
|
|
3
|
return $self->bottom()->attach_source( $source );
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub attach_target_internal {
|
118
|
1
|
|
|
1
|
0
|
3
|
my( $self, $target ) = @_;
|
119
|
1
|
|
|
|
|
2
|
return $self->top()->attach_target( $target );
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub process {
|
123
|
1
|
|
|
1
|
1
|
1321
|
croak 'Process is not well defined on stacks, since the transformers on the stack may return more or less than one row.';
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1;
|