File Coverage

blib/lib/Data/Range/Compare/Stream/Iterator/Consolidate/AdjacentAsc.pm
Criterion Covered Total %
statement 37 37 100.0
branch 13 14 92.8
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 56 58 96.5


line stmt bran cond sub pod time code
1             package Data::Range::Compare::Stream::Iterator::Consolidate::AdjacentAsc;
2              
3 3     3   4809 use strict;
  3         7  
  3         112  
4 3     3   15 use warnings;
  3         6  
  3         89  
5 3     3   15 use base qw(Data::Range::Compare::Stream::Iterator::Consolidate);
  3         4  
  3         1800  
6              
7              
8             sub has_next {
9 28     28 0 1915 my ($self)=@_;
10 28 100       284 return 1 if $self->SUPER::has_next;
11 9 100       33 return 1 if defined($self->{last_result});
12 7         29 return 0;
13             }
14              
15             sub get_next {
16 8     8 1 2120 my ($self)=@_;
17 8 100       26 return undef unless $self->has_next;
18            
19 7         17 my $result;
20 7 100       35 if(defined($self->{last_result})) {
    50          
21 3         6 $result=$self->{last_result};
22             } elsif($self->SUPER::has_next) {
23 4         32 $result=$self->SUPER::get_next;
24             }
25              
26 7         30 while($self->has_next) {
27 12         28 my $last_result;
28 12 100       45 if($self->SUPER::has_next) {
29 11         74 $last_result=$self->SUPER::get_next;
30             } else {
31 1         4 $self->{last_result}=undef;
32 1         3 return $result;
33             }
34              
35            
36             # get our common result range
37 11         47 my $common=$result->get_common;
38 11         39 my $next=$last_result->get_common;
39              
40             # stop here if the contiguous check turns up nothing
41            
42 11 100       45 unless($common->contiguous_check($next)) {
43 3         8 $self->{last_result}=$last_result;
44 3         12 return $result
45             }
46              
47             # if we got here then we need to get the starting range
48              
49             # compute the overlap
50 8         66 my $overlap=$common->get_overlapping_range([$common,$next]);
51 8         51 $self->on_consolidate($overlap,$common,$next);
52              
53 8         35 my ($start,$end)=$common->find_smallest_outer_ranges([$result->get_start->get_common,$result->get_end->get_common,$last_result->get_start->get_common,$last_result->get_end->get_common]);
54              
55             # get our new result
56 8         226 $result=$self->RESULT_CLASS->new($overlap,$start->get_common,$end->get_common,0,1);
57              
58             # update the internals
59 8         247 $self->{last_result}=undef;
60              
61              
62             }
63            
64 3         9 $self->{last_result}=undef;
65 3         14 return $result;
66             }
67              
68             1;