File Coverage

blib/lib/App/RecordStream/Aggregator/ValuesToKeys.pm
Criterion Covered Total %
statement 12 22 54.5
branch n/a
condition n/a
subroutine 4 9 44.4
pod 0 5 0.0
total 16 36 44.4


line stmt bran cond sub pod time code
1             package App::RecordStream::Aggregator::ValuesToKeys;
2              
3             our $VERSION = "4.0.24";
4              
5 5     5   2282 use strict;
  5         12  
  5         120  
6 5     5   23 use warnings;
  5         9  
  5         102  
7              
8 5     5   28 use App::RecordStream::Aggregator;
  5         11  
  5         107  
9 5     5   22 use base qw(App::RecordStream::Aggregator::MapReduce::FieldSet);
  5         9  
  5         1054  
10              
11             #sub new -- passed through
12              
13             #sub new_from_valuation -- passed through
14              
15             sub map_fields {
16 0     0 0   my ($this, $key, $value) = @_;
17 0           return { $key => $value };
18             }
19              
20             sub reduce {
21 0     0 0   my ($this, $cookie1, $cookie2) = @_;
22              
23 0           foreach my $key (keys %$cookie2 ) {
24 0           my $value = $cookie2->{$key};
25 0           $cookie1->{$key} = $value;
26             }
27              
28 0           return $cookie1;
29             }
30              
31             sub long_usage {
32 0     0 0   return <
33             Usage: valuestokeys,,
34             Take the specified keyfield, use its value as the key for the value of value
35             field.. For instance:
36             { k: 'FOO', t: 2 }
37             { k: 'BAR', t: 5 }
38              
39             becomes:
40             { 'FOO': 2, 'BAR': 5 }
41              
42             with the aggregator 'vk,k,t'. Repeated keyfield values will clobber earlier
43             instances
44             EOF
45             }
46              
47             sub short_usage {
48 0     0 0   return "use one key-value as a key for a different value in the record";
49             }
50              
51             sub argct {
52 0     0 0   return 2;
53             }
54              
55             App::RecordStream::Aggregator->register_implementation('valuestokeys', __PACKAGE__);
56             App::RecordStream::Aggregator->register_implementation('vk', __PACKAGE__);
57              
58             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'valuestokeys', 'VALUATION', 'VALUATION');
59             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'vk', 'VALUATION', 'VALUATION');
60              
61             1;