/
CountBy.pm
67 lines (49 loc) · 1.3 KB
/
CountBy.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package App::RecordStream::Aggregator::CountBy;
our $VERSION = "4.0.22";
use strict;
use warnings;
use App::RecordStream::Aggregator::InjectInto::Field;
use App::RecordStream::DomainLanguage::Registry;
use base qw(App::RecordStream::Aggregator::InjectInto::Field);
#sub new -- passed through
#sub new_from_valuation -- passed through
sub initial
{
return {};
}
sub combine_field
{
my $this = shift;
my $cookie = shift;
my $value = shift;
$cookie->{$value}++;
return $cookie;
}
sub squish
{
my $this = shift;
my $cookie = shift;
return $cookie;
}
sub short_usage
{
return "counts by unique value for a field";
}
sub long_usage
{
return <<EOF;
Usage: cb,<field>
Returns a list of uniq values associated with their counts.
Unlike most other aggregators, the value of the field returned will actually
be a hash, with keys of uniq fields, and values of the counts.
EOF
}
sub argct
{
return 1;
}
App::RecordStream::Aggregator->register_implementation('countby', __PACKAGE__);
App::RecordStream::Aggregator->register_implementation('cb', __PACKAGE__);
App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'countby', 'VALUATION');
App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'cb', 'VALUATION');
1;