blib/lib/App/RecordStream/Operation/decollate.pm

filter: Statementstmt 88.1% 67 / 76 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 16 / 20 Podpod 0.0% 0 / 7 totaltotal 76.7% 89 / 116 CC 8 SCAR 7.8
CC
8
Cov
84%
init
4.4
print_usage
3.8
accept_record_aux
3.0
CRAP 2.2
« blib/lib/App/RecordStream/Operation/fromkv.pm ↑ Summary blib/lib/App/RecordStream/Operation/tohtml.pm »
1 package App::RecordStream::Operation::decollate;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use App::RecordStream::Deaggregator;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use App::RecordStream::DomainLanguage::Library;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use App::RecordStream::DomainLanguage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use App::RecordStream::Operation;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use App::RecordStream::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use base 'App::RecordStream::Operation';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub init
15 {
16 7 ▶ my $this = shift;
Subroutine init: called CC=4 SCAR=14.7
Pod undocumented
17 7 my $args = shift;
18  
19 7 App::RecordStream::Deaggregator->load_implementations();
20  
21 7 my @deaggregators;
22 my @dldeaggregators;
23 7 my $list_deaggregators = 0;
24 7 my $deaggregator = 0;
25  
26 my $spec =
27 {
28 7 ▶ "deaggregator|d=s" => sub { push @deaggregators, split(/:/, $_[1]); },
Subroutine __ANON__: called CC=1 SCAR=0.0
29 0 ▶ "dldeaggregator=s" => sub { push @dldeaggregators, build_dldeaggregator($_[1]); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 7 "list-deaggregators" => \$list_deaggregators,
31 "show-deaggregator=s" => \$deaggregator,
32 };
33  
34 7 $this->parse_options($args, $spec);
35  
36 6 ▶ if($list_deaggregators)
Branch: 1 branch
BranchTrueFalseTotal
if ($list_deaggregators) 0 6 6
37 {
38 0 ▶ die sub { print App::RecordStream::Deaggregator->list_implementations(); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 }
40  
41 6 ▶ if($deaggregator)
Branch: 1 branch
BranchTrueFalseTotal
if ($deaggregator) 0 6 6
42 {
43 0 ▶ die sub { App::RecordStream::Deaggregator->show_implementation($deaggregator) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 }
45  
46 6 my @deaggregator_objects;
47 6 for my $spec (@deaggregators)
48 {
49 7 push @deaggregator_objects, App::RecordStream::Deaggregator->make_deaggregator($spec);
50 }
51  
52 6 @deaggregator_objects = (@deaggregator_objects, @dldeaggregators);
53  
54 6 $this->{'DEAGGREGATORS'} = \@deaggregator_objects;
55 }
56  
57 sub build_dldeaggregator
58 {
59 0 ▶ my $string = shift;
Subroutine build_dldeaggregator: not called CC=1 SCAR=6.9
Pod undocumented
60  
61 0 return App::RecordStream::DomainLanguage::Snippet->new($string)->evaluate_as('DEAGGREGATOR');
62 }
63  
64 sub accept_record
65 {
66 11 ▶ my $this = shift;
Subroutine accept_record: called CC=1 SCAR=0.0
Pod undocumented
67 11 my $record = shift;
68  
69 11 $this->accept_record_aux(0, $record);
70  
71 11 return 1;
72 }
73  
74 sub accept_record_aux
75 {
76 50 ▶ my $this = shift;
Subroutine accept_record_aux: called CC=3 SCAR=11.0
Pod undocumented
77 50 my $depth = shift;
78 50 my $record = shift;
79  
80 50 ▶ if($depth < @{$this->{'DEAGGREGATORS'}})
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < @{$this->{'DEAGGREGATORS'};}) { } 17 33 50
81 {
82 17 my $deaggregator = $this->{'DEAGGREGATORS'}->[$depth];
83  
84 17 for my $deaggregated_record (@{$deaggregator->deaggregate($record)})
85 {
86 39 $this->accept_record_aux($depth + 1, App::RecordStream::Record->new({%$record, %$deaggregated_record}));
87 }
88 }
89 else
90 {
91 33 $this->push_record($record);
92 }
93 }
94  
95 sub print_usage
96 {
97 1 ▶ my $this = shift;
Subroutine print_usage: called CC=3 SCAR=13.5
Pod undocumented
98 1 my $message = shift;
99  
100 1 ▶ if($message && UNIVERSAL::isa($message, 'CODE')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message and UNIVERSAL::isa($message, "CODE")) 0 1 1
Condition33%1/3
$message and UNIVERSAL::isa($message, "CODE")
!ll&&!rl&&r
100
MC/DC0%0/2
$message and UNIVERSAL::isa($message, "CODE")
$message UNIVERSAL::isa($message, "CODE")
Truth table33%1/3
A and B
A= $messageB= UNIVERSAL::isa($message, "CODE")
ABresult
0X0
100
111
101 0 $message->();
102 0 exit(1);
103 }
104  
105 1 $this->SUPER::print_usage($message);
106 }
107  
108 sub add_help_types
109 {
110 7 ▶ my $this = shift;
Subroutine add_help_types: called CC=1 SCAR=0.0
Pod undocumented
111 7 $this->use_help_type('domainlanguage');
112 $this->add_help_type(
113 'deaggregators',
114 1 ▶ sub { print App::RecordStream::Deaggregator->list_implementations(); },
Subroutine __ANON__: called CC=1 SCAR=0.0
115 7 'List the deaggregators'
116 );
117 }
118  
119 sub usage {
120 1 ▶ my $this = shift;
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
121  
122 1 my $options = [
123 [ 'dldeaggregator ...', 'Specify a domain language aggregate. See "Domain Language Integration" below.'],
124 [ 'deaggregator|-d <deaggregators>', 'Colon separated list of aggregate field specifiers. See "Deaggregates" section below.'],
125 [ 'list-deaggregators', 'Bail and output a list of deaggregators.'],
126 [ 'show-deaggregator <deaggregator>', 'Bail and output this deaggregator\'s detailed usage.'],
127 ];
128  
129 1 my $args_string = $this->options_string($options);
130 return <<USAGE
131 Usage: recs-decollate <args> [<files>]
132 __FORMAT_TEXT__
133 Decollate records of input (or records from <files>) into output records.
134 __FORMAT_TEXT__
135  
136 Arguments:
137 $args_string
138  
139 Deaggregates:
140 __FORMAT_TEXT__
141 Deaggregates are specified as <deaggregator>[,<arguments>]. See
142 --list-deaggregators for a list of available deaggregators.
143  
144 In general, key name arguments to deaggregators may be key specs, but not
145 key groups
146 __FORMAT_TEXT__
147  
148 Domain Lanuage Integration:
149 USAGE
150 1 . App::RecordStream::DomainLanguage::short_usage()
151 . <<USAGE
152  
153 __FORMAT_TEXT__
154 Deaggregates may be specified using the recs domain language.
155 --dldeaggregator requires the code evaluate as a deaggregator.
156  
157 See --help-domainlanguage for a more complete description of its workings
158 and a list of available functions.
159  
160 See the examples below for a more gentle introduction.
161 __FORMAT_TEXT__
162  
163 Examples:
164 Split the "hosts" field into individual "host" fields
165 recs-decollate --dldeaggregator '_split(hosts,qr/, */,host)'
166 USAGE
167 ;
168 }
169  
170 2 1;
« blib/lib/App/RecordStream/Operation/fromkv.pm ↑ Summary blib/lib/App/RecordStream/Operation/tohtml.pm »