File Coverage

blib/lib/DS/Transformer/Opaque.pm
Criterion Covered Total %
statement 32 39 82.0
branch 6 8 75.0
condition 2 6 33.3
subroutine 9 13 69.2
pod 3 6 50.0
total 52 72 72.2


line stmt bran cond sub pod time code
1             #!perl
2            
3             # ########################################################################## #
4             # Title: Opaque transformer
5             # Creation date: 2007-03-05
6             # Author: Michael Zedeler
7             # Description: Provides opaque bindings between some internal transformers
8             # and external transformers
9             # Data Stream class
10             # Data transformer
11             # File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/Opaque.pm,v $
12             # Repository: kronhjorten
13             # State: $State: Exp $
14             # Documentation: inline
15             # Recepient: -
16             # ########################################################################## #
17            
18             package DS::Transformer::Opaque;
19            
20 1     1   5 use base qw{ DS::Transformer };
  1         2  
  1         77  
21            
22 1     1   6 use strict;
  1         1  
  1         35  
23 1     1   5 use Carp qw{ confess croak };
  1         1  
  1         50  
24 1     1   5 use Carp::Assert;
  1         1  
  1         16  
25 1     1   605 use DS::Source::Push;
  1         3  
  1         47  
26 1     1   533 use DS::Target::Sub;
  1         2  
  1         363  
27            
28             our ($VERSION) = $DS::VERSION;
29             our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
30            
31            
32             sub source {
33 3     3 1 4 my( $self, $source ) = @_;
34            
35 3         13 my $result = $self->SUPER::source( $source );
36 3 100       7 if( $source ) {
37 1 50       3 $self->{internal_source} = new DS::Source::Push( $source->out_type )
38             or confess("Fatal error while trying to create source proxy object.");
39 1   33     7 $result &&= $self->attach_source_internal( $self->{internal_source} );
40             }
41 3         11 return $result;
42             }
43            
44             sub target {
45 30     30 1 40 my( $self, $target ) = @_;
46            
47 30         76 my $result = $self->SUPER::target( $target );
48 30 100       58 if( $target ) {
49             $self->{internal_target} = new DS::Target::Sub(
50             sub {
51 13     13   19 my( undef, $row ) = @_;
52 13         33 $self->pass_row( $row );
53             },
54 1 50       8 $target->in_type
55             ) or confess("Fatal error while trying to create target proxy object.");
56 1   33     7 $result &&= $self->attach_target_internal( $self->{internal_target} );
57             }
58 30         86 return $result;
59             }
60            
61             sub validate_source {
62             # In DS::Transformer::Stack validation is done elsewhere.
63             # Proxies causes validation to happen at two places:
64             # (1) top-of-stack and target and (2) bottom-of-stack and source
65 0     0 0   return 1;
66             }
67            
68             sub receive_row {
69 0     0 1   my( $self, $row ) = @_;
70            
71 0           assert( $self->{internal_source}, 'Cannot receive rows from undefined source' );
72 0           $self->{internal_source}->receive_row( $row );
73            
74 0           return;
75             }
76            
77             # The following methods are delegated to the internal object
78             foreach my $internal_method ( qw{ target source } ) {
79 0     0 0   eval <<"END_METHOD"; ## no critic
  0     0 0    
80             sub attach_${internal_method}_internal {
81             croak("This method must be overridden. You probably want to proxy it to the internal object that needs to be hidden from the outside.");
82            
83             }
84             END_METHOD
85             }
86            
87             1;