DS/Transformer/Stack.pm

filter: Statementstmt 91.5% 54 / 59 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 50.0% 5 / 10 totaltotal 85.4% 82 / 96 CC 8 SCAR 6.8
CC
8
Cov
87%
push_transformer
3.3
bottom
3.0
top
3.0
CRAP 2.0
« DS/Transformer/Sth.pm ↑ Summary DS/Source/Push.pm »
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 ▶use base qw{ DS::Transformer::Opaque };
Subroutine BEGIN: called CC=1 SCAR=0.0
24
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Carp qw{ croak cluck confess };
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Carp::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use DS::Target::Proxy;
Subroutine BEGIN: called CC=1 SCAR=0.0
29
30 1 our ($VERSION) = $DS::VERSION;
31 1 our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
32
33 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
34 1 my( $class, $source, $stack ) = @_;
35
36 1 my $self = $class->SUPER::new( undef, undef, $source );
37
38 1 foreach my $transformer (@$stack) {
39 0 $self->push_transformer( $transformer );
40 }
41
42 1 return $self;
43 }
44
45 1 ▶sub push_transformer {
Subroutine push_transformer: called CC=3 SCAR=12.0
Pod undocumented
46 1 my( $self, $transformer ) = @_;
47
48 1 assert( $transformer->isa('DS::Transformer') );
49
50 1 ▶ if( $self->target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->target) 0 1 1
51 0 confess("Invalid use of stack. It is not possible to modify stack after target has been set.");
52 }
53
54 1 ▶ if( defined( $self->top() ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->top) { } 0 1 1
55 0 $transformer->attach_source( $self->top() );
56 } else {
57 1 $self->bottom( $transformer );
58 }
59 1 $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 4 ▶sub top {
Subroutine top: called CC=3 SCAR=11.1
Pod undocumented
65 4 my( $self, $top ) = @_;
66
67 4 my $result;
68 4 ▶ if( defined( $top ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $top) { } 1 3 4
69 1 ▶ if( $self->target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->target) 0 1 1
70 0 confess("Invalid use of stack. It is not possible to modify stack after target has been set.");
71 }
72 1 $self->{top} = $top;
73 1 $result = 1;
74 } else {
75 3 $result = $self->{top};
76 }
77 4 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 17 ▶sub bottom {
Subroutine bottom: called CC=3 SCAR=11.1
Pod undocumented
83 17 my( $self, $bottom ) = @_;
84
85 17 my $result;
86 17 ▶ if( defined( $bottom ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bottom) { } 1 16 17
87 1 ▶ if( defined( $self->source ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->source) 0 1 1
88 0 $bottom->attach_source( $self->source );
89 }
90 1 $self->{bottom} = $bottom;
91 } else {
92 16 $result = $self->{bottom};
93 }
94 17 return $result;
95 }
96
97 2 ▶sub in_type {
Subroutine in_type: called CC=1 SCAR=0.0
Pod documented
98 2 my( $self, $in_type ) = @_;
99 2 return $self->bottom()->in_type( $in_type );
100 }
101
102 1 ▶sub out_type {
Subroutine out_type: called CC=1 SCAR=0.0
Pod documented
103 1 my( $self, $out_type ) = @_;
104 1 return $self->top()->out_type( $out_type );
105 }
106
107 13 ▶sub receive_row {
Subroutine receive_row: called CC=1 SCAR=0.0
Pod documented
108 13 my( $self, $row ) = @_;
109 13 return $self->bottom()->receive_row( $row );
110 }
111
112 1 ▶sub attach_source_internal {
Subroutine attach_source_internal: called CC=1 SCAR=0.0
Pod undocumented
113 1 my( $self, $source ) = @_;
114 1 return $self->bottom()->attach_source( $source );
115 }
116
117 1 ▶sub attach_target_internal {
Subroutine attach_target_internal: called CC=1 SCAR=0.0
Pod undocumented
118 1 my( $self, $target ) = @_;
119 1 return $self->top()->attach_target( $target );
120 }
121
122 1 ▶sub process {
Subroutine process: called CC=1 SCAR=0.0
Pod documented
123 1 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 1;
« DS/Transformer/Sth.pm ↑ Summary DS/Source/Push.pm »