line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::PgX::Cursor::Results; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Mojo::IOLoop; |
4
|
|
|
|
|
|
|
require Mojo::PgX::Cursor::Cursor; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Time::HiRes qw(time); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
175
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has [qw(seconds_blocked fetch)]; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub array { |
13
|
0
|
|
|
0
|
1
|
|
my $self = shift->_fetch; |
14
|
0
|
|
|
|
|
|
$self->{remaining}--; |
15
|
0
|
|
|
|
|
|
return $self->{results}->array; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
|
sub columns { shift->_results->columns } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub cursor { |
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
22
|
0
|
0
|
|
|
|
|
if (@_) { |
23
|
0
|
0
|
|
|
|
|
if ($self->{delay}) { |
24
|
0
|
|
|
|
|
|
$self->{delay}->wait; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$self->{cursor} = shift; |
27
|
0
|
|
|
|
|
|
$self->{remaining} = 0; |
28
|
0
|
|
|
|
|
|
delete $self->{delay}; |
29
|
0
|
|
|
|
|
|
delete $self->{next}; |
30
|
0
|
|
|
|
|
|
delete $self->{results}; |
31
|
0
|
|
|
|
|
|
return $self->_load_next; |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
|
return $self->{cursor}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub hash { |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift->_fetch; |
38
|
0
|
|
|
|
|
|
$self->{remaining}--; |
39
|
0
|
|
|
|
|
|
return $self->{results}->hash; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub expand { |
43
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
$self->{expand}++; |
45
|
0
|
0
|
|
|
|
|
if ($self->{results}) { |
46
|
0
|
|
|
|
|
|
$self->{results}->expand; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub new { |
52
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
53
|
0
|
|
|
|
|
|
return $self->_load_next; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
1
|
|
sub rows { shift->_results->rows } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _fetch { |
59
|
0
|
|
|
0
|
|
|
my $self = shift; |
60
|
0
|
0
|
|
|
|
|
return $self if $self->{remaining}; |
61
|
0
|
0
|
|
|
|
|
unless ($self->{next}) { |
62
|
0
|
|
|
|
|
|
my $start = time; |
63
|
0
|
|
|
|
|
|
$self->{delay}->wait; |
64
|
0
|
|
|
|
|
|
$self->{seconds_blocked} += time - $start; |
65
|
0
|
|
|
|
|
|
delete $self->{delay}; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
$self->{results} = delete $self->{next}; |
68
|
0
|
|
|
|
|
|
$self->{remaining} = $self->{results}->rows; |
69
|
0
|
|
|
|
|
|
return $self->_load_next; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _load_next { |
73
|
0
|
|
|
0
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
$self->{delay} = Mojo::IOLoop->delay( |
75
|
|
|
|
|
|
|
sub { |
76
|
0
|
|
|
0
|
|
|
$self->cursor->fetch($self->{fetch}, shift->begin); |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
sub { |
79
|
0
|
|
|
0
|
|
|
$self->{next} = $_[2]; |
80
|
0
|
0
|
|
|
|
|
$self->{next}->expand if ($self->{expand}); |
81
|
|
|
|
|
|
|
}, |
82
|
0
|
|
|
|
|
|
); |
83
|
0
|
|
|
|
|
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _results { |
87
|
0
|
|
|
0
|
|
|
my $self = shift; |
88
|
0
|
0
|
|
|
|
|
return $self->{results} if $self->{results}; |
89
|
0
|
|
|
|
|
|
return $self->_fetch->{results}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |