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

filter: Statementstmt 100% 44 / 44 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 93.4% 57 / 61 CC 5 SCAR 7.3
CC
5
Cov
100%
combine
4.0
squish
2.0
BEGIN
1.0
CRAP 2.1
« blib/lib/App/RecordStream/Operation/topn.pm ↑ Summary blib/lib/App/RecordStream/LRUSheriff.pm »
1 package App::RecordStream::Aggregator::Internal::ForField;
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 6 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 6 my $regex = shift;
15 6 my $snippet = shift;
16  
17 6 my $this =
18 {
19 'REGEX' => $regex,
20 'SNIPPET' => $snippet,
21 };
22  
23 6 bless $this, $class;
24  
25 6 return $this;
26 }
27  
28 sub initial
29 {
30 2 ▶ return {};
Subroutine initial: called CC=1 SCAR=0.0
Pod undocumented
31 }
32  
33 sub combine
34 {
35 8 ▶ my $this = shift;
Subroutine combine: called CC=4 SCAR=13.9
Pod undocumented
36 8 my $cookie = shift;
37 8 my $record = shift;
38  
39 8 for my $field (keys(%$record))
40 {
41 16 ▶ next unless($field =~ $this->{'REGEX'});
Branch: 1 branch
BranchTrueFalseTotal
unless $field =~ /$this->{"REGEX"}/ 8 8 16
42  
43 8 ▶ if(!exists($cookie->{$field}))
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $cookie->{$field}) 4 4 8
44 {
45 4 my $agg = $this->{'SNIPPET'}->evaluate_as('AGGREGATOR', {'$f' => $field});
46 4 $cookie->{$field} = [$agg, $agg->initial()];
47 }
48  
49 8 my ($agg, $sub_cookie) = @{$cookie->{$field}};
50  
51 8 $sub_cookie = $agg->combine($sub_cookie, $record);
52  
53 8 $cookie->{$field}->[1] = $sub_cookie;
54 }
55  
56 8 return $cookie;
57 }
58  
59 sub squish
60 {
61 2 ▶ my $this = shift;
Subroutine squish: called CC=2 SCAR=6.9
Pod undocumented
62 2 my $cookie = shift;
63  
64 2 for my $field (keys(%$cookie))
65 {
66 4 my ($agg, $sub_cookie) = @{$cookie->{$field}};
67 4 $cookie->{$field} = $agg->squish($sub_cookie);
68 }
69  
70 2 return $cookie;
71 }
72  
73 6 App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new', 'for_field', 'SCALAR', 'SNIPPET');
74  
75 6 1;
« blib/lib/App/RecordStream/Operation/topn.pm ↑ Summary blib/lib/App/RecordStream/LRUSheriff.pm »