File Coverage

blib/lib/App/RecordStream/Deaggregator/Unhash.pm
Criterion Covered Total %
statement 37 47 78.7
branch 2 2 100.0
condition n/a
subroutine 9 12 75.0
pod 0 6 0.0
total 48 67 71.6


line stmt bran cond sub pod time code
1             package App::RecordStream::Deaggregator::Unhash;
2              
3 1     1   1090 use strict;
  1         2  
  1         31  
4 1     1   8 use warnings;
  1         4  
  1         45  
5              
6 1     1   9 use App::RecordStream::Deaggregator::Field;
  1         3  
  1         47  
7 1     1   10 use App::RecordStream::Deaggregator;
  1         4  
  1         24  
8 1     1   4 use App::RecordStream::DomainLanguage::Registry;
  1         2  
  1         20  
9              
10 1     1   5 use base 'App::RecordStream::Deaggregator::Field';
  1         3  
  1         402  
11              
12             sub new
13             {
14 2     2 0 10 my $class = shift;
15 2         8 my $old_field = shift;
16 2         8 my $new_key_field = shift;
17 2         7 my $new_value_field = shift;
18              
19 2         24 my $this = $class->SUPER::new($old_field);
20              
21 2         20 $this->{'new_key_field'} = $new_key_field;
22 2         10 $this->{'new_value_field'} = $new_value_field;
23              
24 2         19 return $this;
25             }
26              
27             sub new_from_valuation
28             {
29 0     0 0 0 my $class = shift;
30 0         0 my $valuation = shift;
31 0         0 my $new_key_field = shift;
32 0         0 my $new_value_field = shift;
33              
34 0         0 my $this = $class->SUPER::new_from_valuation($valuation);
35              
36 0         0 $this->{'new_key_field'} = $new_key_field;
37 0         0 $this->{'new_value_field'} = $new_value_field;
38              
39 0         0 return $this;
40             }
41              
42             sub deaggregate_field
43             {
44 2     2 0 7 my $this = shift;
45 2         6 my $hashref = shift;
46              
47 2         8 my @ret;
48              
49 2         19 for my $key (sort(keys(%$hashref)))
50             {
51 4         13 my $record = {};
52 4         20 $record->{$this->{'new_key_field'}} = $key;
53 4 100       16 if(defined($this->{'new_value_field'}))
54             {
55 2         10 $record->{$this->{'new_value_field'}} = $hashref->{$key};
56             }
57 4         15 push @ret, $record;
58             }
59              
60 2         16 return \@ret;
61             }
62              
63             sub long_usage
64             {
65 0     0 0 0 return <
66             Usage: unhash,,[,]
67             Split the hash into key/value \"pair\" records
68             EOF
69             }
70              
71             sub short_usage
72             {
73 0     0 0 0 return "split the provided hash";
74             }
75              
76             sub argct
77             {
78 2     2 0 14 return [2, 3];
79             }
80              
81             App::RecordStream::Deaggregator->register_implementation('unhash', __PACKAGE__);
82              
83             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'unhash', 'VALUATION', 'SCALAR');
84             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'unhash', 'VALUATION', 'SCALAR', 'SCALAR');
85              
86             1;