line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ArrayDataRole::Source::LinesInDATA; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2021-05-03'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'ArrayDataRoles-Standard'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.005'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1197
|
use Role::Tiny; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
9
|
2
|
|
|
2
|
|
353
|
use Role::Tiny::With; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
128
|
|
10
|
|
|
|
|
|
|
with 'ArrayDataRole::Spec::Basic'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
931
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
0
|
216
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
4
|
my $fh = \*{"$class\::DATA"}; |
|
2
|
|
|
|
|
13
|
|
18
|
2
|
|
|
|
|
8
|
my $fhpos_data_begin = tell $fh; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
16
|
bless { |
21
|
|
|
|
|
|
|
fh => $fh, |
22
|
|
|
|
|
|
|
fhpos_data_begin => $fhpos_data_begin, |
23
|
|
|
|
|
|
|
pos => 0, # iterator |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_next_item { |
28
|
22
|
|
|
22
|
0
|
114
|
my $self = shift; |
29
|
22
|
100
|
|
|
|
111
|
die "StopIteration" if eof($self->{fh}); |
30
|
21
|
|
|
|
|
54
|
chomp(my $elem = readline($self->{fh})); |
31
|
21
|
|
|
|
|
47
|
$self->{pos}++; |
32
|
21
|
|
|
|
|
62
|
$elem; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub has_next_item { |
36
|
18
|
|
|
18
|
0
|
102
|
my $self = shift; |
37
|
18
|
|
|
|
|
115
|
!eof($self->{fh}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_iterator_pos { |
41
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
42
|
0
|
|
|
|
|
0
|
$self->{pos}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub reset_iterator { |
46
|
5
|
|
|
5
|
0
|
1706
|
my $self = shift; |
47
|
5
|
|
|
|
|
69
|
seek $self->{fh}, $self->{fhpos_data_begin}, 0; |
48
|
5
|
|
|
|
|
23
|
$self->{pos} = 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_item_at_pos { |
52
|
3
|
|
|
3
|
0
|
52
|
my ($self, $pos) = @_; |
53
|
3
|
100
|
|
|
|
14
|
$self->reset_iterator if $self->{pos} > $pos; |
54
|
3
|
|
|
|
|
5
|
while (1) { |
55
|
7
|
100
|
|
|
|
14
|
die "Out of range" unless $self->has_next_item; |
56
|
6
|
|
|
|
|
31
|
my $item = $self->get_next_item; |
57
|
6
|
100
|
|
|
|
26
|
return $item if $self->{pos} > $pos; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub has_item_at_pos { |
62
|
3
|
|
|
3
|
0
|
11
|
my ($self, $pos) = @_; |
63
|
3
|
100
|
|
|
|
16
|
return 1 if $self->{pos} > $pos; |
64
|
2
|
|
|
|
|
4
|
while (1) { |
65
|
5
|
100
|
|
|
|
11
|
return 0 unless $self->has_next_item; |
66
|
4
|
|
|
|
|
11
|
$self->get_next_item; |
67
|
4
|
100
|
|
|
|
15
|
return 1 if $self->{pos} > $pos; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
# ABSTRACT: Role to access array data from DATA section, one line per element |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |