blib/lib/App/RecordStream/Operation.pm

filter: Statementstmt 90.6% 262 / 289 Branchbran 75.7% 53 / 70 Conditioncond 70.0% 21 / 30 MC/DCmcdc 41.1% 7 / 17 Subroutinesub 92.7% 51 / 55 Podpod 0.0% 0 / 37 totaltotal 79.1% 394 / 498 CC 56 SCAR 14.9
CC
56
Cov
86%
main
12.7
parse_options
10.1
load_operation
7.0
CRAP 4.4
« blib/lib/App/RecordStream/Operation/fromcsv.pm ↑ Summary blib/lib/App/RecordStream/Operation/chain.pm »
1 package App::RecordStream::Operation;
2  
3 112 our $VERSION = "4.0.23";
4  
5 112 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 112 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 112 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 112 ▶use FindBin qw($Script $RealScript);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 112 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 112 ▶use Text::Autoformat;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 112 ▶use App::RecordStream::Clumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 112 ▶use App::RecordStream::DomainLanguage;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 112 ▶use App::RecordStream::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 112 ▶use App::RecordStream::KeyGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 112 ▶use App::RecordStream::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 112 ▶use App::RecordStream::Stream::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 112 ▶use App::RecordStream::Stream::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 112 ▶use base 'App::RecordStream::Stream::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 sub usage {
24 0 ▶ subclass_should_implement(shift);
Subroutine usage: not called CC=1 SCAR=6.9
Pod undocumented
25 }
26  
27 sub new {
28 212 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
29 212 my $args = shift;
30 212 my $next = shift;
31  
32 212 my $this = {
33 NEXT => $next,
34 };
35  
36 212 bless $this, $class;
37  
38 212 $this->init_help();
39 212 $this->init($args);
40 183 return $this;
41 }
42  
43 sub init_help {
44 212 ▶ my $this = shift;
Subroutine init_help: called CC=1 SCAR=0.0
Pod undocumented
45 212 $this->{'HELP_TYPES'} = {
46 all => {
47 USE => 0,
48 SKIP_IN_ALL => 1,
49 CODE => \&all_help,
50 DESCRIPTION => 'Output all help for this script',
51 },
52 snippet => {
53 USE => 0,
54 SKIP_IN_ALL => 0,
55 CODE => \&snippet_help,
56 DESCRIPTION => 'Help on code snippets',
57 },
58 keygroups => {
59 USE => 0,
60 SKIP_IN_ALL => 0,
61 CODE => \&keygroups_help,
62 DESCRIPTION => 'Help on keygroups, a way of specifying multiple keys',
63 },
64 keyspecs => {
65 USE => 0,
66 SKIP_IN_ALL => 0,
67 CODE => \&keyspecs_help,
68 DESCRIPTION => 'Help on keyspecs, a way to index deeply and with regexes',
69 },
70 basic => {
71 USE => 1,
72 SKIP_IN_ALL => 0,
73 CODE => \&basic_help,
74 OPTION_NAME => 'help',
75 DESCRIPTION => 'This help screen',
76 },
77 'keys' => {
78 USE => 0,
79 SKIP_IN_ALL => 1,
80 CODE => \&keys_help,
81 DESCRIPTION => 'Help on keygroups and keyspecs',
82 },
83 domainlanguage => {
84 USE => 0,
85 SKIP_IN_ALL => 0,
86 CODE => \&domainlanguage_help,
87 DESCRIPTION => 'Help on the recs domain language, a [very complicated] way of specifying valuations (which act like keys) or aggregators',
88 },
89 clumping => {
90 USE => 0,
91 SKIP_IN_ALL => 0,
92 CODE => \&clumping_help,
93 DESCRIPTION => 'Help on clumping; mechanisms to group records across a stream'
94 },
95 };
96  
97 212 $this->add_help_types();
98 }
99  
100 # Prints out unified options for usage. $options is a hash with keys of the
101 # argument spec and values of the description
102 sub options_string {
103 32 ▶ my ($this, $options) = @_;
Subroutine options_string: called CC=6 SCAR=17.9
Pod undocumented
104  
105 32 ▶ push @$options, ['filename-key|fk <keyspec>', 'Add a key with the source filename (if no filename is applicable will put NONE)']
Branch: 1 branch
BranchTrueFalseTotal
if $this->does_record_output 32 0 32
106 if $this->does_record_output;
107  
108 32 my $string = $this->_options_format($options);
109 32 $string .= "\n Help Options:\n";
110  
111 32 my $help_options = [];
112 32 foreach my $type (sort keys %{$this->{'HELP_TYPES'}}) {
113 266 my $info = $this->{'HELP_TYPES'}->{$type};
114 266 ▶ next unless ( $info->{'USE'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"USE"} 123 143 266
115  
116 143 ▶ my $option_name = $info->{'OPTION_NAME'} || "help-$type";
Condition100%2/2
$info->{'OPTION_NAME'} || "help-$type"
l!l
32111
MC/DC100%1/1
$info->{'OPTION_NAME'} || "help-$type"
$info->{'OPTION_NAME'}
Truth table100%2/2
A
A= $info->{'OPTION_NAME'}
Aresult
11
00
117 143 my $description = $info->{'DESCRIPTION'};
118 143 push @$help_options, [$option_name, $description];
119 }
120  
121 32 $string .= $this->_options_format($help_options, 2);
122  
123 # Remove trailing whitespace
124 32 ▶ while (chomp $string > 0) {}
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $string > 0) 32 32 64
125  
126 32 return $string;
127 }
128  
129 sub _options_format {
130 64 ▶ my ($this, $options, $indent_level) = @_;
Subroutine _options_format: called CC=5 SCAR=16.1
131 64 ▶ $indent_level = 1 if ( not defined $indent_level );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $indent_level 32 32 64
132  
133 64 my $max_length = 0;
134 64 foreach my $pair (@$options) {
135 356 my ($name) = @$pair;
136 356 my $name_length = length($name);
137 356 ▶ $max_length = $name_length if ( $name_length > $max_length);
Branch: 1 branch
BranchTrueFalseTotal
if $name_length > $max_length 164 192 356
138 }
139  
140 64 my $string = '';
141  
142 64 my $description_indent_level = ($indent_level * 3) + $max_length + 4;
143  
144 64 foreach my $pair (@$options) {
145 356 my ($name, $description) = @$pair;
146 356 my $formatted = $this->format_text($description, $description_indent_level);
147 356 my $description_prefix = (' ' x ($indent_level * 3)) . '--' . $name;
148  
149 356 $description_prefix .= ' ' x ($description_indent_level - length($description_prefix));
150  
151 356 my $prefix_size = length($description_prefix);
152 356 $string .= $description_prefix;
153 356 $string .= substr $formatted, $prefix_size;
154 }
155  
156 64 return $string;
157 }
158  
159 {
160 112 my $size_initialized = 0;
161 112 my $size = 80;
162 sub get_terminal_size {
163 637 ▶ if ( ! $size_initialized ) {
Subroutine get_terminal_size: called CC=4 SCAR=14.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless ($size_initialized) 30 607 637
164 30 $size_initialized = 1;
165 30 ▶ if (eval { require Term::ReadKey; 1 }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Term::ReadKey; 1 } }) { } 30 0 30
elsif ($ENV{'COLUMNS'}) { } 0 0 0
166 30 eval {
167 30 $size = (Term::ReadKey::GetTerminalSize())[0];
168 };
169 } elsif ($ENV{COLUMNS}) {
170 0 $size = $ENV{COLUMNS};
171 }
172 }
173 637 return $size;
174 }
175 }
176  
177 112 sub format_text {
178 637 ▶ my ($this, $text, $left_indent) = @_;
Subroutine format_text: called CC=2 SCAR=6.9
Pod undocumented
179 637 ▶ $left_indent ||= 0;
Condition100%2/2
$left_indent ||= 0
l!l
62611
MC/DC100%1/1
$left_indent ||= 0
$left_indent
Truth table100%2/2
A
A= $left_indent
Aresult
11
00
180 637 return autoformat $text, {
181 left => $left_indent + 1,
182 right => get_terminal_size(),
183 all => 1,
184 };
185 }
186  
187 # this is a hook for subclasses
188 ▶sub add_help_types {
Subroutine add_help_types: called CC=1 SCAR=0.0
Pod undocumented
189 }
190  
191 sub use_help_type {
192 454 ▶ my $this = shift;
Subroutine use_help_type: called CC=1 SCAR=0.0
Pod undocumented
193 454 my $type = shift;
194  
195 454 $this->{'HELP_TYPES'}->{$type}->{'USE'} = 1;
196 454 $this->{'HELP_TYPES'}->{'all'}->{'USE'} = 1;
197 }
198  
199 sub add_help_type {
200 65 ▶ my $this = shift;
Subroutine add_help_type: called CC=2 SCAR=7.0
Pod undocumented
201 65 my $type = shift;
202 65 my $action = shift;
203 65 my $description = shift;
204 65 my $skip_in_all = shift;
205 65 ▶ my $option_name = shift || 0;
Condition50%1/2
shift() || 0
l!l
065
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
206  
207 65 $this->{'HELP_TYPES'}->{$type} = {
208 USE => 1,
209 SKIP_IN_ALL => $skip_in_all,
210 CODE => $action,
211 OPTION_NAME => $option_name,
212 DESCRIPTION => $description,
213 };
214 }
215  
216 sub parse_options {
217 212 ▶ my $this = shift;
Subroutine parse_options: called CC=10 SCAR=23.2
Pod undocumented
218 212 ▶ my $args = shift || [];
Condition50%1/2
shift() || []
l!l
2120
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
219 212 ▶ my $options_spec = shift || {};
Condition100%2/2
shift() || {}
l!l
2102
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
220 212 ▶ my $configuration_options = shift || [];
Condition100%2/2
shift() || []
l!l
60152
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
221  
222 # Add help options
223 212 foreach my $help_type (keys %{$this->{'HELP_TYPES'}}) {
224 1761 my $type_info = $this->{'HELP_TYPES'}->{$help_type};
225 1761 ▶ next unless ( $type_info->{'USE'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $type_info->{"USE"} 831 930 1761
226  
227 930 ▶ my $help_option = $type_info->{'OPTION_NAME'} || 'help-' . $help_type;
Condition100%2/2
$type_info->{'OPTION_NAME'} || 'help-' . $help_type
l!l
212718
MC/DC100%1/1
$type_info->{'OPTION_NAME'} || 'help-' . $help_type
$type_info->{'OPTION_NAME'}
Truth table100%2/2
A
A= $type_info->{'OPTION_NAME'}
Aresult
11
00
228  
229 $options_spec->{$help_option} ||= sub {
230 28 ▶ $type_info->{'CODE'}->($this);
Subroutine __ANON__: called CC=1 SCAR=0.0
231 28 exit 1;
232 930 ▶ };
Condition33%1/3
$options_spec->{$help_option} ||= sub { $type_info->{"CODE"}->($this); exit 1; }
l!l&&r!l&&!r
09300
MC/DC0%0/2
$options_spec->{$help_option} ||= sub { $type_info->{"CODE"}->($this); exit 1; }
$options_spec->{$help_option} sub { $type_info->{"CODE"}->($this); exit 1; }
Truth table33%1/3
A ||= B
A= $options_spec->{$help_option}B= sub { $type_info->{"CODE"}->($this); exit 1; }
ABresult
1X1
011
000
233 }
234  
235 # Add filename annotation option
236 212 ▶ $options_spec->{'--filename-key|fk=s'} = \($this->{'FILENAME_KEY'})
Branch: 1 branch
BranchTrueFalseTotal
if $this->does_record_output 212 0 212
237 if $this->does_record_output;
238  
239 212 my $starting_config = Getopt::Long::Configure();
240  
241 # Push custom configuration
242 212 Getopt::Long::Configure('no_ignore_case', @$configuration_options);
243  
244 212 local @ARGV = @$args;
245 212 ▶ unless (GetOptions(%$options_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptions(%$options_spec)) 2 182 184
246 # output usage if there was a problem with option parsing
247 2 $this->_set_wants_help(1);
248 }
249  
250 # Restore original configuration
251 184 Getopt::Long::Configure($starting_config);
252  
253 184 @$args = @ARGV;
254 }
255  
256 sub update_current_filename {
257 4 ▶ my ($this, $filename) = @_;
Subroutine update_current_filename: called CC=1 SCAR=0.0
Pod undocumented
258 4 set_current_filename($filename);
259 }
260  
261 sub _set_wants_help {
262 2 ▶ my $this = shift;
Subroutine _set_wants_help: called CC=1 SCAR=0.0
263 2 my $help = shift;
264  
265 2 $this->{'WANTS_HELP'} = $help;
266 }
267  
268 sub get_wants_help {
269 25 ▶ my $this = shift;
Subroutine get_wants_help: called CC=1 SCAR=0.0
Pod undocumented
270 25 return $this->{'WANTS_HELP'};
271 }
272  
273 sub _set_exit_value {
274 0 ▶ my $this = shift;
Subroutine _set_exit_value: not called CC=1 SCAR=6.9
275 0 my $value = shift;
276  
277 0 $this->{'EXIT_VALUE'} = $value;
278 }
279  
280 sub get_exit_value {
281 3 ▶ my $this = shift;
Subroutine get_exit_value: called CC=2 SCAR=7.2
Pod undocumented
282 3 ▶ return $this->{'EXIT_VALUE'} || 0;
Condition50%1/2
$this->{'EXIT_VALUE'} || 0
l!l
03
MC/DC0%0/1
$this->{'EXIT_VALUE'} || 0
$this->{'EXIT_VALUE'}
Truth table50%1/2
A
A= $this->{'EXIT_VALUE'}
Aresult
11
00
283 }
284  
285 sub print_usage {
286 30 ▶ my $this = shift;
Subroutine print_usage: called CC=5 SCAR=18.0
Pod undocumented
287 30 my $message = shift;
288  
289 30 ▶ if ( $message ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message) 0 30 30
290 0 chomp $message;
291 0 warn "$message\n";
292  
293 0 ▶ if ( $message =~ m/FATAL/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message =~ /FATAL/) 0 0 0
294 0 return;
295 }
296 }
297  
298 30 my $usage = $this->usage();
299  
300 #Remove all trailing newlines
301 30 ▶ while (chomp $usage > 0) {}
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $usage > 0) 31 30 61
302  
303 30 my $formatted_usage = $this->format_usage($usage);
304  
305 #Remove all trailing newlines
306 30 ▶ while (chomp $formatted_usage > 0) {}
Branch: 1 branch
BranchTrueFalseTotal
if (chomp $formatted_usage > 0) 30 30 60
307  
308 30 print $formatted_usage . "\n";
309 }
310  
311 sub format_usage {
312 82 ▶ my ($this, $usage) = @_;
Subroutine format_usage: called CC=6 SCAR=17.9
Pod undocumented
313  
314 82 my $lines = [split("\n", $usage)];
315  
316 82 my $output = '';
317 82 my $capturing = 0;
318 82 my $accumulator = 0;
319 82 my $current_indent = 0;
320  
321 82 ▶ while(@$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 3731 82 3813
322 3731 my $line = shift @$lines;
323 3731 chomp $line;
324 3731 ▶ if ( $line =~ m/^\s*__FORMAT_TEXT__\s*$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\s*__FORMAT_TEXT__\s*$/) { } 562 3169 3731
elsif ($capturing) { } 1134 2035 3169
325 562 ▶ if ( $capturing ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($capturing) { } 281 281 562
326 281 $capturing = 0;
327 281 $output .= $this->format_text($accumulator, $current_indent);
328 }
329 else {
330 281 $capturing = 1;
331  
332 281 my $first_line = shift @$lines;
333 281 chomp $first_line;
334 281 my ($indention) = $first_line =~ m/^(\s*)/;
335 281 $first_line =~ s/\s*//;
336 281 $current_indent = length($indention);
337 281 $accumulator = $first_line;
338 }
339 }
340 elsif ( $capturing ) {
341 1134 ▶ if ( $line =~ m/^\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) { } 259 875 1134
342 259 $accumulator .= "\n\n";
343 }
344 else {
345 875 $line =~ s/^\s*//;
346 875 $accumulator .= " $line";
347 }
348 }
349 else {
350 2035 $output .= $line . "\n";
351 }
352 }
353  
354 82 return $output;
355 }
356  
357 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
358 }
359  
360 # subclasses can override to indicate they'll handle their own extra
361 # args and input in stream_done()
362 sub wants_input {
363 248 ▶ return 1;
Subroutine wants_input: called CC=1 SCAR=0.0
Pod undocumented
364 }
365  
366 sub does_record_output {
367 244 ▶ return 1;
Subroutine does_record_output: called CC=1 SCAR=0.0
Pod undocumented
368 }
369  
370 sub finish {
371 171 ▶ my $this = shift;
Subroutine finish: called CC=1 SCAR=0.0
Pod undocumented
372 171 $this->stream_done();
373 169 $this->{'NEXT'}->finish();
374 }
375  
376 {
377 112 my $filename;
378 sub get_current_filename {
379 196 ▶ return $filename || 'NONE';
Subroutine get_current_filename: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
$filename || 'NONE'
l!l
17917
MC/DC100%1/1
$filename || 'NONE'
$filename
Truth table100%2/2
A
A= $filename
Aresult
11
00
380 }
381  
382 sub set_current_filename {
383 404 ▶ my $name = shift;
Subroutine set_current_filename: called CC=1 SCAR=0.0
Pod undocumented
384 404 $filename = $name;
385 }
386 }
387  
388 112 sub subclass_should_implement {
389 0 ▶ my $this = shift;
Subroutine subclass_should_implement: not called CC=1 SCAR=6.9
Pod undocumented
390 0 croak "Subclass should implement: " . ref($this);
391 }
392  
393 ▶sub stream_done {
Subroutine stream_done: called CC=1 SCAR=0.0
Pod undocumented
394 }
395  
396 sub push_record {
397 479 ▶ my ($this, $record) = @_;
Subroutine push_record: called CC=2 SCAR=6.9
Pod undocumented
398  
399 479 ▶ if ( $this->{'FILENAME_KEY'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FILENAME_KEY"}) 14 465 479
400 14 ${$record->guess_key_from_spec($this->{'FILENAME_KEY'})} = get_current_filename();
401 }
402  
403 479 return $this->{'NEXT'}->accept_record($record);
404 }
405  
406 sub push_line {
407 482 ▶ my ($this, $line) = @_;
Subroutine push_line: called CC=1 SCAR=0.0
Pod undocumented
408 482 $this->{'NEXT'}->accept_line($line);
409 }
410  
411 sub load_operation {
412 92 ▶ my $script = shift;
Subroutine load_operation: called CC=7 SCAR=19.5
Pod undocumented
413  
414 92 my $operation = $script;
415  
416 92 ▶ die "Script not named recs-*: $script" unless ( $script =~ s/^recs-// );
Branch: 1 branch
BranchTrueFalseTotal
unless $script =~ s/^recs-// 0 92 92
417  
418 92 my @modules = ("App::RecordStream::Operation::$script");
419 92 App::RecordStream::Site::bootstrap();
420 92 my @sites = sort { $a->{'priority'} <=> $b->{'priority'} } App::RecordStream::Site::list_sites();
421 92 for my $site (@sites)
422 {
423 0 unshift @modules, $site->{'path'} . "::Operation::$script";
424 }
425  
426 92 my $module;
427 my @errors;
428 92 for my $try_module (@modules)
429 {
430 92 eval "require $try_module";
431 92 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 10 82 92
432 10 ▶ if ($@ =~ m/^Please install missing/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /^Please install missing/) 8 2 10
433 8 warn $@;
434 8 exit 1;
435 }
436 2 push @errors, "Could not load $try_module: $@";
437 }
438 else {
439 82 $module = $try_module;
440 82 last;
441 }
442 }
443 84 ▶ if(!$module) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 2 82 84
444 2 die "Could not find operation $script:\n" . join("", @errors);
445 }
446  
447 82 return $module;
448 }
449  
450 sub is_recs_operation {
451 33 ▶ my $script = shift;
Subroutine is_recs_operation: called CC=3 SCAR=11.0
Pod undocumented
452  
453 33 ▶ if ( $script =~ m/^recs-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script =~ /^recs-/) 28 5 33
454 28 eval { load_operation($script) };
455 28 ▶ return 0 if ( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28 28
456 28 return 1;
457 }
458  
459 5 return 0;
460 }
461  
462 sub create_operation {
463 64 ▶ my $script = shift;
Subroutine create_operation: called CC=5 SCAR=16.5
Pod undocumented
464 64 my $args = shift;
465 64 ▶ my $next = shift || App::RecordStream::Stream::Printer->new();
Condition66%2/3
shift() || 'App::RecordStream::Stream::Printer'->new
l!l&&r!l&&!r
20440
MC/DC0%0/2
shift() || 'App::RecordStream::Stream::Printer'->new
shift() 'App::RecordStream::Stream::Printer'->new
Truth table66%2/3
A || B
A= shift()B= 'App::RecordStream::Stream::Printer'->new
ABresult
1X1
011
000
466  
467 64 my $module = load_operation($script);
468  
469 54 my $op;
470 54 eval {
471 54 $op = $module->new($args, $next);
472 };
473  
474 25 ▶ if ( $@ || $op->get_wants_help() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or $op->get_wants_help) 2 23 25
Condition66%2/3
$@ or $op->get_wants_help
l!l&&r!l&&!r
0223
MC/DC50%1/2
$@ or $op->get_wants_help
$@ $op->get_wants_help
Truth table66%2/3
A or B
A= $@B= $op->get_wants_help
ABresult
1X1
011
000
475 2 ▶ if ( ! $op ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 0 2 2
476 0 $op = bless {}, $module;
477 0 $op->init_help();
478 }
479 2 $op->print_usage($@);
480 2 exit 1;
481 }
482  
483 23 return $op;
484 }
485  
486 sub basic_help {
487 28 ▶ my $this = shift;
Subroutine basic_help: called CC=1 SCAR=0.0
Pod undocumented
488 28 $this->print_usage($@);
489 }
490  
491 sub all_help {
492 28 ▶ my $this = shift;
Subroutine all_help: called CC=4 SCAR=13.9
Pod undocumented
493  
494 28 foreach my $type (sort keys %{$this->{'HELP_TYPES'}}) {
495 231 my $info = $this->{'HELP_TYPES'}->{$type};
496 231 ▶ next if ( $info->{'SKIP_IN_ALL'} );
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"SKIP_IN_ALL"} 56 175 231
497 175 ▶ next if ( !$info->{'USE'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"USE"} 91 84 175
498  
499 84 print "Help from: --help-$type:\n";
500  
501 84 $info->{'CODE'}->($this);
502 84 print "\n"
503 }
504 }
505  
506 sub keys_help {
507 0 ▶ my $this = shift;
Subroutine keys_help: not called CC=1 SCAR=6.9
Pod undocumented
508 0 $this->keyspecs_help();
509 0 print "\n";
510 0 $this->keygroups_help();
511 }
512  
513 sub snippet_help {
514 7 ▶ my $this = shift;
Subroutine snippet_help: called CC=1 SCAR=0.0
Pod undocumented
515 7 print $this->format_usage(App::RecordStream::Executor::usage());
516 }
517  
518 sub keyspecs_help {
519 25 ▶ my $this = shift;
Subroutine keyspecs_help: called CC=1 SCAR=0.0
Pod undocumented
520 25 print $this->format_usage(App::RecordStream::KeySpec::keyspec_help());
521 }
522  
523 sub keygroups_help {
524 12 ▶ my $this = shift;
Subroutine keygroups_help: called CC=1 SCAR=0.0
Pod undocumented
525 12 print $this->format_usage(App::RecordStream::KeyGroups::usage());
526 }
527  
528 sub domainlanguage_help {
529 3 ▶ my $this = shift;
Subroutine domainlanguage_help: called CC=1 SCAR=0.0
Pod undocumented
530 3 print $this->format_usage(App::RecordStream::DomainLanguage::usage());
531 }
532  
533 sub clumping_help {
534 2 ▶ my $this = shift;
Subroutine clumping_help: called CC=1 SCAR=0.0
Pod undocumented
535 2 print $this->format_usage(App::RecordStream::Clumper::usage());
536 }
537  
538 # A static method for a single-line operation bootstrap. Operation wrappers
539 # can/should be a symlink to recs-operation itself or just this one line: use
540 # App::RecordStream::Operation; App::RecordStream::Operation::main();
541 sub main {
542 44 ▶ my $command = shift || $Script;
Subroutine main: called CC=6 SCAR=25.4
Pod undocumented
Condition33%1/3
shift() || $App::RecordStream::Operation::Script
l!l&&r!l&&!r
0440
MC/DC0%0/2
shift() || $App::RecordStream::Operation::Script
shift() $App::RecordStream::Operation::Script
Truth table33%1/3
A || B
A= shift()B= $App::RecordStream::Operation::Script
ABresult
1X1
011
000
543  
544 44 $| = 1;
545  
546 44 ▶ if ( $command eq 'recs-operation' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "recs-operation") 0 44 44
547 0 print <<MESSAGE;
548 WARNING!
549 recs-operation invoked directly!
550  
551 recs-operation is a wrapper for all other recs commands. You do not want to
552 use this script. It uses the App::RecordStream::Operation::* modules to performation
553 operations, like recs-grep. If you are looking for implementation of those
554 scripts, look in those modules. Otherwise, use a different recs script like
555 recs-grep or recs-collate directly.
556  
557 Terminating program.
558 MESSAGE
559 0 exit 1;
560 }
561  
562 44 my @args = @ARGV;
563 44 @ARGV = ();
564  
565 44 my $op = App::RecordStream::Operation::create_operation($command, \@args);
566  
567 3 ▶ if ( $op->wants_input() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($op->wants_input) 0 3 3
568 0 @ARGV = @args;
569 0 ▶ while(my $line = <>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline ARGV)) 0 0 0
570 0 chomp $line;
571 0 App::RecordStream::Operation::set_current_filename($ARGV);
572 0 ▶ if ( ! $op->accept_line($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op->accept_line($line)) 0 0 0
573 0 last;
574 }
575 }
576 }
577 3 $op->finish();
578  
579 3 exit $op->get_exit_value();
580 }
581  
582 112 1;
« blib/lib/App/RecordStream/Operation/fromcsv.pm ↑ Summary blib/lib/App/RecordStream/Operation/chain.pm »