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

filter: Statementstmt 100% 39 / 39 Branchbran 92.8% 13 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 92.1% 70 / 76 CC 10 SCAR 13.7
CC
10
Cov
98%
accept_record
7.0
init
3.0
stream_done
2.1
CRAP 3.9
« blib/lib/App/RecordStream/Operation/normalizetime.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/PercentileMap.pm »
1 package App::RecordStream::Operation::substream;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use base qw(App::RecordStream::Operation);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use App::RecordStream::Executor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub init {
10 6 ▶ my $this = shift;
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
11 6 my $args = shift;
12  
13 6 my $begin;
14 my $end;
15  
16 6 my $spec = {
17 "begin|b=s" => \$begin,
18 "end|e=s" => \$end,
19 };
20  
21 6 $this->parse_options($args, $spec);
22  
23 5 ▶ $this->{'BEGIN_EXECUTOR'} = App::RecordStream::Executor->new($begin) if defined $begin;
Branch: 1 branch
BranchTrueFalseTotal
if defined $begin 3 2 5
24 5 ▶ $this->{'END_EXECUTOR'} = App::RecordStream::Executor->new($end) if defined $end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $end 3 2 5
25 }
26  
27 sub accept_record {
28 33 ▶ my $this = shift;
Subroutine accept_record: called CC=7 SCAR=19.5
Pod undocumented
29 33 my $record = shift;
30  
31 33 ▶ if ( ! $this->{'IN_SUBSTREAM'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"IN_SUBSTREAM"}) 8 25 33
32 8 my $executor = $this->{'BEGIN_EXECUTOR'};
33  
34 8 ▶ if ( (! defined $executor) || $executor->execute_code($record) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $executor or $executor->execute_code($record)) 5 3 8
Condition100%3/3
not defined $executor or $executor->execute_code($record)
l!l&&r!l&&!r
233
MC/DC100%2/2
not defined $executor or $executor->execute_code($record)
not defined $executor $executor->execute_code($record)
Truth table100%3/3
not(A) or B
A= not defined $executorB= $executor->execute_code($record)
ABresult
1X1
011
000
35 5 $this->{'IN_SUBSTREAM'} = 1;
36 }
37 }
38  
39 33 ▶ if ( $this->{'IN_SUBSTREAM'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"IN_SUBSTREAM"}) 30 3 33
40 30 my $executor = $this->{'END_EXECUTOR'};
41  
42 30 $this->push_record($record);
43 30 $this->{'SEEN_RECORD'} = 1;
44  
45 30 ▶ if ( (defined $executor) && $executor->execute_code($record) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $executor and $executor->execute_code($record)) 3 27 30
Condition100%3/3
defined $executor and $executor->execute_code($record)
!ll&&!rl&&r
1983
MC/DC100%2/2
defined $executor and $executor->execute_code($record)
defined $executor $executor->execute_code($record)
Truth table100%3/3
A and B
A= defined $executorB= $executor->execute_code($record)
ABresult
0X0
100
111
46 3 $this->{'IN_SUBSTREAM'} = 0;
47 3 return 0; # terminate early to avoid reading the rest of the stream
48 }
49 }
50  
51 30 return 1;
52 }
53  
54 sub stream_done {
55 5 ▶ my $this = shift;
Subroutine stream_done: called CC=2 SCAR=7.2
Pod undocumented
56 5 ▶ $this->_set_exit_value(1) unless ( $this->{'SEEN_RECORD'} );
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"SEEN_RECORD"} 0 5 5
57 }
58  
59 sub add_help_types {
60 6 ▶ my $this = shift;
Subroutine add_help_types: called CC=1 SCAR=0.0
Pod undocumented
61 6 $this->use_help_type('snippet');
62 }
63  
64 sub usage {
65 1 ▶ my $this = shift;
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
66  
67 1 my $options = [
68 ['begin|b SNIP ', 'Begins outputting records when this snippet becomes true. If omitted, output starts from beginning of the stream.'],
69 ['end|e SNIP', 'Stops outputting records after this snippet becomes true. If omitted, outputs to the end of the stream.'],
70 ];
71  
72 1 my $args_string = $this->options_string($options);
73  
74 1 return <<USAGE;
75 Usage: recs-substream <args> [<files>]
76 __FORMAT_TEXT__
77 Filters to a range of records delimited from when the begin snippet becomes true to when the end snippet becomes true, ie. [begin, end]. Compare to Perl's inclusive, bistable ".." range operator.
78  
79 See --help-snippet for details on snippets.
80 __FORMAT_TEXT__
81  
82 Arguments:
83 $args_string
84  
85 Examples:
86 Filter to a specific minute:
87 recs-substream -b '{{EndTime}} =~ /Thu, 07 Nov 2013 22:42/' -e 'not {{EndTime}} =~ /Thu, 07 Nov 2013 22:42/'
88 Truncate past a specific date:
89 recs-substream -e '{{EndTime}} =~ /Thu, 07 Nov/'
90 USAGE
91 }
92  
93 2 1;
« blib/lib/App/RecordStream/Operation/normalizetime.pm ↑ Summary blib/lib/App/RecordStream/Aggregator/PercentileMap.pm »