File Coverage

blib/lib/App/RecordStream/Aggregator/CountBy.pm
Criterion Covered Total %
statement 24 27 88.8
branch n/a
condition n/a
subroutine 8 11 72.7
pod 0 6 0.0
total 32 44 72.7


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