File Coverage

blib/lib/App/RecordStream/DomainLanguage/Library.pm
Criterion Covered Total %
statement 89 91 97.8
branch 3 4 75.0
condition 4 6 66.6
subroutine 29 30 96.6
pod 0 2 0.0
total 125 133 93.9


line stmt bran cond sub pod time code
1             package App::RecordStream::DomainLanguage::Library;
2              
3 6     6   1026 use strict;
  6         14  
  6         148  
4 6     6   21 use warnings;
  6         10  
  6         123  
5              
6 6     6   2110 use App::RecordStream::Aggregator::InjectInto::Subrefs;
  6         14  
  6         127  
7 6     6   746 use App::RecordStream::DomainLanguage::Registry;
  6         17  
  6         116  
8 6     6   27 use App::RecordStream::DomainLanguage::Snippet;
  6         10  
  6         87  
9 6     6   22 use App::RecordStream::DomainLanguage::Valuation::KeySpec;
  6         8  
  6         89  
10 6     6   25 use App::RecordStream::DomainLanguage::Valuation::Sub;
  6         6  
  6         80  
11 6     6   74 use App::RecordStream::DomainLanguage::Value;
  6         10  
  6         5486  
12              
13             sub _identity
14             {
15 0     0   0 return $_[0];
16             }
17              
18             App::RecordStream::DomainLanguage::Registry::register_fn(\&_identity, 'type_agg', 'AGGREGATOR');
19             App::RecordStream::DomainLanguage::Registry::register_fn(\&_identity, 'type_valuation', 'VALUATION');
20             App::RecordStream::DomainLanguage::Registry::register_fn(\&_identity, 'type_scalar', 'SCALAR');
21              
22             sub _snippet_upgrade
23             {
24 147     147   216 my $snippet = shift;
25              
26 147         308 my $ret = App::RecordStream::DomainLanguage::Value->new();
27 147     28   816 $ret->add_possibility('VALUATION', App::RecordStream::DomainLanguage::Valuation::Sub->new(sub { return $snippet->evaluate_as('SCALAR', {'$r' => $_[0]}); }));
  28         94  
28 147         391 $ret->add_possibility('SNIPPET', $snippet);
29 147         291 return $ret;
30             }
31              
32             App::RecordStream::DomainLanguage::Registry::register_fn(\&_snippet_upgrade, 'snip', 'SNIPPET');
33              
34             sub _rec_valuation
35             {
36 2     2   6 return App::RecordStream::DomainLanguage::Valuation::Sub->new(sub { return $_[0]; });
  3     3   37  
37             }
38              
39             App::RecordStream::DomainLanguage::Registry::register_fn(\&_rec_valuation, 'record');
40             App::RecordStream::DomainLanguage::Registry::register_fn(\&_rec_valuation, 'rec');
41              
42             sub _raw_valuation
43             {
44 1     1   2 my $v = shift;
45              
46 1 50       11 if(ref($v) eq "CODE")
47             {
48 1         5 return App::RecordStream::DomainLanguage::Valuation::Sub->new($v);
49             }
50              
51 0         0 return App::RecordStream::DomainLanguage::Valuation::KeySpec->new($v);
52             }
53              
54             App::RecordStream::DomainLanguage::Registry::register_fn(\&_raw_valuation, 'valuation', 'SCALAR');
55             App::RecordStream::DomainLanguage::Registry::register_fn(\&_raw_valuation, 'val', 'SCALAR');
56              
57             sub inject_into_aggregator
58             {
59 37     37 0 62 my $initial_snippet = shift;
60 37         45 my $combine_snippet = shift;
61 37   66     93 my $squish_snippet = shift || App::RecordStream::DomainLanguage::Snippet->new('$a');
62              
63             my $initial_sub = sub
64             {
65 13     13   42 return $initial_snippet->evaluate_as('SCALAR');
66 37         142 };
67              
68             my $combine_sub = sub
69             {
70 43     43   74 my $cookie = shift;
71 43         57 my $record = shift;
72              
73 43         154 return $combine_snippet->evaluate_as('SCALAR', {'$a' => $cookie, '$r' => $record});
74 37         136 };
75              
76             my $squish_sub = sub
77             {
78 13     13   25 my $cookie = shift;
79              
80 13         56 return $squish_snippet->evaluate_as('SCALAR', {'$a' => $cookie});
81 37         131 };
82              
83 37         152 return App::RecordStream::Aggregator::InjectInto::Subrefs->new($initial_sub, $combine_sub, $squish_sub);
84             }
85              
86             for my $ii_name ('ii', 'inject_into')
87             {
88             for my $agg_name ('agg', 'aggregator')
89             {
90             App::RecordStream::DomainLanguage::Registry::register_fn(\&inject_into_aggregator, $ii_name . '_' . $agg_name, 'SNIPPET', 'SNIPPET');
91             App::RecordStream::DomainLanguage::Registry::register_fn(\&inject_into_aggregator, $ii_name . '_' . $agg_name, 'SNIPPET', 'SNIPPET', 'SNIPPET');
92             }
93             }
94              
95             sub map_reduce_aggregator
96             {
97 43     43 0 67 my $map_snippet = shift;
98 43         84 my $reduce_snippet = shift;
99 43   66     121 my $squish_snippet = shift || App::RecordStream::DomainLanguage::Snippet->new('$a');
100              
101             my $map_sub = sub
102             {
103 49     49   74 my $record = shift;
104              
105 49         161 return $map_snippet->evaluate_as('SCALAR', {'$r' => $record});
106 43         216 };
107              
108             my $reduce_sub = sub
109             {
110 31     31   55 my $cookie1 = shift;
111 31         44 my $cookie2 = shift;
112              
113 31         126 return $reduce_snippet->evaluate_as('SCALAR', {'$a' => $cookie1, '$b' => $cookie2});
114 43         152 };
115              
116             my $squish_sub = sub
117             {
118 15     15   32 my $cookie = shift;
119              
120 15         66 return $squish_snippet->evaluate_as('SCALAR', {'$a' => $cookie});
121 43         139 };
122              
123 43         191 return App::RecordStream::Aggregator::MapReduce::Subrefs->new($map_sub, $reduce_sub, $squish_sub);
124             }
125              
126             for my $mr_name ('mr', 'map_reduce')
127             {
128             for my $agg_name ('agg', 'aggregator')
129             {
130             App::RecordStream::DomainLanguage::Registry::register_fn(\&map_reduce_aggregator, $mr_name . '_' . $agg_name, 'SNIPPET', 'SNIPPET');
131             App::RecordStream::DomainLanguage::Registry::register_fn(\&map_reduce_aggregator, $mr_name . '_' . $agg_name, 'SNIPPET', 'SNIPPET', 'SNIPPET');
132             }
133             }
134              
135             sub _subset_agg
136             {
137 6     6   9 my $match_snippet = shift;
138 6         9 my $aggregator = shift;
139              
140             my $initial_sub = sub
141             {
142 2     2   9 return $aggregator->initial();
143 6         23 };
144              
145             my $combine_sub = sub
146             {
147 12     12   19 my $cookie = shift;
148 12         16 my $record = shift;
149              
150 12 100       35 if($match_snippet->evaluate_as('SCALAR', {'$r' => $record}))
151             {
152 6         22 $cookie = $aggregator->combine($cookie, $record);
153             }
154              
155 12         47 return $cookie;
156 6         24 };
157              
158             my $squish_sub = sub
159             {
160 2     2   4 my $cookie = shift;
161              
162 2         9 return $aggregator->squish($cookie);
163 6         17 };
164              
165 6         25 return App::RecordStream::Aggregator::InjectInto::Subrefs->new($initial_sub, $combine_sub, $squish_sub);
166             }
167              
168             App::RecordStream::DomainLanguage::Registry::register_fn(\&_subset_agg, 'subset_aggregator', 'SNIPPET', 'AGGREGATOR');
169             App::RecordStream::DomainLanguage::Registry::register_fn(\&_subset_agg, 'subset_agg', 'SNIPPET', 'AGGREGATOR');
170              
171             sub _xform_agg
172             {
173 3     3   5 my $aggregator = shift;
174 3         7 my $snippet = shift;
175              
176             my $initial_sub = sub
177             {
178 1     1   11 return $aggregator->initial();
179 3         9 };
180              
181             my $combine_sub = sub
182             {
183 3     3   7 my $cookie = shift;
184 3         4 my $record = shift;
185              
186 3         8 return $aggregator->combine($cookie, $record);
187 3         10 };
188              
189             my $squish_sub = sub
190             {
191 1     1   3 my $cookie = shift;
192              
193 1         6 my $result = $aggregator->squish($cookie);
194              
195 1         5 return $snippet->evaluate_as('SCALAR', {'$r' => $result});
196 3         10 };
197              
198 3         10 return App::RecordStream::Aggregator::InjectInto::Subrefs->new($initial_sub, $combine_sub, $squish_sub);
199             }
200              
201             App::RecordStream::DomainLanguage::Registry::register_fn(\&_xform_agg, 'xform', 'AGGREGATOR', 'SNIPPET');
202              
203             1;