blib/lib/App/RecordStream/Aggregator/Internal/ForField2.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 94.2% 65 / 69 CC 8 SCAR 13.2
CC
8
Cov
100%
combine
7.0
squish
2.0
BEGIN
1.0
CRAP 3.8
« blib/lib/App/RecordStream/Operation/frommultire.pm ↑ Summary blib/lib/App/RecordStream/Operation/annotate.pm »
1 package App::RecordStream::Aggregator::Internal::ForField2;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use App::RecordStream::Aggregator::Aggregation;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use App::RecordStream::DomainLanguage::Registry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use base 'App::RecordStream::Aggregator::Aggregation';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 {
13 12 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 12 my $regex1 = shift;
15 12 my $regex2 = shift;
16 12 my $snippet = shift;
17  
18 12 my $this =
19 {
20 'REGEX1' => $regex1,
21 'REGEX2' => $regex2,
22 'SNIPPET' => $snippet,
23 };
24  
25 12 bless $this, $class;
26  
27 12 return $this;
28 }
29  
30 sub initial
31 {
32 4 ▶ return {};
Subroutine initial: called CC=1 SCAR=0.0
Pod undocumented
33 }
34  
35 sub combine
36 {
37 40 ▶ my $this = shift;
Subroutine combine: called CC=7 SCAR=19.5
Pod undocumented
38 40 my $cookie = shift;
39 40 my $record = shift;
40  
41 40 my @field1;
42 my @field2;
43 40 for my $field (keys(%$record))
44 {
45 132 ▶ push @field1, $field if($field =~ $this->{'REGEX1'});
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /$this->{"REGEX1"}/ 64 68 132
46 132 ▶ push @field2, $field if($field =~ $this->{'REGEX2'});
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /$this->{"REGEX2"}/ 68 64 132
47 }
48  
49 40 for my $field1 (@field1)
50 {
51 64 for my $field2 (@field2)
52 {
53 112 my $fieldc = "$field1,$field2";
54  
55 112 ▶ if(!exists($cookie->{$fieldc}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $cookie->{$fieldc}) 16 96 112
56 {
57 16 my $agg = $this->{'SNIPPET'}->evaluate_as('AGGREGATOR', {'$f1' => $field1, '$f2' => $field2});
58 16 $cookie->{$fieldc} = [$agg, $agg->initial()];
59 }
60  
61 112 my ($agg, $sub_cookie) = @{$cookie->{$fieldc}};
62  
63 112 $sub_cookie = $agg->combine($sub_cookie, $record);
64  
65 112 $cookie->{$fieldc}->[1] = $sub_cookie;
66 }
67 }
68  
69 40 return $cookie;
70 }
71  
72 sub squish
73 {
74 4 ▶ my $this = shift;
Subroutine squish: called CC=2 SCAR=6.9
Pod undocumented
75 4 my $cookie = shift;
76  
77 4 for my $fieldc (keys(%$cookie))
78 {
79 16 my ($agg, $sub_cookie) = @{$cookie->{$fieldc}};
80 16 $cookie->{$fieldc} = $agg->squish($sub_cookie);
81 }
82  
83 4 return $cookie;
84 }
85  
86 6 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new', 'for_field', 'SCALAR', 'SCALAR', 'SNIPPET');
87  
88 6 1;
« blib/lib/App/RecordStream/Operation/frommultire.pm ↑ Summary blib/lib/App/RecordStream/Operation/annotate.pm »