File Coverage

File:lib/List/Enumerator/Sub.pm
Coverage:90.5%

linestmtbrancondsubpodtimecode
1package List::Enumerator::Sub;
2
5
5
5
22
7
29
use base qw/List::Enumerator::Role/;
3use overload
4
5
5
5
28
7
69
        '@{}' => \&getarray;
5
6__PACKAGE__->mk_accessors(qw/next_sub rewind_sub/);
7
8sub BUILD {
9
95
0
166
        my ($self, $params) = @_;
10
11
95
335
        $self->next_sub($params->{next});
12
95
0
1167
0
        $self->rewind_sub($params->{rewind} || sub {});
13}
14
15sub _next {
16
848
1115
        my ($self, $new) = @_;
17
18
848
978
        local $_ = $self;
19
848
2284
        $self->next_sub->($self);
20}
21
22sub _rewind {
23
14
26
        my ($self, $new) = @_;
24
25
14
26
        local $_ = $self;
26
14
45
        $self->rewind_sub->($self);
27
14
33
        $self;
28}
29
30sub getarray {
31
1
0
3
        my ($self) = @_;
32
1
2
        my @temp;
33
1
0
        tie @temp, __PACKAGE__, $self;
34
1
4
        \@temp;
35}
36
37sub TIEARRAY {
38
1
3
        my ($class, $arg) = @_;
39
1
3
        bless $arg, $class;
40}
41
42sub FETCHSIZE {
43
1
4
        0;
44}
45
46sub FETCH { #TODO orz orz orz
47
1
3
        my ($self, $index) = @_;
48
1
7
        $self->rewind;
49
1
12
        $self->next while ($index--);
50
1
3
        $self->next;
51}
52
531;