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   1067 use strict;
  6         15  
  6         212  
4 6     6   34 use warnings;
  6         12  
  6         151  
5              
6 6     6   2146 use App::RecordStream::Aggregator::InjectInto::Subrefs;
  6         16  
  6         124  
7 6     6   650 use App::RecordStream::DomainLanguage::Registry;
  6         14  
  6         113  
8 6     6   29 use App::RecordStream::DomainLanguage::Snippet;
  6         13  
  6         94  
9 6     6   25 use App::RecordStream::DomainLanguage::Valuation::KeySpec;
  6         13  
  6         90  
10 6     6   23 use App::RecordStream::DomainLanguage::Valuation::Sub;
  6         13  
  6         85  
11 6     6   24 use App::RecordStream::DomainLanguage::Value;
  6         11  
  6         4732  
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   276 my $snippet = shift;
25              
26 147         414 my $ret = App::RecordStream::DomainLanguage::Value->new();
27 147     28   906 $ret->add_possibility('VALUATION', App::RecordStream::DomainLanguage::Valuation::Sub->new(sub { return $snippet->evaluate_as('SCALAR', {'$r' => $_[0]}); }));
  28         126  
28 147         493 $ret->add_possibility('SNIPPET', $snippet);
29 147         399 return $ret;
30             }
31              
32             App::RecordStream::DomainLanguage::Registry::register_fn(\&_snippet_upgrade, 'snip', 'SNIPPET');
33              
34             sub _rec_valuation
35             {
36 2     2   9 return App::RecordStream::DomainLanguage::Valuation::Sub->new(sub { return $_[0]; });
  3     3   24  
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       4 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 118 my $initial_snippet = shift;
60 37         71 my $combine_snippet = shift;
61 37   66     111 my $squish_snippet = shift || App::RecordStream::DomainLanguage::Snippet->new('$a');
62              
63             my $initial_sub = sub
64             {
65 13     13   49 return $initial_snippet->evaluate_as('SCALAR');
66 37         145 };
67              
68             my $combine_sub = sub
69             {
70 43     43   74 my $cookie = shift;
71 43         75 my $record = shift;
72              
73 43         179 return $combine_snippet->evaluate_as('SCALAR', {'$a' => $cookie, '$r' => $record});
74 37         130 };
75              
76             my $squish_sub = sub
77             {
78 13     13   29 my $cookie = shift;
79              
80 13         59 return $squish_snippet->evaluate_as('SCALAR', {'$a' => $cookie});
81 37         114 };
82              
83 37         154 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 88 my $map_snippet = shift;
98 43         77 my $reduce_snippet = shift;
99 43   66     163 my $squish_snippet = shift || App::RecordStream::DomainLanguage::Snippet->new('$a');
100              
101             my $map_sub = sub
102             {
103 49     49   94 my $record = shift;
104              
105 49         200 return $map_snippet->evaluate_as('SCALAR', {'$r' => $record});
106 43         196 };
107              
108             my $reduce_sub = sub
109             {
110 31     31   64 my $cookie1 = shift;
111 31         59 my $cookie2 = shift;
112              
113 31         146 return $reduce_snippet->evaluate_as('SCALAR', {'$a' => $cookie1, '$b' => $cookie2});
114 43         140 };
115              
116             my $squish_sub = sub
117             {
118 15     15   41 my $cookie = shift;
119              
120 15         79 return $squish_snippet->evaluate_as('SCALAR', {'$a' => $cookie});
121 43         141 };
122              
123 43         229 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   13 my $match_snippet = shift;
138 6         22 my $aggregator = shift;
139              
140             my $initial_sub = sub
141             {
142 2     2   14 return $aggregator->initial();
143 6         36 };
144              
145             my $combine_sub = sub
146             {
147 12     12   29 my $cookie = shift;
148 12         21 my $record = shift;
149              
150 12 100       53 if($match_snippet->evaluate_as('SCALAR', {'$r' => $record}))
151             {
152 6         39 $cookie = $aggregator->combine($cookie, $record);
153             }
154              
155 12         66 return $cookie;
156 6         45 };
157              
158             my $squish_sub = sub
159             {
160 2     2   5 my $cookie = shift;
161              
162 2         16 return $aggregator->squish($cookie);
163 6         21 };
164              
165 6         33 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   7 my $aggregator = shift;
174 3         6 my $snippet = shift;
175              
176             my $initial_sub = sub
177             {
178 1     1   10 return $aggregator->initial();
179 3         11 };
180              
181             my $combine_sub = sub
182             {
183 3     3   5 my $cookie = shift;
184 3         6 my $record = shift;
185              
186 3         11 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         6 return $snippet->evaluate_as('SCALAR', {'$r' => $result});
196 3         10 };
197              
198 3         13 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;