| 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
| |||||||||||
| 42 | |||||||||||
| 43 | 8 | ▶ | if(!exists($cookie->{$field})) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||