| 1 | package App::RecordStream::Clumper::Window; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use App::RecordStream::Clumper::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use App::RecordStream::DomainLanguage::Registry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use base 'App::RecordStream::Clumper::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | sub new | ||||||||||
| 12 | { | ||||||||||
| 13 | 2 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 14 | 2 | my $size = shift; | |||||||||
| 15 | |||||||||||
| 16 | 2 | my $this = | |||||||||
| 17 | { | ||||||||||
| 18 | 'size' => $size, | ||||||||||
| 19 | }; | ||||||||||
| 20 | 2 | bless $this, $class; | |||||||||
| 21 | |||||||||||
| 22 | 2 | return $this; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | sub long_usage | ||||||||||
| 26 | { | ||||||||||
| 27 | 0 | ▶ | return <<EOF; | ||||||||
|
Subroutine
long_usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 28 | Usage: window,<size> | ||||||||||
| 29 | Clump records by a rolling window of size <size>. The windows are strict | ||||||||||
| 30 | (that is partial windows are not given at the beginning or end). For | ||||||||||
| 31 | example, if there are five input records (1, 2, 3, 4, 5) and the window is | ||||||||||
| 32 | 3, then the first clump will be (1, 2, 3), the second (2, 3, 4) and the | ||||||||||
| 33 | third and final (3, 4, 5). | ||||||||||
| 34 | EOF | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub short_usage | ||||||||||
| 38 | { | ||||||||||
| 39 | 2 | ▶ | return "clump records by a rolling window"; | ||||||||
|
Subroutine
short_usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub argct | ||||||||||
| 43 | { | ||||||||||
| 44 | 2 | ▶ | return 1; | ||||||||
|
Subroutine
argct: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | sub clumper_begin | ||||||||||
| 48 | { | ||||||||||
| 49 | 5 | ▶ | my $this = shift; | ||||||||
|
Subroutine
clumper_begin: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 50 | 5 | my $bucket = shift; | |||||||||
| 51 | |||||||||||
| 52 | 5 | return [$bucket, []]; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | sub clumper_push_record | ||||||||||
| 56 | { | ||||||||||
| 57 | 19 | ▶ | my $this = shift; | ||||||||
|
Subroutine
clumper_push_record: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 58 | 19 | my $cookie = shift; | |||||||||
| 59 | 19 | my $record = shift; | |||||||||
| 60 | 19 | my $next = shift; | |||||||||
| 61 | |||||||||||
| 62 | 19 | my $bucket = $cookie->[0]; | |||||||||
| 63 | 19 | my $window = $cookie->[1]; | |||||||||
| 64 | |||||||||||
| 65 | 19 | push @$window, $record; | |||||||||
| 66 | 19 | ▶ | if(@$window > $this->{'size'}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | { | ||||||||||
| 68 | 7 | shift @$window; | |||||||||
| 69 | } | ||||||||||
| 70 | 19 | ▶ | if(@$window >= $this->{'size'}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | { | ||||||||||
| 72 | 10 | my $next_cookie = $next->clumper_callback_begin($bucket); | |||||||||
| 73 | 10 | for my $record (@$window) | |||||||||
| 74 | { | ||||||||||
| 75 | 30 | $next->clumper_callback_push_record($next_cookie, $record); | |||||||||
| 76 | } | ||||||||||
| 77 | 10 | $next->clumper_callback_end($next_cookie); | |||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | sub clumper_end | ||||||||||
| 82 | ▶ | { | |||||||||
|
Subroutine
clumper_end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 83 | # ignore | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 5 | App::RecordStream::Clumper->register_implementation('window', __PACKAGE__); | |||||||||
| 87 | |||||||||||
| 88 | 5 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new', 'window', 'SCALAR'); | |||||||||
| 89 | |||||||||||
| 90 | 5 | 1; | |||||||||