File Coverage

blib/lib/Data/Pipeline/Action/Tail.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Data::Pipeline::Action::Tail;
2              
3 1     1   1696 use Moose;
  0            
  0            
4             with 'Data::Pipeline::Action';
5              
6             has length => (
7             isa => 'Int',
8             is => 'ro',
9             required => 1
10             );
11              
12             sub transform {
13             my($self, $iterator) = @_;
14              
15             my $count = $self -> length;
16             my @stack;
17              
18             $iterator = $self -> make_iterator($iterator);
19              
20             return Data::Pipeline::Iterator -> new(
21             source => Data::Pipeline::Source::Iterator -> new(
22             has_next => sub {
23             @stack > 0
24             },
25             get_next => sub {
26             while(defined( $iterator ) && !$iterator -> finished) {
27             push @stack, $iterator -> next;
28             shift @stack if @stack > $count;
29             }
30             $iterator = undef;
31              
32             return shift @stack;
33             },
34             )
35             );
36             }
37              
38             1;
39              
40             __END__