File Coverage

blib/lib/Data/Range/Compare/Stream/Iterator/Consolidate/FillMissing.pm
Criterion Covered Total %
statement 48 49 97.9
branch 16 18 88.8
condition n/a
subroutine 9 9 100.0
pod 1 3 33.3
total 74 79 93.6


line stmt bran cond sub pod time code
1             package Data::Range::Compare::Stream::Iterator::Consolidate::FillMissing;
2              
3 2     2   2431 use strict;
  2         5  
  2         48  
4 2     2   11 use warnings;
  2         4  
  2         59  
5              
6 2     2   10 use base qw(Data::Range::Compare::Stream::Iterator::Base);
  2         2  
  2         172  
7 2     2   11 use Data::Range::Compare::Stream::Iterator::Consolidate::Result;
  2         4  
  2         62  
8 2     2   9 use Carp qw(croak);
  2         3  
  2         110  
9              
10 2     2   10 use constant NEW_RESULT_FROM=>'Data::Range::Compare::Stream::Iterator::Consolidate::Result';
  2         3  
  2         794  
11              
12             sub new {
13 5     5 0 47 my ($class,$con,%args)=@_;
14 5 50       20 croak 'Consolidator object must be defined' unless defined($con);
15            
16 5         34 $class->SUPER::new(con=>$con,%args);
17             }
18              
19             sub has_next {
20 51     51 0 5810 my ($self)=@_;
21 51 100       223 return 1 if $self->{con}->has_next;
22 25 100       91 return 1 if defined($self->{missing_result});
23 18 100       77 return 1 if defined($self->{last_result_obj});
24 11         48 return 0;
25             }
26              
27             sub get_next {
28 24     24 1 43 my ($self)=@_;
29 24         43 my $it=$self->{con};
30            
31 24         31 my $last_result;
32 24 100       81 if(defined($self->{missing_result})) {
    100          
33 8         15 my $result=$self->{missing_result};
34 8         16 $self->{missing_result}=undef;
35 8         27 return $result;
36             } elsif(defined($self->{last_result_obj})) {
37 11         20 $last_result=$self->{last_result_obj};
38 11         21 $self->{last_result_obj}=undef;
39             } else {
40 5 50       23 if($it->has_next) {
41 5         36 $last_result=$it->get_next;
42             } else {
43 0         0 croak 'iterator called when has_next is false!';
44             }
45             }
46              
47 16 100       61 if($it->has_next) {
48 11         36 my $result=$it->get_next;
49 11 100       40 if($last_result->get_common->contiguous_check($result->get_common)) {
50 3         8 $self->{last_result_obj}=$result;
51 3         11 return $last_result;
52             } else {
53 8         16 $self->{last_result_obj}=$result;
54 8         26 my $new_result=$self->create_from_factory($last_result->get_common->next_range_start,$result->get_common->previous_range_end);
55 8         29 $new_result->get_common->on_create_range($last_result->get_common);
56 8         42 $self->{missing_result}=$self->NEW_RESULT_FROM->new($new_result,$new_result,$new_result,1,1);
57              
58 8         30 return $last_result;
59             }
60             } else {
61 5         17 return $last_result;
62             }
63             }
64              
65              
66             1;