line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Mowyw::Datasource::Array; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2180
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
62
|
|
4
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
54
|
|
5
|
3
|
|
|
3
|
|
8
|
use base 'App::Mowyw::Datasource'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
237
|
|
6
|
3
|
|
|
3
|
|
12
|
use Scalar::Util qw(reftype); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
228
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use Carp qw(confess); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
703
|
|
9
|
|
|
|
|
|
|
#use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
7
|
|
|
7
|
0
|
10
|
my ($class, $opts) = @_; |
13
|
7
|
100
|
|
|
|
34
|
my $self = bless { OPTIONS => $opts, INDEX => 0 }, ref $class ? ref $class : $class; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# print Dumper $opts; |
16
|
7
|
100
|
|
|
|
192
|
$self->{DATA} = $opts->{source} or confess "Mandatory option 'source' is missing\n"; |
17
|
6
|
100
|
|
|
|
28
|
if (reftype($self->{DATA}) ne 'ARRAY'){ |
18
|
1
|
|
|
|
|
91
|
confess "Source must be an array"; |
19
|
|
|
|
|
|
|
} |
20
|
5
|
100
|
|
|
|
14
|
if (exists $opts->{limit}){ |
21
|
1
|
|
|
|
|
2
|
$self->{remaining} = $opts->{limit}; |
22
|
|
|
|
|
|
|
} |
23
|
5
|
|
|
|
|
14
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub is_exhausted { |
27
|
21
|
|
|
21
|
0
|
1194
|
my $self = shift; |
28
|
21
|
100
|
100
|
|
|
76
|
return 1 if (exists $self->{remaining} && $self->{remaining} == 0); |
29
|
20
|
|
|
|
|
65
|
return scalar(@{$self->{DATA}}) <= $self->{INDEX} |
30
|
20
|
|
|
|
|
15
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get { |
33
|
15
|
|
|
15
|
0
|
17
|
my $self = shift; |
34
|
15
|
100
|
|
|
|
28
|
$self->{remaining}-- if exists $self->{remaining}; |
35
|
15
|
|
|
|
|
39
|
return $self->{DATA}[$self->{INDEX}]; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub next { |
39
|
13
|
|
|
13
|
0
|
2816
|
shift->{INDEX}++; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub reset { |
43
|
2
|
|
|
2
|
0
|
4
|
shift->{INDEX} = 0; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |