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   849 use strict;
  1         3  
  1         23  
4 1     1   5 use warnings;
  1         1  
  1         21  
5              
6 1     1   4 use App::RecordStream::Deaggregator::Field;
  1         2  
  1         15  
7 1     1   4 use App::RecordStream::Deaggregator;
  1         2  
  1         13  
8 1     1   5 use App::RecordStream::DomainLanguage::Registry;
  1         1  
  1         17  
9              
10 1     1   4 use base 'App::RecordStream::Deaggregator::Field';
  1         1  
  1         293  
11              
12             sub new
13             {
14 2     2 0 5 my $class = shift;
15 2         4 my $old_field = shift;
16 2         4 my $new_key_field = shift;
17 2         4 my $new_value_field = shift;
18              
19 2         10 my $this = $class->SUPER::new($old_field);
20              
21 2         9 $this->{'new_key_field'} = $new_key_field;
22 2         4 $this->{'new_value_field'} = $new_value_field;
23              
24 2         9 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 4 my $this = shift;
45 2         4 my $hashref = shift;
46              
47 2         4 my @ret;
48              
49 2         10 for my $key (sort(keys(%$hashref)))
50             {
51 4         8 my $record = {};
52 4         10 $record->{$this->{'new_key_field'}} = $key;
53 4 100       12 if(defined($this->{'new_value_field'}))
54             {
55 2         6 $record->{$this->{'new_value_field'}} = $hashref->{$key};
56             }
57 4         8 push @ret, $record;
58             }
59              
60 2         7 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 6 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;