Reconciliation/Rule.pm

filter: Statementstmt 98.1% 107 / 109 Branchbran 72.5% 29 / 40 Conditioncond 38.4% 15 / 39 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 86.6% 13 / 15 Podpod 71.4% 5 / 7 totaltotal 74.7% 169 / 226 CC 39 SCAR 25.4
CC
39
Cov
80%
add_comparison
25.0
identification
13.4
compare
5.0
CRAP 12.6
↑ Summary Reconciliation.pm »
1 ##======================================================================
2 ## Authors:
3 ## Martial.Chateauvieux@sfs.siemens.de
4 ## O.Capdevielle@cadextan.fr
5 ##======================================================================
6 ## Copyright (c) 2001, Siemens Financial Services. All rights reserved.
7 ## This library is free software; you can redistribute it and/or modify
8 ## it under the same terms as Perl itself.
9 ##======================================================================
10 ## $Log:$
11 ##======================================================================
12  
13 package Data::Reconciliation::Rule;
14  
15 2 require 5.005_62;
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 our $VERSION = '0.01';
22  
23 3 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
24 3 my $class = shift;
25 3 my $src1 = shift;
26 3 my $src2 = shift;
27  
28 croak "Usage: new $class (<Data::Table>, <Data::Table>)"
29 3 if ! eval { $src1->isa('Data::Table') } ||
30 3 ▶ ! eval { $src2->isa('Data::Table') };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $src1->isa("Data::Table") } } and eval { do { $src2->isa("Data::Table") } } 0 3 3
Condition33%1/3
eval { do { $src1->isa("Data::Table") } } and eval { do { $src2->isa("Data::Table") } }
!ll&&!rl&&r
003
MC/DC0%0/2
eval { do { $src1->isa("Data::Table") } } and eval { do { $src2->isa("Data::Table") } }
eval { do { $src1->isa("Data::Table") } } eval { do { $src2->isa("Data::Table") } }
Truth table33%1/3
A and B
A= eval { do { $src1->isa("Data::Table") } }B= eval { do { $src2->isa("Data::Table") } }
ABresult
0X0
100
111
31  
32 3 return bless {
33 'srcs' => [$src1, $src2]
34 }, $class;
35 }
36  
37 2 ▶sub identification {
Subroutine identification: called CC=12 SCAR=25.9
Pod documented
38 2 my $this = shift;
39  
40 2 ▶ if (@_ > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 0) 2 0 2
41 2 my $field_names_1 = shift;
42 2 my $canon_sub_1 = shift;
43 2 my $field_names_2 = shift;
44 2 my $canon_sub_2 = shift;
45  
46 2 foreach (@$field_names_1) {
47 croak "identification: Inavlid column name [$_]"
48 3 ▶ if $this->{'srcs'}->[0]->colIndex($_) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"srcs"}[0]->colIndex($_) == -1 0 3 3
49 }
50 2 foreach (@$field_names_2) {
51 croak "identification: Inavlid column name [$_]"
52 2 ▶ if $this->{'srcs'}->[1]->colIndex($_) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"srcs"}[1]->colIndex($_) == -1 0 2 2
53 }
54
55 2 my @field_idx_1 = map {$this->{'srcs'}->[0]->colIndex($_)} @$field_names_1;
56 2 my @field_idx_2 = map {$this->{'srcs'}->[1]->colIndex($_)} @$field_names_2;
57
58 6 ▶ $canon_sub_1 = sub { join '|', @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
59 2 ▶ if ! defined $canon_sub_1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $canon_sub_1 1 1 2
60 6 ▶ $canon_sub_2 = sub { join '|', @_ }
Subroutine __ANON__: called CC=1 SCAR=0.0
61 2 ▶ if ! defined $canon_sub_2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $canon_sub_2 1 1 2
62
63 2 ▶ croak 'Usage: $rule->identification(\@fields_1, \&canon_sub_1, ' .
Branch: 1 branch
BranchTrueFalseTotal
unless "ARRAY" eq ref $field_names_1 and "CODE" eq ref $canon_sub_1 and "ARRAY" eq ref $field_names_2 and "CODE" eq ref $canon_sub_2 0 2 2
Condition33%3/9
"ARRAY" eq ref $field_names_1 and "CODE" eq ref $canon_sub_1 and "ARRAY" eq ref $field_names_2 and "CODE" eq ref $canon_sub_2
!ll&&!rl&&r
002
"ARRAY" eq ref $field_names_1 and "CODE" eq ref $canon_sub_1 and "ARRAY" eq ref $field_names_2
!ll&&!rl&&r
002
"ARRAY" eq ref $field_names_1 and "CODE" eq ref $canon_sub_1
!ll&&!rl&&r
002
MC/DC0%0/4
"ARRAY" eq ref $field_names_1 and "CODE" eq ref $canon_sub_1 and "ARRAY" eq ref $field_names_2 and "CODE" eq ref $canon_sub_2
"ARRAY" eq ref $field_names_1 "CODE" eq ref $canon_sub_1 "ARRAY" eq ref $field_names_2 "CODE" eq ref $canon_sub_2
Truth table20%1/5
A and B and C and D
A= "ARRAY" eq ref $field_names_1B= "CODE" eq ref $canon_sub_1C= "ARRAY" eq ref $field_names_2D= "CODE" eq ref $canon_sub_2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
64 '\@fields_2, \&canon_sub_2);'
65 if ! (('ARRAY' eq ref $field_names_1) &&
66 ('CODE' eq ref $canon_sub_1) &&
67 ('ARRAY' eq ref $field_names_2) &&
68 ('CODE' eq ref $canon_sub_2));
69
70 2 $this->{'field_names'}->[0] = [ @$field_names_1];
71 2 $this->{'fields'}->[0] = [ @field_idx_1];
72 2 $this->{'canon_sub'}->[0] = $canon_sub_1;
73 2 $this->{'field_names'}->[1] = [ @$field_names_2];
74 2 $this->{'fields'}->[1] = [ @field_idx_2];
75 2 $this->{'canon_sub'}->[1] = $canon_sub_2;
76 }
77  
78 return ($this->{'fields'}->[0],
79 $this->{'canon_sub'}->[0],
80 $this->{'fields'}->[1],
81 2 $this->{'canon_sub'}->[1]);
82 }
83  
84 8 ▶sub isNumber ($) {
Subroutine isNumber: called CC=2 SCAR=7.2
Pod undocumented
85 8 ▶ return undef if ! defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 8 8
86 8 shift =~ /^\s*([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?\s*$/;
87 }
88  
89 14 ▶sub trim ($) {
Subroutine trim: called CC=2 SCAR=7.0
Pod undocumented
90 14 ▶ return undef if ! defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 14 14
91 14 my $field = shift;
92 14 $field =~ s/\s+$//o;
93 14 $field =~ s/^\s+//o;
94 14 return $field;
95 }
96  
97 4 ▶sub add_comparison {
Subroutine add_comparison: called CC=18 SCAR=32.2
Pod documented
98 4 my $this = shift;
99 4 my $field_names_1 = shift;
100 4 my $canon_sub_1 = shift;
101 4 my $field_names_2 = shift;
102 4 my $canon_sub_2 = shift;
103 4 my $compare_sub = shift;
104 4 my $compare_sub_name = shift;
105 4 my $constants = shift;
106
107 4 ▶ croak('usage: $r->add_comparison(',
Branch: 1 branch
BranchTrueFalseTotal
unless "ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1 and !defined($canon_sub_2) || "CODE" eq ref $canon_sub_2 and !defined($compare_sub) || "CODE" eq ref $compare_sub and !defined($constants) || "ARRAY" eq ref $constants 0 4 4
Condition40%11/27
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1 and !defined($canon_sub_2) || "CODE" eq ref $canon_sub_2 and !defined($compare_sub) || "CODE" eq ref $compare_sub and !defined($constants) || "ARRAY" eq ref $constants
!ll&&!rl&&r
004
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1 and !defined($canon_sub_2) || "CODE" eq ref $canon_sub_2 and !defined($compare_sub) || "CODE" eq ref $compare_sub
!ll&&!rl&&r
004
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1 and !defined($canon_sub_2) || "CODE" eq ref $canon_sub_2
!ll&&!rl&&r
004
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1
!ll&&!rl&&r
004
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2
!ll&&!rl&&r
004
not defined $canon_sub_1 or "CODE" eq ref $canon_sub_1
l!l&&r!l&&!r
310
not defined $canon_sub_2 or "CODE" eq ref $canon_sub_2
l!l&&r!l&&!r
310
not defined $compare_sub or "CODE" eq ref $compare_sub
l!l&&r!l&&!r
400
not defined $constants or "ARRAY" eq ref $constants
l!l&&r!l&&!r
400
MC/DC0%0/10
"ARRAY" eq ref $field_names_1 and "ARRAY" eq ref $field_names_2 and !defined($canon_sub_1) || "CODE" eq ref $canon_sub_1 and !defined($canon_sub_2) || "CODE" eq ref $canon_sub_2 and !defined($compare_sub) || "CODE" eq ref $compare_sub and !defined($constants) || "ARRAY" eq ref $constants
"ARRAY" eq ref $field_names_1 "ARRAY" eq ref $field_names_2 not defined $canon_sub_1 "CODE" eq ref $canon_sub_1 not defined $canon_sub_2 "CODE" eq ref $canon_sub_2 not defined $compare_sub "CODE" eq ref $compare_sub not defined $constants "ARRAY" eq ref $constants
Truth table6%2/33
A and B and not(C) or D and not(E) or F and not(G) or H and not(I) or J
A= "ARRAY" eq ref $field_names_1B= "ARRAY" eq ref $field_names_2C= not defined $canon_sub_1D= "CODE" eq ref $canon_sub_1E= not defined $canon_sub_2F= "CODE" eq ref $canon_sub_2G= not defined $compare_subH= "CODE" eq ref $compare_subI= not defined $constantsJ= "ARRAY" eq ref $constants
ABCDEFGHIJresult
0XXXXXXXXX0
10XXXXXXXX0
1100XXXXXX0
111X00XXXX0
110100XXXX0
111X1X00XX0
111X0100XX0
11011X00XX0
11010100XX0
111X1X1X000
111X1X01000
111X011X000
111X0101000
11011X1X000
11011X01000
1101011X000
11010101000
111X1X1X1X1
111X1X1X011
111X1X011X1
111X1X01011
111X011X1X1
111X011X011
111X01011X1
111X0101011
11011X1X1X1
11011X1X011
11011X011X1
11011X01011
1101011X1X1
1101011X011
110101011X1
11010101011
108 '\@field_names_1, \&canon_1, ',
109 '\@field_names_2, \&canon_2, ',
110 '\&compare, $compare_name, \@constants); ')
111 if ! (('ARRAY' eq ref $field_names_1) &&
112 ('ARRAY' eq ref $field_names_2) &&
113 ((! defined $canon_sub_1) || ('CODE' eq ref $canon_sub_1)) &&
114 ((! defined $canon_sub_2) || ('CODE' eq ref $canon_sub_2)) &&
115 ((! defined $compare_sub) || ('CODE' eq ref $compare_sub)) &&
116 ((! defined $constants) || ('ARRAY' eq ref $constants)));
117  
118 4 foreach (@$field_names_1) {
119 croak "add_comparison: Inavlid column name [$_]"
120 5 ▶ if $this->{'srcs'}->[0]->colIndex($_) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"srcs"}[0]->colIndex($_) == -1 0 5 5
121 }
122 4 foreach (@$field_names_2) {
123 croak "add_comparison: Inavlid column name [$_]"
124 4 ▶ if $this->{'srcs'}->[1]->colIndex($_) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"srcs"}[1]->colIndex($_) == -1 0 4 4
125 }
126  
127 4 my @field_idx_1 = map {$this->{'srcs'}->[0]->colIndex($_)} @$field_names_1;
128 4 my @field_idx_2 = map {$this->{'srcs'}->[1]->colIndex($_)} @$field_names_2;
129  
130 4 ▶ if (! defined $compare_sub) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $compare_sub) 4 0 4
131  
132 0 ▶ my $sub_1 = defined $canon_sub_1 ? $canon_sub_1 : sub { @_ };
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
defined $canon_sub_1 ? : 1 3 4
133 0 ▶ my $sub_2 = defined $canon_sub_2 ? $canon_sub_2 : sub { @_ };
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
defined $canon_sub_2 ? : 1 3 4
134  
135 8 ▶ $compare_sub = sub (\@\@\@\@$) {
Subroutine __ANON__: called CC=3 SCAR=11.0
136 8 my $field_names_1 = shift;
137 8 my $field_values_1 = shift;
138 8 my $field_names_2 = shift;
139 8 my $field_values_2 = shift;
140 8 my $constants = shift;
141 8 my $func_name = shift;
142
143 8 my $value_1 = join '|', @$field_values_1;
144 8 my $value_2 = join '|', @$field_values_2;
145  
146 8 ▶ if (isNumber($value_1) ?
Branch: 2 branches
BranchTrueFalseTotal
if (&isNumber($value_1) ? $value_1 <=> $value_2 : &trim($value_1) cmp &trim($value_2)) { } 2 6 8
&isNumber($value_1) ? : 1 7 8
147 $value_1 <=> $value_2 :
148 trim($value_1) cmp trim($value_2)) {
149 2 return sprintf("SRC1.%s=[%s] <> SRC2.%s=[%s]",
150 join('.', @$field_names_1),
151 $value_1,
152 join('.', @$field_names_2),
153 $value_2);
154 } else {
155 6 return undef ;
156 }
157 4 };
158 }
159  
160 4 push @{$this->{'comparison'}}, [$field_names_1, \@field_idx_1, $canon_sub_1,
161 $field_names_2, \@field_idx_2, $canon_sub_2,
162 $compare_sub, $compare_sub_name, $constants];
163 }
164  
165 15 ▶sub signature {
Subroutine signature: called CC=1 SCAR=0.0
Pod documented
166 15 my $this = shift;
167 15 my $source_nb = shift;
168 15 my $record = shift;
169  
170 15 my $fields = $this->{'fields'}->[$source_nb];
171 15 my $canon = $this->{'canon_sub'}->[$source_nb];
172  
173 15 return &$canon(@{$record}[@$fields]);
174 }
175  
176 7 ▶sub compare {
Subroutine compare: called CC=5 SCAR=16.1
Pod documented
177 7 my $this = shift;
178 7 my $record_1 = shift; #array ref
179 7 my $record_2 = shift; #array ref
180  
181 7 my @messages;
182  
183 7 foreach my $comp (@{$this->{'comparison'}}) {
184 8 my($fnames1, $fidx1, $sub_1,
185 $fnames2, $fidx2, $sub_2,
186 $comp_sub, $comp_sub_name, $consts) = @$comp;
187 my $msg = &$comp_sub($fnames1,
188 [ defined $sub_1 ?
189 1 &$sub_1(@{$record_1}[@$fidx1]) :
190 7 ▶ @{$record_1}[@$fidx1] ],
Branch: 1 branch
BranchTrueFalseTotal
defined $sub_2 ? : 1 7 8
191 $fnames2,
192 [ defined $sub_2 ?
193 1 &$sub_2(@{$record_2}[@$fidx2]) :
194 8 ▶ @{$record_2}[@$fidx2] ],
Branch: 1 branch
BranchTrueFalseTotal
defined $sub_1 ? : 1 7 8
195 $consts,
196 $comp_sub_name);
197 8 ▶ push @messages, $msg if defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $msg 2 6 8
198 }
199  
200 7 return @messages;
201 }
202  
203 2 1;
204 __END__
↑ Summary Reconciliation.pm »