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-10'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'ArrayDataRoles-Standard'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.006'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1104
|
use Role::Tiny; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
9
|
2
|
|
|
2
|
|
359
|
use Role::Tiny::With; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
113
|
|
10
|
|
|
|
|
|
|
with 'ArrayDataRole::Spec::Basic'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
|
12
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
957
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
0
|
204
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
5
|
my $fh = \*{"$class\::DATA"}; |
|
2
|
|
|
|
|
12
|
|
18
|
2
|
|
|
|
|
9
|
my $fhpos_data_begin = tell $fh; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
14
|
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
|
108
|
my $self = shift; |
29
|
22
|
100
|
|
|
|
99
|
die "StopIteration" if eof($self->{fh}); |
30
|
21
|
|
|
|
|
61
|
chomp(my $elem = readline($self->{fh})); |
31
|
21
|
|
|
|
|
46
|
$self->{pos}++; |
32
|
21
|
|
|
|
|
59
|
$elem; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub has_next_item { |
36
|
18
|
|
|
18
|
0
|
108
|
my $self = shift; |
37
|
18
|
|
|
|
|
117
|
!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
|
1804
|
my $self = shift; |
47
|
5
|
|
|
|
|
66
|
seek $self->{fh}, $self->{fhpos_data_begin}, 0; |
48
|
5
|
|
|
|
|
26
|
$self->{pos} = 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_item_at_pos { |
52
|
3
|
|
|
3
|
0
|
39
|
my ($self, $pos) = @_; |
53
|
3
|
100
|
|
|
|
14
|
$self->reset_iterator if $self->{pos} > $pos; |
54
|
3
|
|
|
|
|
6
|
while (1) { |
55
|
7
|
100
|
|
|
|
17
|
die "Out of range" unless $self->has_next_item; |
56
|
6
|
|
|
|
|
15
|
my $item = $self->get_next_item; |
57
|
6
|
100
|
|
|
|
24
|
return $item if $self->{pos} > $pos; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub has_item_at_pos { |
62
|
3
|
|
|
3
|
0
|
8
|
my ($self, $pos) = @_; |
63
|
3
|
100
|
|
|
|
16
|
return 1 if $self->{pos} > $pos; |
64
|
2
|
|
|
|
|
4
|
while (1) { |
65
|
5
|
100
|
|
|
|
10
|
return 0 unless $self->has_next_item; |
66
|
4
|
|
|
|
|
11
|
$self->get_next_item; |
67
|
4
|
100
|
|
|
|
14
|
return 1 if $self->{pos} > $pos; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub fh { |
72
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
73
|
0
|
|
|
|
|
|
$self->{fh}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub fh_min_offset { |
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
$self->{fhpos_data_begin}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
0
|
1
|
|
sub fh_max_offset { undef } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
# ABSTRACT: Role to access array data from DATA section, one line per element |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |