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