« blib/lib/App/RecordStream/Clumper/KeyLRU.pm
↑ Summary
blib/lib/App/RecordStream/Deaggregator/Unhash.pm »
| 1 | package App::RecordStream::Aggregator::Mode; | ||||||||||
| 2 | |||||||||||
| 3 | 7 | our $VERSION = "4.0.23"; | |||||||||
| 4 | |||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 7 | ▶ | use App::RecordStream::Aggregator::InjectInto::Field; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 7 | ▶ | use App::RecordStream::DomainLanguage::Registry; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 7 | ▶ | use base qw(App::RecordStream::Aggregator::InjectInto::Field); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | #sub new -- passed through | ||||||||||
| 14 | |||||||||||
| 15 | #sub new_from_valuation -- passed through | ||||||||||
| 16 | |||||||||||
| 17 | sub initial { | ||||||||||
| 18 | 1 | ▶ | return {}; | ||||||||
|
Subroutine
initial: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | sub combine_field | ||||||||||
| 22 | { | ||||||||||
| 23 | 9 | ▶ | my $this = shift; | ||||||||
|
Subroutine
combine_field: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 9 | my $cookie = shift; | |||||||||
| 25 | 9 | my $value = shift; | |||||||||
| 26 | |||||||||||
| 27 | 9 | $cookie->{$value}++; | |||||||||
| 28 | 9 | return $cookie; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | sub squish { | ||||||||||
| 32 | 1 | ▶ | my $this = shift; | ||||||||
|
Subroutine
squish: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 33 | 1 | my $cookie = shift; | |||||||||
| 34 | |||||||||||
| 35 | 1 | my @keys = keys %$cookie; | |||||||||
| 36 | 1 | my $max_key = shift @keys; | |||||||||
| 37 | 1 | my $max_value = $cookie->{$max_key}; | |||||||||
| 38 | |||||||||||
| 39 | 1 | foreach my $key ( @keys ) { | |||||||||
| 40 | 5 | my $value = $cookie->{$key}; | |||||||||
| 41 | 5 | ▶ | if ( $max_value < $value ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 1 | $max_key = $key; | |||||||||
| 43 | 1 | $max_value = $value; | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | return $max_key; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub short_usage | ||||||||||
| 51 | { | ||||||||||
| 52 | 1 | ▶ | return "most common value for a field"; | ||||||||
|
Subroutine
short_usage: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | sub long_usage | ||||||||||
| 56 | { | ||||||||||
| 57 | 0 | ▶ | print <<EOF; | ||||||||
|
Subroutine
long_usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | Usage: mode,<field> | ||||||||||
| 59 | Finds the most common value for a field and returns it. | ||||||||||
| 60 | Will load all values into memory. | ||||||||||
| 61 | EOF | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 7 | App::RecordStream::Aggregator->register_implementation('mode', __PACKAGE__); | |||||||||
| 65 | |||||||||||
| 66 | 7 | App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'mode', 'VALUATION'); | |||||||||
| 67 | |||||||||||
| 68 | 7 | 1; | |||||||||