| 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; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | require 5.005_62; | |||||||||||||||||||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Data::Table; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Data::Reconciliation::Rule; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 30 | 1 | my $source1 = shift; | |||||||||||||||||||||||||||
| 31 | 1 | my $source2 = shift; | |||||||||||||||||||||||||||
| 32 | 1 | my %prms = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | croak 'Sources must be of type Data::Table' | ||||||||||||||||||||||||||||
| 35 | 1 | if (! eval {$source1->isa('Data::Table')}) || | |||||||||||||||||||||||||||
| 36 | 1 | ▶ | (! eval {$source2->isa('Data::Table')}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
eval {
do {
$source1->isa("Data::Table")
}
} and eval {
do {
$source2->isa("Data::Table")
}
}
MC/DC0%0/2
eval {
do {
$source1->isa("Data::Table")
}
} and eval {
do {
$source2->isa("Data::Table")
}
}
eval {
do {
$source1->isa("Data::Table")
}
}
eval {
do {
$source2->isa("Data::Table")
}
}
Truth table33%1/3
A and B
A= eval {
do {
$source1->isa("Data::Table")
}
}B= eval {
do {
$source2->isa("Data::Table")
}
}
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | my @rules; | |||||||||||||||||||||||||||
| 39 | 1 | ▶ | if (exists $prms{-rules}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 1 | @rules = @{$prms{-rules}}; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | croak 'Invalid Data::Reconciliation::Rule' | ||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if grep(! eval {$_->isa('Data::Reconciliation::Rule')}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | @rules); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 0 | my $r = new Data::Reconciliation::Rule; | |||||||||||||||||||||||||||
| 48 | 0 | $r->identification([0], undef, [0], undef); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $col_nb = 0; | |||||||||||||||||||||||||||
| 51 | 0 | foreach ($source1->header) { | |||||||||||||||||||||||||||
| 52 | 0 | $r->add_comparison([++$col_nb], undef, [$col_nb], undef, undef); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | push @rules, $r; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | return bless {'srcs' => [$source1, $source2], | |||||||||||||||||||||||||||
| 58 | 'rules' => \@rules, | ||||||||||||||||||||||||||||
| 59 | #'result-store' => $result_store | ||||||||||||||||||||||||||||
| 60 | }, $class; | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub build_signatures { | ||||||||||||||||||||||||||
|
Subroutine
build_signatures: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 65 | 1 | my $rule_nb = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 1 | ▶ | croak 'usage: $r->build_signatures(<rule_nb>);' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | if ! defined $rule_nb; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | croak 'invalid rule nb' | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | if $rule_nb >= @{$this->{'rules'}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | for my $src_nb (0 .. 1) { | |||||||||||||||||||||||||||
| 74 | 2 | my %signature; | |||||||||||||||||||||||||||
| 75 | 2 | my $rule = $this->{'rules'}->[$rule_nb]; | |||||||||||||||||||||||||||
| 76 | 2 | my $src = $this->{'srcs'}->[$src_nb]; | |||||||||||||||||||||||||||
| 77 | 2 | ▶ | for(my $i = 0 ; $i < $src->nofRow ; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 12 | push @{$signature{$rule->signature($src_nb, $src->rowRef($i))}}, $i; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 2 | $this->{'signatures'}->[$src_nb] = \%signature; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub signatures { | ||||||||||||||||||||||||||
|
Subroutine
signatures: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 86 | 1 | ▶ | return ([], []) if ! defined $this->{'signatures'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 1 | return @{$this->{'signatures'}}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub duplicate_signatures { | ||||||||||||||||||||||||||
|
Subroutine
duplicate_signatures: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 3 | my $this = shift; | |||||||||||||||||||||||||||
| 92 | 3 | my @results; | |||||||||||||||||||||||||||
| 93 | 3 | foreach my $src_nb (0..1) { | |||||||||||||||||||||||||||
| 94 | 6 | my $signature = $this->{'signatures'}->[$src_nb]; | |||||||||||||||||||||||||||
| 95 | $results[$src_nb] = { | ||||||||||||||||||||||||||||
| 96 | map { | ||||||||||||||||||||||||||||
| 97 | 2 | ($_ => $signature->{$_}) | |||||||||||||||||||||||||||
| 98 | 6 | } grep(1 < @{$signature->{$_}}, keys %$signature) | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 3 | return @results; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sub _delete { | ||||||||||||||||||||||||||
|
Subroutine
_delete: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 105 | 2 | my $this = shift; | |||||||||||||||||||||||||||
| 106 | 2 | my @signs = @_; | |||||||||||||||||||||||||||
| 107 | 2 | my @results = ({},{}); | |||||||||||||||||||||||||||
| 108 | 2 | foreach my $src_nb (0..1) { | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 4 | my $signs = $signs[$src_nb]; | |||||||||||||||||||||||||||
| 111 | 4 | ▶ | next if @$signs == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 2 | my $src = $this->{'srcs'}->[$src_nb]; | |||||||||||||||||||||||||||
| 114 | 2 | my $signature = $this->{'signatures'}->[$src_nb]; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | %{$results[$src_nb]} = map { ($_ => delete $signature->{$_}) } @$signs; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 2 | return @results; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub delete_dup_signatures { | ||||||||||||||||||||||||||
|
Subroutine
delete_dup_signatures: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 123 | 1 | return $this->_delete(map {[keys %$_]} $this->duplicate_signatures); | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 3 | ▶ | sub widow_signatures { | ||||||||||||||||||||||||||
|
Subroutine
widow_signatures: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 3 | my $this = shift; | |||||||||||||||||||||||||||
| 128 | 3 | my @results = ({},{}); | |||||||||||||||||||||||||||
| 129 | 3 | foreach my $src_nb (0..1) { | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 6 | my $sign = $this->{'signatures'}->[$src_nb]; | |||||||||||||||||||||||||||
| 132 | 6 | ▶ | my $sign_other_src = $this->{'signatures'}->[ $src_nb == 0 ? 1 : 0 ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 6 | my $result = $results[$src_nb]; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 4 | %$result = map {($_ =>$sign->{$_})} | |||||||||||||||||||||||||||
| 136 | 6 | grep(! exists $sign_other_src->{$_}, keys %$sign); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # foreach my $sign (keys %$sign) { | ||||||||||||||||||||||||||||
| 139 | # push @$result, ($sign => $sign->{$sign}) | ||||||||||||||||||||||||||||
| 140 | # if ! exists $sign_other_src->{$sign}; | ||||||||||||||||||||||||||||
| 141 | # } | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 3 | return @results; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub delete_wid_signatures { | ||||||||||||||||||||||||||
|
Subroutine
delete_wid_signatures: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 148 | 1 | return $this->_delete(map {[keys %$_]} $this->widow_signatures); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub reconciliate { | ||||||||||||||||||||||||||
|
Subroutine
reconciliate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 1 | my $this = shift; | |||||||||||||||||||||||||||
| 153 | 1 | my $rule_nb = shift; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | ▶ | croak 'usage: $r->reconciliate(<rule_nb>);' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | if ! defined $rule_nb; | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | croak 'invalid rule nb' | ||||||||||||||||||||||||||||
| 159 | 1 | ▶ | if $rule_nb >= @{$this->{'rules'}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 1 | my $rule = $this->{'rules'}->[$rule_nb]; | |||||||||||||||||||||||||||
| 162 | 1 | my @results; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 1 | my $sign_1 = $this->{'signatures'}->[0]; | |||||||||||||||||||||||||||
| 165 | 1 | my $src_1 = $this->{'srcs'}->[0]; | |||||||||||||||||||||||||||
| 166 | 1 | my $sign_2 = $this->{'signatures'}->[1]; | |||||||||||||||||||||||||||
| 167 | 1 | my $src_2 = $this->{'srcs'}->[1]; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 1 | foreach my $signature (keys %$sign_1) { | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 4 | (my $idx1) = @{$sign_1->{$signature}}; | |||||||||||||||||||||||||||
| 172 | 4 | (my $idx2) = @{$sign_2->{$signature}}; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 4 | my $rec1 = [ $src_1->row($idx1) ]; | |||||||||||||||||||||||||||
| 175 | 4 | my $rec2 = [ $src_2->row($idx2) ]; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | push @results, map { | ||||||||||||||||||||||||||||
| 178 | # if ($mode eq 'all') { | ||||||||||||||||||||||||||||
| 179 | 4 | [$signature, [$idx1, $idx2], $rule, $_]; | |||||||||||||||||||||||||||
| 180 | # } elsif ($mode eq 'ok') { | ||||||||||||||||||||||||||||
| 181 | # $_ ? () : [$key, $rule, $_]; | ||||||||||||||||||||||||||||
| 182 | # } else { | ||||||||||||||||||||||||||||
| 183 | # $_ ? [$key, $rule, $_] : (); | ||||||||||||||||||||||||||||
| 184 | # } | ||||||||||||||||||||||||||||
| 185 | } $rule->compare($rec1, $rec2); | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 1 | return @results; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 1 | 1; | |||||||||||||||||||||||||||
| 193 | __END__ | ||||||||||||||||||||||||||||