DS/Transformer.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 3 / 3 totaltotal 95.4% 42 / 44 CC 5 SCAR 12.0
CC
5
Cov
97%
new
5.0
process
2.0
BEGIN
1.0
CRAP 3.3
« DS/Transformer/Grep.pm ↑ Summary DS.pm »
1 #!perl
2
3 # ########################################################################## #
4 # Title: Data stream transformer
5 # Creation date: 2007-03-05
6 # Author: Michael Zedeler
7 # Description: Transforms data stream
8 # Data Stream class
9 # File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer.pm,v $
10 # Repository: kronhjorten
11 # State: $State: Exp $
12 # Documentation: inline
13 # Recepient: -
14 # ########################################################################## #
15
16 package DS::Transformer;
17
18 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use Carp::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
20
21 6 our ($VERSION) = $DS::VERSION;
22 6 our ($REVISION) = '$Revision: 1.2 $' =~ /(\d+\.\d+)/;
23
24 6 require DS::TypeSpec;
25 6 require DS::Target;
26 6 require DS::Source;
27
28 6 our( @ISA ) = qw{ DS::Target DS::Source };
29
30
31 17 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
32 17 my( $class, $in_type, $out_type, $source, $target ) = @_;
33
34 17 bless my $self = {}, $class;
35
36 17 ▶ if( $in_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_type) 6 11 17
37 6 $self->in_type( $in_type );
38 }
39 17 ▶ if( $out_type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out_type) 6 11 17
40 6 $self->out_type( $out_type );
41 }
42 17 ▶ if( $source ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source) 3 14 17
43 3 $self->attach_source( $source );
44 }
45 17 ▶ if( $target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target) 1 16 17
46 1 $self->attach_target( $target );
47 }
48
49 17 return $self;
50 }
51
52 # Override this method if you want to change how the transformer passes
53 # rows onto its target when this method is called. If you just want to
54 # transform the row without changing how data is passed on, override
55 # process() in stead.
56 # This method MUST NOT return anything. If errors occur, croak or die with exceptions
57 91 ▶sub receive_row {
Subroutine receive_row: called CC=1 SCAR=0.0
Pod documented
58 91 my( $self, $row ) = @_;
59
60 91 $self->pass_row( $self->process( $row ) );
61
62 91 return;
63 }
64
65 # Process row (possibly transforming it) before passing it to
66 # the next transformer.
67 # Just no operation (this method is here to be overridden)
68 0 ▶sub process {
Subroutine process: not called CC=1 SCAR=6.9
Pod documented
69 0 return $_[1];
70 }
71
72 6 1;
73
74 __END__
« DS/Transformer/Grep.pm ↑ Summary DS.pm »