| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Pool.pm |
|
3
|
|
|
|
|
|
|
## Version v0.2.0 |
|
4
|
|
|
|
|
|
|
## Copyright(c) 2022 DEGUEST Pte. Ltd. |
|
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
|
6
|
|
|
|
|
|
|
## Created 2022/03/27 |
|
7
|
|
|
|
|
|
|
## Modified 2023/09/08 |
|
8
|
|
|
|
|
|
|
## All rights reserved. |
|
9
|
|
|
|
|
|
|
## |
|
10
|
|
|
|
|
|
|
## |
|
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
|
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
|
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
14
|
|
|
|
|
|
|
package HTTP::Promise::Pool; |
|
15
|
|
|
|
|
|
|
BEGIN |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
2
|
|
|
2
|
|
16
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
73
|
|
|
18
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
79
|
|
|
19
|
2
|
|
|
2
|
|
11
|
use parent qw( Module::Generic ); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
16
|
|
|
20
|
2
|
|
|
2
|
|
166
|
our $VERSION = 'v0.2.0'; |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
36
|
|
|
24
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1217
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
1
|
|
|
1
|
1
|
8185
|
my $self = shift( @_ ); |
|
29
|
1
|
|
|
|
|
64
|
$self->{host} = undef; |
|
30
|
1
|
|
|
|
|
22
|
$self->{port} = undef; |
|
31
|
1
|
|
|
|
|
9
|
$self->{sock} = undef; |
|
32
|
1
|
|
|
|
|
11
|
$self->{_init_strict_use_sub} = 1; |
|
33
|
1
|
50
|
|
|
|
16
|
$self->SUPER::init( @_ ) || return( $self->pass_error ); |
|
34
|
1
|
|
|
|
|
99
|
return( $self ); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
0
|
sub host { return( shift->_set_get_scalar_as_object( 'host', @_ ) ); } |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub host_port |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
42
|
0
|
|
0
|
|
|
0
|
my $host = $self->host || ''; |
|
43
|
0
|
|
0
|
|
|
0
|
my $port = $self->port || ''; |
|
44
|
0
|
0
|
0
|
|
|
0
|
return( join( ':', $host, $port ) ) if( length( $host ) && length( $port ) ); |
|
45
|
0
|
0
|
|
|
|
0
|
return( $host ) if( length( $host ) ); |
|
46
|
0
|
|
|
|
|
0
|
return; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
sub port { return( shift->_set_get_number( 'port', @_ ) ); } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub push |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
54
|
0
|
|
|
|
|
0
|
my( $host, $port, $sock ) = @_; |
|
55
|
0
|
|
|
|
|
0
|
$self->host( $host ); |
|
56
|
0
|
|
|
|
|
0
|
$self->port( $port ); |
|
57
|
0
|
|
|
|
|
0
|
$self->sock( $sock ); |
|
58
|
0
|
|
|
|
|
0
|
return( $self ); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub reset |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
64
|
0
|
|
|
|
|
0
|
$self->{host} = undef; |
|
65
|
0
|
|
|
|
|
0
|
$self->{port} = undef; |
|
66
|
0
|
|
|
|
|
0
|
return( $self ); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
1
|
0
|
sub sock { return( shift->_set_get_scalar( 'sock', @_ ) ); } |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub steal |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
74
|
0
|
|
|
|
|
0
|
my( $host, $port ) = @_; |
|
75
|
0
|
|
|
|
|
0
|
my $host_port = $self->host_port; |
|
76
|
0
|
0
|
0
|
|
|
0
|
if( defined( $host_port ) && |
|
77
|
|
|
|
|
|
|
$host_port eq "${host}:${port}" ) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
0
|
|
|
|
|
0
|
my $sock = $self->sock; |
|
80
|
0
|
|
|
|
|
0
|
$self->reset; |
|
81
|
0
|
|
|
|
|
0
|
return( $sock ); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
else |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
0
|
|
|
|
|
0
|
return; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub FREEZE |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
1
|
|
|
1
|
0
|
14
|
my $self = CORE::shift( @_ ); |
|
92
|
1
|
|
50
|
|
|
12
|
my $serialiser = CORE::shift( @_ ) // ''; |
|
93
|
1
|
|
|
|
|
10
|
my $class = CORE::ref( $self ); |
|
94
|
1
|
|
|
|
|
17
|
my %hash = %$self; |
|
95
|
1
|
|
|
|
|
25
|
CORE::delete( @hash{ qw( sock ) } ); |
|
96
|
|
|
|
|
|
|
# Return an array reference rather than a list so this works with Sereal and CBOR |
|
97
|
1
|
50
|
33
|
|
|
34
|
CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' || $serialiser eq 'CBOR' ); |
|
98
|
|
|
|
|
|
|
# But Storable want a list with the first element being the serialised element |
|
99
|
1
|
|
|
|
|
50
|
CORE::return( $class, \%hash ); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
1
|
|
|
1
|
0
|
81
|
sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); } |
|
103
|
|
|
|
|
|
|
|
|
104
|
1
|
|
|
1
|
0
|
73
|
sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); } |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# NOTE: sub THAW is inherited |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
|
109
|
|
|
|
|
|
|
# NOTE: POD |
|
110
|
|
|
|
|
|
|
__END__ |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=encoding utf-8 |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
HTTP::Promise::Pool - HTTP Connections Cache |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use HTTP::Promise::Pool; |
|
121
|
|
|
|
|
|
|
my $this = HTTP::Promise::Pool->new || |
|
122
|
|
|
|
|
|
|
die( HTTP::Promise::Pool->error, "\n" ); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 VERSION |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
v0.2.0 |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This modules managed a cache of HTTP connections. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 host |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Sets or gets the host. Returns a L<scalar object|Module::Generic::Scalar> |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 host_port |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Read-only. Returns the host and port separated by a semi colon if a port is defined, otherwise returns just the host. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 port |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Sets or gets the port. Returns a L<number object|Module::Generic::Number> |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 push |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Add the C<host>, C<port> and C<socket> provided to the stack. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 reset |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Resets the C<host> and C<port> |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 sock |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Sets or gets the socket. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 steal |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Provided with an C<host> and C<port>, this checks if those matches the current values, and returns the current socket after resetting the object. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception> |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Copyright(c) 2022 DEGUEST Pte. Ltd. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
All rights reserved. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |