DSL/Context/TextBlock.pm

filter: Statementstmt 10.6% 7 / 66 Branchbran 0.0% 0 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 0.0% 0 / 3 totaltotal 8.1% 9 / 110 CC 24 SCAR 57.5
CC
24
Cov
7%
update_stream
414.8
change_context
20.0
new
2.0
CRAP 314.1
« DSL.pm ↑ Summary DSL/Context/Range.pm »
1 package Outthentic::DSL::Context::TextBlock;
2 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4  
5 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
6  
7 0 bless { succeeded => [] }, __PACKAGE__
8 }
9  
10 0 ▶sub change_context {
Subroutine change_context: not called CC=4 SCAR=30.0
Pod undocumented
11  
12 0 my $self = shift;
13 0 my $cur_ctx = shift; # current search context
14 0 my $orig_ctx = shift; # original search context
15 0 my $succ = shift; # latest succeeded items
16  
17 #warn Dumper($cur_ctx);
18 #warn Dumper($succ);
19  
20 0 my $new_ctx = []; # new context
21  
22 0 ▶ if (scalar @{$succ}){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$succ;}) { } 0 0 0
23  
24 0 for my $c (@{$succ}){
25 0 ▶ push @$new_ctx, $orig_ctx->[$c->[1]] if defined($orig_ctx->[$c->[1]]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $$orig_ctx[$c->[1]] 0 0 0
26 }
27 }else{
28 0 $new_ctx = $cur_ctx;
29 }
30  
31 0 $new_ctx;
32  
33 }
34  
35  
36 0 ▶sub update_stream {
Subroutine update_stream: not called CC=21 SCAR=60.3
Pod undocumented
37  
38 0 ▶ print "\n\nxxxx start of text block update stream \n \n \n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
39  
40 0 my $self = shift;
41 0 my $cur_ctx = shift; # current search context
42 0 my $orig_ctx = shift; # original search context
43 0 my $succ = shift; # latest succeeded items
44 0 my $stream_ref = shift; # reference to stream object to update
45  
46 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 0 my %live_chains = ();
49  
50  
51 0 ▶ if (scalar @{$succ}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$succ;}) 0 0 0
52  
53 0 ▶ unless ($self->{chains}){ # chain initialization
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"chains"}) 0 0 0
54 0 for my $c ( @{$succ} ){
55 0 ▶ print "[OTX_DEBUG] init chain $c[0]($c[1]) )...\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
56 0 $self->{chains}->{$c->[1]} = [$c];
57 }
58 };
59  
60  
61  
62 0 for my $c (@{$succ}){
63 0 my @k = keys %{$self->{chains}};
64 0 CHAIN: for my $cid (sort { $a <=> $b } @k ){
65  
66 0 ▶ next CHAIN if $live_chains{$cid};
Branch: 1 branch
BranchTrueFalseTotal
if $live_chains{$cid} 0 0 0
67  
68 0 ▶ print "[OTX_DEBUG] chain end at ".($self->{chains}->{$cid}->[-1]->[1])."\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
69
70 0 ▶ if ( $self->{chains}->{$cid}->[-1]->[1] == $c->[1]-1 ){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'chains'}{$cid}[-1][1] == $c->[1] - 1) { } 0 0 0
elsif ($self->{'chains'}{$cid}[-1][1] == $c->[1]) { } 0 0 0
71 0 $live_chains{$cid} = 1;
72 0 push @{$self->{chains}->{$cid}}, $c;
73 0 ▶ print "[OTX_DEBUG] push $c->[0]($c->[1]) to chain $cid ...\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
74 0 ▶ print "[OTX_DEBUG] new chain end at ".($self->{chains}->{$cid}->[-1]->[0])."\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
75 0 last CHAIN;
76 }elsif ( $self->{chains}->{$cid}->[-1]->[1] == $c->[1] ) {
77 0 $live_chains{$cid} = 1;
78 0 ▶ print "[OTX_DEBUG] keep chain $cid ...\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
79 0 last CHAIN;
80 }else{
81 0 ▶ print "[OTX_DEBUG] skip $c->[0] [ $c->[1] ] ...\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
82 }
83 }
84 }
85 }
86  
87 #warn Dumper([sort { $a <=> $b } keys %live_chains]) if $ENV{OUTH_DBG};
88  
89 # delete failed chains
90  
91 0 ${$stream_ref} = {};
92  
93 0 ▶ print "\n\nxxxx generating text block stream xxxx \n \n \n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
94  
95 0 for my $cid (sort { $a <=> $b } keys %{$self->{chains}}){
96 0 ▶ if ($live_chains{$cid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($live_chains{$cid}) { } 0 0 0
97 0 ${$stream_ref}->{$cid} = $self->{chains}->{$cid};
98 0 ▶ print "[OTX_DEBUG] chain end at ".($self->{chains}->{$cid}->[-1]->[1])."\n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
99 } else {
100 0 delete @{$self->{chains}}{$cid};
101 }
102 }
103  
104 0 ▶ print "\n\nxxxx end of text block update stream \n \n \n" if $ENV{OUTH_DBG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OUTH_DBG"} 0 0 0
105  
106 }
107  
108  
109 2 1;
110  
« DSL.pm ↑ Summary DSL/Context/Range.pm »