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
|
|
5
|
use Time::HiRes qw(time); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
168
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has [qw(seconds_blocked)]; |
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
|
|
|
|
|
|
$self->wait; |
24
|
0
|
|
|
|
|
|
$self->{cursor} = shift; |
25
|
0
|
|
|
|
|
|
$self->{remaining} = 0; |
26
|
0
|
|
|
|
|
|
delete $self->{delay}; |
27
|
0
|
|
|
|
|
|
delete $self->{next}; |
28
|
0
|
|
|
|
|
|
delete $self->{results}; |
29
|
0
|
|
|
|
|
|
return $self->_load_next; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
return $self->{cursor}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub expand { |
35
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
$self->{expand}++; |
37
|
0
|
0
|
|
|
|
|
if ($self->{results}) { |
38
|
0
|
|
|
|
|
|
$self->{results}->expand; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub hash { |
44
|
0
|
|
|
0
|
1
|
|
my $self = shift->_fetch; |
45
|
0
|
|
|
|
|
|
$self->{remaining}--; |
46
|
0
|
|
|
|
|
|
return $self->{results}->hash; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
51
|
0
|
|
|
|
|
|
return $self->_load_next; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub rows { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
0
|
|
|
|
|
return $self->_results->rows unless @_; |
57
|
0
|
|
|
|
|
|
$self->{rows} = shift; |
58
|
0
|
|
|
|
|
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub wait { |
62
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
63
|
0
|
0
|
|
|
|
|
if ($self->{delay}) { |
64
|
0
|
|
|
|
|
|
$self->{delay}->wait; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return $self; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _fetch { |
70
|
0
|
|
|
0
|
|
|
my $self = shift; |
71
|
0
|
0
|
|
|
|
|
return $self if $self->{remaining}; |
72
|
0
|
0
|
|
|
|
|
unless ($self->{next}) { |
73
|
0
|
|
|
|
|
|
my $start = time; |
74
|
0
|
|
|
|
|
|
$self->wait; |
75
|
0
|
|
|
|
|
|
$self->{seconds_blocked} += time - $start; |
76
|
0
|
|
|
|
|
|
delete $self->{delay}; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
$self->{results} = delete $self->{next}; |
79
|
0
|
|
|
|
|
|
$self->{remaining} = $self->{results}->rows; |
80
|
0
|
|
|
|
|
|
return $self->_load_next; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _load_next { |
84
|
0
|
|
|
0
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
$self->{delay} = Mojo::IOLoop->delay( |
86
|
|
|
|
|
|
|
sub { |
87
|
0
|
|
|
0
|
|
|
$self->cursor->fetch($self->{rows}, shift->begin); |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
sub { |
90
|
0
|
|
|
0
|
|
|
$self->{next} = $_[2]; |
91
|
0
|
0
|
|
|
|
|
$self->{next}->expand if ($self->{expand}); |
92
|
|
|
|
|
|
|
}, |
93
|
0
|
|
|
|
|
|
); |
94
|
0
|
|
|
|
|
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _results { |
98
|
0
|
|
|
0
|
|
|
my $self = shift; |
99
|
0
|
0
|
|
|
|
|
return $self->{results} if $self->{results}; |
100
|
0
|
|
|
|
|
|
return $self->_fetch->{results}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
__END__ |