blib/lib/Text/NumericData/FileCalc.pm

filter: Statementstmt 100% 58 / 58 Branchbran 71.4% 20 / 28 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 2 / 2 Podpod 0.0% 0 / 1 totaltotal 82.8% 82 / 99 SCAR 31.4
CC
22
Cov
87%
file_calc
23.5
BEGIN
1.0
CRAP 23.1
« blib/lib/Text/NumericData/App/txdrows.pm ↑ Summary blib/lib/Text/NumericData/Stat.pm »
1 package Text::NumericData::FileCalc;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 require Exporter;
6  
7 # This is just a placeholder because of a past build system bug.
8 # The one and only version for Text::NumericData is kept in
9 # the Text::NumericData module itself.
10 3 our $VERSION = '1';
11 3 $VERSION = eval $VERSION;
12  
13 3 our @ISA = qw(Exporter);
14 3 our @EXPORT_OK = qw(file_calc);
15  
16 # Returns list ref of deletion indices, undef on failure.
17 sub file_calc
18 {
19 421 ▶ my $ff = shift; # formula function
Subroutine file_calc: called CC=22 SCAR=31.6
Pod undocumented
20 421 my $config = shift; # see defaults below
21 421 my $data = shift; # main data set to work on
22 421 my $files = shift; # list of Text::NumericData::File objects to use
23 421 my $workarray = shift; # \@A
24 421 my $constants = shift; # \@C
25 # configuration defaults
26 421 ▶ $config =
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config 1 420 421
27 {
28 bycol=>0
29 , fromcol=>undef
30 , byrow=>0
31 , skipempty=>1 # Do nothing on empty data sets,
32 , rowoffset=>0 # offset for byrow ($data starting with that row)
33 } unless(defined $config);
34  
35 421 ▶ return undef unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 421 421
36  
37 421 my @delete;
38 # shortcut for context-less computations
39 421 ▶ unless(defined $files)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $files) 1 420 421
40 {
41 1 for my $row (0..$#{$data})
42 {
43 4 ▶ next if(not @{$data->[$row]} and $config->{skipempty});
Branch: 1 branch
BranchTrueFalseTotal
if not @{$data->[$row];} and $config->{"skipempty"} 0 4 4
Condition33%1/3
not @{$data->[$row];} and $config->{"skipempty"}
!ll&&!rl&&r
400
MC/DC0%0/2
not @{$data->[$row];} and $config->{"skipempty"}
not @{$data->[$row];} $config->{"skipempty"}
Truth table33%1/3
not(A) and B
A= not @{$data->[$row];}B= $config->{"skipempty"}
ABresult
0X0
100
111
44 4 my $ignore = &$ff([$data->[$row]]);
45 4 ▶ push(@delete, $row) if $ignore;
Branch: 1 branch
BranchTrueFalseTotal
if $ignore 0 4 4
46 }
47 1 return \@delete;
48 }
49  
50 # the real deal, full computation in all complexity
51 420 my @fromcol;
52 420 my $bycol = 0;
53 $bycol = $config->{bycol}
54 420 ▶ if defined $config->{bycol};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"bycol"} 420 0 420
55 420 my $byrow = 0;
56 $byrow = $config->{byrow}
57 420 ▶ if defined $config->{byrow};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"byrow"} 420 0 420
58 420 for my $i (0..$#{$files})
59 {
60 420 ▶ if(defined $config->{fromcol})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"fromcol"}) 420 0 420
61 {
62 420 $fromcol[$i] = $config->{fromcol}[$i];
63 }
64 420 ▶ $fromcol[$i] = $bycol unless defined $fromcol[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fromcol[$i] 0 420 420
65 }
66  
67 420 for my $row (0..$#{$data})
68 {
69 420 ▶ next if(not @{$data->[$row]} and $config->{skipempty});
Branch: 1 branch
BranchTrueFalseTotal
if not @{$data->[$row];} and $config->{"skipempty"} 0 420 420
Condition33%1/3
not @{$data->[$row];} and $config->{"skipempty"}
!ll&&!rl&&r
42000
MC/DC0%0/2
not @{$data->[$row];} and $config->{"skipempty"}
not @{$data->[$row];} $config->{"skipempty"}
Truth table33%1/3
not(A) and B
A= not @{$data->[$row];}B= $config->{"skipempty"}
ABresult
0X0
100
111
70 # Construct array for data arrays.
71 420 my @fd = ($data->[$row]); # main data set first
72 # Add the files' sets, possibly using interpolation.
73 # This uses Text::Numeric::Data::File methods.
74 420 my $realrow = $row + $config->{rowoffset};
75 420 for my $i (0..$#{$files})
76 {
77 420 my $d = undef;
78 # Correlate via row ...
79 420 ▶ if($byrow){ $d = $files->[$i]->{data}->[$realrow]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($byrow) { } 20 400 420
80 # Interpolation is possible if configured.
81 else
82 {
83 400 $d = $files->[$i]->set_of($fd[0]->[$bycol], $fromcol[$i]);
84 }
85 420 push(@fd, $d);
86 }
87 420 my $ignore = 0;
88 # Ignore data sets that had no match in given files.
89 420 ▶ for(@fd){ if(not defined $_){ $ignore = 1; last; } }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_) 90 750 840
90 # Finally compute!
91 420 ▶ $ignore = &$ff(\@fd, $workarray, $constants) unless $ignore;
Branch: 1 branch
BranchTrueFalseTotal
unless $ignore 330 90 420
92 420 ▶ if($ignore){ push(@delete, $row); }
Branch: 1 branch
BranchTrueFalseTotal
if ($ignore) 90 330 420
93 }
94 420 return \@delete;
95 }
96  
97 3 1;
98  
99 __END__
« blib/lib/Text/NumericData/App/txdrows.pm ↑ Summary blib/lib/Text/NumericData/Stat.pm »