| 1 | #!perl | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | # ########################################################################## # | ||||||||||||||||||||||||||
| 4 | # Title: Data stream target proxy | ||||||||||||||||||||||||||
| 5 | # Creation date: 2007-04-16 | ||||||||||||||||||||||||||
| 6 | # Author: Michael Zedeler | ||||||||||||||||||||||||||
| 7 | # Description: Receives data and passes it to another, underlying target | ||||||||||||||||||||||||||
| 8 | # Data Stream class | ||||||||||||||||||||||||||
| 9 | # File: $Source: /data/cvs/lib/DSlib/lib/DS/Target/Proxy.pm,v $ | ||||||||||||||||||||||||||
| 10 | # Repository: kronhjorten | ||||||||||||||||||||||||||
| 11 | # State: $State: Exp $ | ||||||||||||||||||||||||||
| 12 | # Documentation: inline | ||||||||||||||||||||||||||
| 13 | # Recepient: - | ||||||||||||||||||||||||||
| 14 | # ########################################################################## # | ||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||
| 16 | package DS::Target::Proxy; | ||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||
| 18 | 1 | ▶ | use base qw{ DS::Target }; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Carp qw{ croak cluck confess carp }; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Carp::Assert; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||
| 24 | 1 | our ($VERSION) = $DS::VERSION; | |||||||||||||||||||||||||
| 25 | 1 | our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/; | |||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||
| 27 | 1 | my @proxy_methods = qw{ receive_row source attach_source in_type validate_source }; | |||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub new { | ||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||
| 30 | 0 | my( $class, $inner_object, $delegate ) = @_; | |||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||
| 32 | 0 | bless my $self = {}, $class; | |||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->inner_object( $inner_object ) if $inner_object; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 34 | 0 | ▶ | $self->delegate( $delegate ) if $delegate; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub inner_object { | ||||||||||||||||||||||||
|
Subroutine
inner_object: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 40 | 0 | my( $self, $object ) = @_; | |||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | 0 | my $result = 1; | |||||||||||||||||||||||||
| 43 | 0 | ▶ | if( $object ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 44 | 0 | assert($object->isa( 'DS::Target' ) ); | |||||||||||||||||||||||||
| 45 | 0 | $self->{inner_object} = $object; | |||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||
| 47 | 0 | $result = $self->{inner_object}; | |||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||
| 49 | 0 | return $result; | |||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub delegate { | ||||||||||||||||||||||||
|
Subroutine
delegate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||
| 53 | 0 | my( $self, $delegate ) = @_; | |||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||
| 55 | 0 | my $result = 1; | |||||||||||||||||||||||||
| 56 | 0 | ▶ | if( $delegate ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 57 | 0 | $self->{delegate} = $delegate; | |||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||
| 59 | 0 | $result = $self->{delegate}; | |||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||
| 61 | 0 | return $result; | |||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | # Create all proxy methods using eval | ||||||||||||||||||||||||||
| 65 | # This is not very expensive, since it is only done once - at load time | ||||||||||||||||||||||||||
| 66 | 1 | foreach my $method ( @proxy_methods ) { | |||||||||||||||||||||||||
| 67 | 0 | ▶ | eval <<"END_METHOD"; ## no critic | ||||||||||||||||||||||||
|
Subroutine
attach_source: not called CC=2 SCAR=17.3
Subroutine
in_type: not called CC=2 SCAR=17.3
Subroutine
receive_row: not called CC=2 SCAR=17.3
Subroutine
source: not called CC=2 SCAR=17.3
Subroutine
validate_source: not called CC=2 SCAR=17.3
Pod
documented
Pod
documented
Pod
documented
Pod
documented
Pod
undocumented
Branch: 5 branches
| |||||||||||||||||||||||||||
| 68 | sub $method { | ||||||||||||||||||||||||||
| 69 | my( \$self, \@args ) = \@_; | ||||||||||||||||||||||||||
| 70 | if( \$self->{delegate}->can( 'delegate_$method' ) ) { | ||||||||||||||||||||||||||
| 71 | return \$self->{delegate}->delegate_invoke( '$method', \$self, \@args ); | ||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||
| 73 | return \$self->{inner_object}->$method( \@args ); | ||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||
| 76 | END_METHOD | ||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||