line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CWB::CQP::More::Iterator; |
2
|
|
|
|
|
|
|
$CWB::CQP::More::Iterator::VERSION = '0.08'; |
3
|
1
|
|
|
1
|
|
4045
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
850
|
use Data::Dumper; |
|
1
|
|
|
|
|
6975
|
|
|
1
|
|
|
|
|
566
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
0
|
|
|
0
|
1
|
|
my ($class, $cwb, $resultset, %ops) = @_; |
9
|
0
|
0
|
0
|
|
|
|
return undef unless $resultset && eval { $cwb->isa('CWB::CQP::More') }; |
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
my $self = { name => $resultset, cwb => $cwb }; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
$self->{pos} = 0; |
14
|
0
|
|
0
|
|
|
|
$self->{crp} = uc($ops{corpus}) || undef; |
15
|
0
|
|
0
|
|
|
|
$self->{size} = $ops{size} || 1; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
$self->{fname} = $self->{crp}?"$self->{crp}:$self->{name}" : $self->{name}; |
18
|
0
|
|
0
|
|
|
|
$self->{limit} = $cwb->size($self->{fname}) || 0; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return bless $self => $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub reset { |
24
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
$self->{pos} = 0; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub increment { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
my $current = $self->{size}; |
31
|
0
|
0
|
|
|
|
|
$self->{size} = shift @_ if $_[0]; |
32
|
0
|
|
|
|
|
|
return $current; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub next { |
36
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
37
|
0
|
|
|
|
|
|
my $cwb = $self->{cwb}; |
38
|
0
|
0
|
|
|
|
|
if ($self->{pos} < $self->{limit}) { |
39
|
|
|
|
|
|
|
my @lines = $cwb->cat($self->{fname}, |
40
|
0
|
|
|
|
|
|
$self->{pos} => $self->{pos} + $self->{size} -1); |
41
|
0
|
|
|
|
|
|
$self->{pos} += $self->{size}; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if (scalar(@lines) > 1) { |
44
|
|
|
|
|
|
|
return @lines |
45
|
0
|
|
|
|
|
|
} else { |
46
|
0
|
0
|
|
|
|
|
return wantarray ? @lines : $lines[0]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
return undef |
51
|
0
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub peek { |
55
|
0
|
|
|
0
|
1
|
|
my ($self, $offset) = @_; |
56
|
0
|
|
|
|
|
|
my $cwb = $self->{cwb}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$offset = $self->{pos} + $offset; |
59
|
0
|
0
|
0
|
|
|
|
if ($offset >= 0 && $offset < $self->{limit}) { |
60
|
0
|
|
|
|
|
|
my ($line) = $cwb->cat($self->{fname}, $offset => $offset); |
61
|
0
|
|
|
|
|
|
return $line; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
return undef; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub backward { |
68
|
0
|
|
|
0
|
1
|
|
my ($self, $offset) = @_; |
69
|
0
|
|
|
|
|
|
return $self->forward(-$offset); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub forward { |
73
|
0
|
|
|
0
|
1
|
|
my ($self, $offset) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$offset = $self->{pos} + $offset; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
$offset = 0 if $offset < 0; |
78
|
0
|
0
|
|
|
|
|
$offset = $self->{limit} - 1 if $offset > $self->{limit}; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->{pos} = $offset; |
81
|
0
|
|
|
|
|
|
return $offset; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
0
|
|
|
sub _min { $_[0] < $_[1] ? $_[0] : $_[1] } |
85
|
0
|
0
|
|
0
|
|
|
sub _max { $_[0] > $_[1] ? $_[0] : $_[1] } |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |