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.8
CC
56
Cov
86%
main
12.7
parse_options
10.1
load_operation
7.0
CRAP 4.4
« blib/lib/App/RecordStream/Operation/chain.pm ↑ Summary blib/lib/App/RecordStream/Operation/flatten.pm »
1 package App::RecordStream::Operation;
2  
3 113 our $VERSION = "4.0.25";
4  
5 113 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 113 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 113 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 113 ▶use FindBin qw($Script $RealScript);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 113 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 113 ▶use Text::Autoformat;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 113 ▶use App::RecordStream::Clumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 113 ▶use App::RecordStream::DomainLanguage;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 113 ▶use App::RecordStream::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 113 ▶use App::RecordStream::KeyGroups;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 113 ▶use App::RecordStream::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 113 ▶use App::RecordStream::Stream::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 113 ▶use App::RecordStream::Stream::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 113 ▶use base 'App::RecordStream::Stream::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
Pod undocumented
24 0 subclass_should_implement(shift);
25 }
26  
27 214 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
28 214 my $class = shift;
29 214 my $args = shift;
30 214 my $next = shift;
31  
32 214 my $this = {
33 NEXT => $next,
34 };
35  
36 214 bless $this, $class;
37  
38 214 $this->init_help();
39 214 $this->init($args);
40 185 return $this;
41 }
42  
43 214 ▶sub init_help {
Subroutine init_help: called CC=1 SCAR=0.0
Pod undocumented
44 214 my $this = shift;
45 214 $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 214 $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 32 ▶sub options_string {
Subroutine options_string: called CC=6 SCAR=17.9
Pod undocumented
103 32 my ($this, $options) = @_;
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 64 ▶sub _options_format {
Subroutine _options_format: called CC=5 SCAR=16.1
130 64 my ($this, $options, $indent_level) = @_;
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 113 my $size_initialized = 0;
161 113 my $size = 80;
162 637 ▶ sub get_terminal_size {
Subroutine get_terminal_size: called CC=4 SCAR=14.6
Pod undocumented
163 637 ▶ if ( ! $size_initialized ) {
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 113 ▶sub format_text {
Subroutine format_text: called CC=2 SCAR=6.9
Pod undocumented
178 637 my ($this, $text, $left_indent) = @_;
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 13 ▶sub add_help_types {
Subroutine add_help_types: called CC=1 SCAR=0.0
Pod undocumented
189 }
190  
191 464 ▶sub use_help_type {
Subroutine use_help_type: called CC=1 SCAR=0.0
Pod undocumented
192 464 my $this = shift;
193 464 my $type = shift;
194  
195 464 $this->{'HELP_TYPES'}->{$type}->{'USE'} = 1;
196 464 $this->{'HELP_TYPES'}->{'all'}->{'USE'} = 1;
197 }
198  
199 69 ▶sub add_help_type {
Subroutine add_help_type: called CC=2 SCAR=7.0
Pod undocumented
200 69 my $this = shift;
201 69 my $type = shift;
202 69 my $action = shift;
203 69 my $description = shift;
204 69 my $skip_in_all = shift;
205 69 ▶ my $option_name = shift || 0;
Condition50%1/2
shift() || 0
l!l
069
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
206  
207 69 $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 214 ▶sub parse_options {
Subroutine parse_options: called CC=10 SCAR=23.2
Pod undocumented
217 214 my $this = shift;
218 214 ▶ my $args = shift || [];
Condition50%1/2
shift() || []
l!l
2140
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
219 214 ▶ my $options_spec = shift || {};
Condition100%2/2
shift() || {}
l!l
2122
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
220 214 ▶ my $configuration_options = shift || [];
Condition100%2/2
shift() || []
l!l
60154
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
221  
222 # Add help options
223 214 foreach my $help_type (keys %{$this->{'HELP_TYPES'}}) {
224 1781 my $type_info = $this->{'HELP_TYPES'}->{$help_type};
225 1781 ▶ next unless ( $type_info->{'USE'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $type_info->{"USE"} 833 948 1781
226  
227 948 ▶ my $help_option = $type_info->{'OPTION_NAME'} || 'help-' . $help_type;
Condition100%2/2
$type_info->{'OPTION_NAME'} || 'help-' . $help_type
l!l
214734
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 28 ▶ $options_spec->{$help_option} ||= sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
230 28 $type_info->{'CODE'}->($this);
231 28 exit 1;
232 948 ▶ };
Condition33%1/3
$options_spec->{$help_option} ||= sub { $type_info->{"CODE"}->($this); exit 1; }
l!l&&r!l&&!r
09480
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 214 ▶ $options_spec->{'--filename-key|fk=s'} = \($this->{'FILENAME_KEY'})
Branch: 1 branch
BranchTrueFalseTotal
if $this->does_record_output 214 0 214
237 if $this->does_record_output;
238  
239 214 my $starting_config = Getopt::Long::Configure();
240  
241 # Push custom configuration
242 214 Getopt::Long::Configure('no_ignore_case', @$configuration_options);
243  
244 214 local @ARGV = @$args;
245 214 ▶ unless (GetOptions(%$options_spec)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptions(%$options_spec)) 2 184 186
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 186 Getopt::Long::Configure($starting_config);
252  
253 186 @$args = @ARGV;
254 }
255  
256 4 ▶sub update_current_filename {
Subroutine update_current_filename: called CC=1 SCAR=0.0
Pod undocumented
257 4 my ($this, $filename) = @_;
258 4 set_current_filename($filename);
259 }
260  
261 2 ▶sub _set_wants_help {
Subroutine _set_wants_help: called CC=1 SCAR=0.0
262 2 my $this = shift;
263 2 my $help = shift;
264  
265 2 $this->{'WANTS_HELP'} = $help;
266 }
267  
268 25 ▶sub get_wants_help {
Subroutine get_wants_help: called CC=1 SCAR=0.0
Pod undocumented
269 25 my $this = shift;
270 25 return $this->{'WANTS_HELP'};
271 }
272  
273 0 ▶sub _set_exit_value {
Subroutine _set_exit_value: not called CC=1 SCAR=6.9
274 0 my $this = shift;
275 0 my $value = shift;
276  
277 0 $this->{'EXIT_VALUE'} = $value;
278 }
279  
280 3 ▶sub get_exit_value {
Subroutine get_exit_value: called CC=2 SCAR=7.2
Pod undocumented
281 3 my $this = shift;
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 30 ▶sub print_usage {
Subroutine print_usage: called CC=5 SCAR=18.0
Pod undocumented
286 30 my $this = shift;
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 82 ▶sub format_usage {
Subroutine format_usage: called CC=6 SCAR=17.9
Pod undocumented
312 82 my ($this, $usage) = @_;
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 1 ▶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 252 ▶sub wants_input {
Subroutine wants_input: called CC=1 SCAR=0.0
Pod undocumented
363 252 return 1;
364 }
365  
366 246 ▶sub does_record_output {
Subroutine does_record_output: called CC=1 SCAR=0.0
Pod undocumented
367 246 return 1;
368 }
369  
370 174 ▶sub finish {
Subroutine finish: called CC=1 SCAR=0.0
Pod undocumented
371 174 my $this = shift;
372 174 $this->stream_done();
373 172 $this->{'NEXT'}->finish();
374 }
375  
376 {
377 113 my $filename;
378 196 ▶ sub get_current_filename {
Subroutine get_current_filename: called CC=2 SCAR=6.9
Pod undocumented
379 196 ▶ return $filename || 'NONE';
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 412 ▶ sub set_current_filename {
Subroutine set_current_filename: called CC=1 SCAR=0.0
Pod undocumented
383 412 my $name = shift;
384 412 $filename = $name;
385 }
386 }
387  
388 113 ▶sub subclass_should_implement {
Subroutine subclass_should_implement: not called CC=1 SCAR=2.6
Pod undocumented
389 0 my $this = shift;
390 0 croak "Subclass should implement: " . ref($this);
391 }
392  
393 47 ▶sub stream_done {
Subroutine stream_done: called CC=1 SCAR=0.0
Pod undocumented
394 }
395  
396 484 ▶sub push_record {
Subroutine push_record: called CC=2 SCAR=6.9
Pod undocumented
397 484 my ($this, $record) = @_;
398  
399 484 ▶ if ( $this->{'FILENAME_KEY'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FILENAME_KEY"}) 14 470 484
400 14 ${$record->guess_key_from_spec($this->{'FILENAME_KEY'})} = get_current_filename();
401 }
402  
403 484 return $this->{'NEXT'}->accept_record($record);
404 }
405  
406 482 ▶sub push_line {
Subroutine push_line: called CC=1 SCAR=0.0
Pod undocumented
407 482 my ($this, $line) = @_;
408 482 $this->{'NEXT'}->accept_line($line);
409 }
410  
411 92 ▶sub load_operation {
Subroutine load_operation: called CC=7 SCAR=19.5
Pod undocumented
412 92 my $script = shift;
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 0 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 33 ▶sub is_recs_operation {
Subroutine is_recs_operation: called CC=3 SCAR=11.0
Pod undocumented
451 33 my $script = shift;
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 64 ▶sub create_operation {
Subroutine create_operation: called CC=5 SCAR=16.5
Pod undocumented
463 64 my $script = shift;
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 28 ▶sub basic_help {
Subroutine basic_help: called CC=1 SCAR=0.0
Pod undocumented
487 28 my $this = shift;
488 28 $this->print_usage($@);
489 }
490  
491 28 ▶sub all_help {
Subroutine all_help: called CC=4 SCAR=13.9
Pod undocumented
492 28 my $this = shift;
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 0 ▶sub keys_help {
Subroutine keys_help: not called CC=1 SCAR=6.9
Pod undocumented
507 0 my $this = shift;
508 0 $this->keyspecs_help();
509 0 print "\n";
510 0 $this->keygroups_help();
511 }
512  
513 7 ▶sub snippet_help {
Subroutine snippet_help: called CC=1 SCAR=0.0
Pod undocumented
514 7 my $this = shift;
515 7 print $this->format_usage(App::RecordStream::Executor::usage());
516 }
517  
518 25 ▶sub keyspecs_help {
Subroutine keyspecs_help: called CC=1 SCAR=0.0
Pod undocumented
519 25 my $this = shift;
520 25 print $this->format_usage(App::RecordStream::KeySpec::keyspec_help());
521 }
522  
523 12 ▶sub keygroups_help {
Subroutine keygroups_help: called CC=1 SCAR=0.0
Pod undocumented
524 12 my $this = shift;
525 12 print $this->format_usage(App::RecordStream::KeyGroups::usage());
526 }
527  
528 3 ▶sub domainlanguage_help {
Subroutine domainlanguage_help: called CC=1 SCAR=0.0
Pod undocumented
529 3 my $this = shift;
530 3 print $this->format_usage(App::RecordStream::DomainLanguage::usage());
531 }
532  
533 2 ▶sub clumping_help {
Subroutine clumping_help: called CC=1 SCAR=0.0
Pod undocumented
534 2 my $this = shift;
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 44 ▶sub main {
Subroutine main: called CC=6 SCAR=25.4
Pod undocumented
542 44 ▶ my $command = shift || $Script;
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 113 1;
« blib/lib/App/RecordStream/Operation/chain.pm ↑ Summary blib/lib/App/RecordStream/Operation/flatten.pm »