DS/Transformer/Catch.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 CC 3 SCAR 13.9
CC
3
Cov
0%
pass_row
6.0
catch
6.0
new
2.0
CRAP 4.0
1 #!perl
2
3 # ########################################################################## #
4 # Title: Catch transformer
5 # Creation date: 2007-04-18
6 # Author: Michael Zedeler
7 # Description: Catch exceptions and pass them to subroutine
8 # Data Stream class
9 # Data transformer
10 # File: $Source: /data/cvs/lib/DSlib/lib/DS/Transformer/Catch.pm,v $
11 # Repository: kronhjorten
12 # State: $State: Exp $
13 # Documentation: inline
14 # Recepient: -
15 # ########################################################################## #
16
17 package DS::Transformer::Catch;
18
19 use base qw{ DS::Transformer::TypePassthrough };
20
21 use strict;
22 use Carp::Assert;
23
24 our ($VERSION) = $DS::VERSION;
25 our ($REVISION) = '$Revision: 1.1 $' =~ /(\d+\.\d+)/;
26
27
28 sub new {
29 my( $class, $catch, $source, $target ) = @_;
30
31 my $self = $class->SUPER::new( $source, $target );
32
33 $self->{catch} = $catch;
34
35 return $self;
36 }
37
38 sub pass_row {
39 my( $self, $row ) = @_;
40 eval {
41 $self->SUPER::pass_row( $row );
42 };
43 if( $@ ) {
44 &{$self->{catch}}($self, $@);
45 }
46 }
47
48 sub catch {
49 my( $self, $catch ) = @_;
50
51 my $result;
52
53 if( $catch ) {
54 assert( ref( $catch ) eq 'CODE' );
55 $self->{catch} = $catch;
56 } else {
57 $result = $self->{catch};
58 }
59
60 return $result;
61 }
62
63 1;
64
65