| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Amazon::MechanicalTurk::PagedResultsIterator; |
|
2
|
18
|
|
|
18
|
|
94
|
use warnings; |
|
|
18
|
|
|
|
|
31
|
|
|
|
18
|
|
|
|
|
518
|
|
|
3
|
18
|
|
|
18
|
|
90
|
use strict; |
|
|
18
|
|
|
|
|
33
|
|
|
|
18
|
|
|
|
|
489
|
|
|
4
|
18
|
|
|
18
|
|
88
|
use Carp; |
|
|
18
|
|
|
|
|
37
|
|
|
|
18
|
|
|
|
|
1071
|
|
|
5
|
18
|
|
|
18
|
|
98
|
use Net::Amazon::MechanicalTurk::BaseObject; |
|
|
18
|
|
|
|
|
34
|
|
|
|
18
|
|
|
|
|
10852
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw{ Net::Amazon::MechanicalTurk::BaseObject }; |
|
10
|
|
|
|
|
|
|
our %META_RESULT_FIELDS = ( |
|
11
|
|
|
|
|
|
|
NumResults => 1, |
|
12
|
|
|
|
|
|
|
PageNumber => 1, |
|
13
|
|
|
|
|
|
|
TotalNumResults => 1, |
|
14
|
|
|
|
|
|
|
Request => 1 |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Net::Amazon::MechanicalTurk::PagedResultsIterator->attributes(qw{ |
|
18
|
|
|
|
|
|
|
mturk |
|
19
|
|
|
|
|
|
|
operation |
|
20
|
|
|
|
|
|
|
params |
|
21
|
|
|
|
|
|
|
pageSize |
|
22
|
|
|
|
|
|
|
currentPage |
|
23
|
|
|
|
|
|
|
currentResults |
|
24
|
|
|
|
|
|
|
currentResultsPosition |
|
25
|
|
|
|
|
|
|
}); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init { |
|
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
29
|
0
|
|
|
|
|
|
$self->setAttributes(@_); |
|
30
|
0
|
0
|
0
|
|
|
|
if (defined $self->params and $self->params->{PageSize}) { |
|
31
|
0
|
|
|
|
|
|
$self->pageSize($self->params->{PageSize}); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
$self->setAttributesIfNotDefined( |
|
34
|
0
|
|
|
|
|
|
params => {}, |
|
35
|
|
|
|
|
|
|
pageSize => 100 |
|
36
|
|
|
|
|
|
|
); |
|
37
|
0
|
|
|
|
|
|
$self->assertRequiredAttributes(qw{ |
|
38
|
|
|
|
|
|
|
mturk |
|
39
|
|
|
|
|
|
|
operation |
|
40
|
|
|
|
|
|
|
}); |
|
41
|
0
|
|
|
|
|
|
$self->currentResults([]); |
|
42
|
0
|
|
|
|
|
|
$self->currentPage(0); |
|
43
|
0
|
|
|
|
|
|
$self->currentResultsPosition(0); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub next { |
|
47
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $array = $self->currentResults; |
|
50
|
0
|
0
|
|
|
|
|
return undef unless defined($array); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# TODO: make sure this is right |
|
53
|
|
|
|
|
|
|
# perhaps the code should continue until it gets to a page with 0 |
|
54
|
|
|
|
|
|
|
# results. The assumption here is that a page with less items |
|
55
|
|
|
|
|
|
|
# then the requested page size is the last page. |
|
56
|
0
|
0
|
|
|
|
|
if ($self->currentResultsPosition > $#{$array}) { |
|
|
0
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#if (($#{$array}+1) < $self->pageSize) { |
|
58
|
|
|
|
|
|
|
# $self->currentResults(undef); |
|
59
|
|
|
|
|
|
|
# return undef; |
|
60
|
|
|
|
|
|
|
#} |
|
61
|
|
|
|
|
|
|
#else { |
|
62
|
0
|
|
|
|
|
|
$self->currentPage($self->currentPage + 1); |
|
63
|
0
|
|
|
|
|
|
$self->loadPage; |
|
64
|
|
|
|
|
|
|
#} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$array = $self->currentResults; |
|
68
|
0
|
0
|
|
|
|
|
return undef unless defined($array); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ($self->currentResultsPosition > $#{$array}) { |
|
|
0
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->currentResults(undef); |
|
72
|
0
|
|
|
|
|
|
return undef; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $item = $array->[$self->currentResultsPosition]; |
|
76
|
0
|
|
|
|
|
|
$self->currentResultsPosition($self->currentResultsPosition + 1); |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $item; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub loadPage { |
|
82
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
83
|
0
|
|
|
|
|
|
my %params = %{$self->params}; |
|
|
0
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$params{PageNumber} = $self->currentPage; |
|
86
|
0
|
|
|
|
|
|
$params{PageSize} = $self->pageSize; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $result = $self->mturk->call($self->operation, \%params); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (!UNIVERSAL::isa($result, "HASH")) { |
|
91
|
0
|
|
|
|
|
|
Carp::croak("Unexpected result type for " . $self->operation . "."); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$self->currentResults(undef); |
|
95
|
0
|
|
|
|
|
|
$self->currentResultsPosition(0); |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
while (my ($k,$v) = each %$result) { |
|
98
|
0
|
0
|
|
|
|
|
if (! exists $META_RESULT_FIELDS{$k}) { |
|
99
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($v, "ARRAY")) { |
|
100
|
0
|
|
|
|
|
|
$self->currentResults($v); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
else { |
|
103
|
0
|
|
|
|
|
|
$self->currentResults([$v]); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
|
|
|
|
|
last; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return 1; |