line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::LineBuffer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
106839
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
1313
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new |
9
|
|
|
|
|
|
|
{ |
10
|
5
|
|
|
5
|
1
|
4686
|
my $class = shift; |
11
|
5
|
|
33
|
|
|
31
|
$class = ref($class) || $class; |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
|
|
22
|
my $self = bless { cache => [], |
14
|
|
|
|
|
|
|
line => 1 }, $class; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# we use closures like mad here to make a uniform definition |
19
|
|
|
|
|
|
|
# of the get method possible. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Don't shift next argument; need to get a reference |
22
|
|
|
|
|
|
|
# to it if it's a scalar. |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
10
|
my $what = $_[0]; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# scalar? split on newlines |
27
|
5
|
100
|
|
|
|
36
|
unless ( ref $_[0] ) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
|
|
3
|
my $sref = \$_[0]; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
5
|
pos( $$sref ) = 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$self->{next} = |
34
|
|
|
|
|
|
|
sub { |
35
|
6
|
50
|
33
|
6
|
|
50
|
defined pos($$sref) ? scalar $$sref =~ /^(.*)$/mg && $1 : undef |
36
|
1
|
|
|
|
|
13
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# array? grab the next element |
40
|
|
|
|
|
|
|
elsif ( 'ARRAY' eq ref($what) ) |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
|
|
2
|
my $idx = 0; |
43
|
|
|
|
|
|
|
$self->{next} = |
44
|
1
|
50
|
|
6
|
|
7
|
sub { $idx == @$what ? undef : $what->[$idx++] }; |
|
6
|
|
|
|
|
23
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# glob (we're assuming file glob)? read next line |
48
|
|
|
|
|
|
|
elsif ( 'GLOB' eq ref($what) ) |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
6
|
|
4
|
$self->{next} = sub { scalar <$what> }; |
|
6
|
|
|
|
|
28
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# subroutine? call it |
54
|
|
|
|
|
|
|
elsif ( 'CODE' eq ref($what) ) |
55
|
|
|
|
|
|
|
{ |
56
|
1
|
|
|
|
|
3
|
$self->{next} = $what; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# file handle? read next line |
60
|
|
|
|
|
|
|
elsif ( UNIVERSAL::isa($what, 'IO::File') ) |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
6
|
|
5
|
$self->{next} = sub { scalar <$what> }; |
|
6
|
|
|
|
|
25
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
else |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
undef $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
5
|
|
|
|
|
23
|
$self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
45
|
|
|
45
|
1
|
201
|
sub pos { $_[0]->{line} } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub unget |
76
|
|
|
|
|
|
|
{ |
77
|
15
|
|
|
15
|
1
|
56
|
my $self = shift; |
78
|
15
|
|
|
|
|
16
|
push @{$self->{cache}}, @_; |
|
15
|
|
|
|
|
32
|
|
79
|
|
|
|
|
|
|
|
80
|
15
|
|
|
|
|
33
|
$self->{line} -= @_; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get |
84
|
|
|
|
|
|
|
{ |
85
|
45
|
|
|
45
|
1
|
47
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
45
|
|
|
|
|
42
|
my $ret = pop @{$self->{cache}}; |
|
45
|
|
|
|
|
67
|
|
88
|
|
|
|
|
|
|
|
89
|
45
|
100
|
|
|
|
98
|
$ret = &{$self->{next}} |
|
30
|
|
|
|
|
50
|
|
90
|
|
|
|
|
|
|
unless defined $ret; |
91
|
|
|
|
|
|
|
|
92
|
45
|
50
|
|
|
|
118
|
if ( defined $ret ) |
93
|
|
|
|
|
|
|
{ |
94
|
45
|
|
|
|
|
55
|
$self->{line}++; |
95
|
45
|
|
|
|
|
60
|
chomp $ret; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
45
|
|
|
|
|
139
|
$ret; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
0
|
|
sub cache { $_[0]->{cache} }; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |