| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Geonode::Free::Proxy; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
527
|
use 5.010; |
|
|
3
|
|
|
|
|
19
|
|
|
4
|
3
|
|
|
3
|
|
28
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
84
|
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
93
|
|
|
6
|
3
|
|
|
3
|
|
14
|
use Carp 'croak'; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
2408
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Geonode::Free::Proxy - Geonode's Proxy Object returned by Geonode::Free::ProxyList |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Note: this a companion module for Geonode::Free::ProxyList |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 VERSION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Version 0.0.5 |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.0.5'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $preferred_method = 'socks'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Geonode's Proxy Object returned by Geonode::Free::ProxyList |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $some_proxy = Geonode::Free::Proxy->new( |
|
29
|
|
|
|
|
|
|
'some-id', |
|
30
|
|
|
|
|
|
|
'127.0.0.1', |
|
31
|
|
|
|
|
|
|
3128, |
|
32
|
|
|
|
|
|
|
[ 'http', 'socks5' ] |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$some_proxy->get_host(); # '127.0.0.1' |
|
36
|
|
|
|
|
|
|
$some_proxy->get_port(); # 3128 |
|
37
|
|
|
|
|
|
|
$some_proxy->get_methods(); # [ 'http', 'socks5' ] |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $other_proxy = Geonode::Free::Proxy->new( |
|
40
|
|
|
|
|
|
|
'some-id', |
|
41
|
|
|
|
|
|
|
'127.0.0.1', |
|
42
|
|
|
|
|
|
|
3128, |
|
43
|
|
|
|
|
|
|
[ 'http', 'socks5' ] |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Geonode::Free::Proxy::prefer_socks(); |
|
47
|
|
|
|
|
|
|
$some_proxy->get_url(); # 'socks://127.0.0.1:3128'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Geonode::Free::Proxy::prefer_http(); |
|
50
|
|
|
|
|
|
|
$other_proxy->get_url(); # 'http://127.0.0.1:3128'; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $http_proxy = Geonode::Free::Proxy->new( |
|
53
|
|
|
|
|
|
|
'some-id', |
|
54
|
|
|
|
|
|
|
'127.0.0.1', |
|
55
|
|
|
|
|
|
|
3128, |
|
56
|
|
|
|
|
|
|
[ 'http' ] |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$http_proxy->can_use_http(); # 1; |
|
60
|
|
|
|
|
|
|
$http_proxy->can_use_socks(); # 0; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Geonode::Free::Proxy::prefer_socks(); |
|
63
|
|
|
|
|
|
|
$http_proxy->get_url(); # 'http://127.0.0.1:3128'; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 new |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Instantiate Geonode::Free::Proxy object (id, host, port, methods) |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub new { |
|
74
|
17
|
|
|
17
|
1
|
325
|
my ( $class, $id, $host, $port, $methods ) = @_; |
|
75
|
|
|
|
|
|
|
|
|
76
|
17
|
50
|
33
|
|
|
142
|
if ( !defined $id || $id =~ m{^\s*+$}sxmi ) { |
|
77
|
0
|
|
|
|
|
0
|
croak 'ERROR: id not informed'; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
17
|
100
|
66
|
|
|
80
|
if ( !defined $host || $host =~ m{^\s*+$}sxmi ) { |
|
81
|
1
|
|
|
|
|
17
|
croak 'ERROR: host not informed'; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
16
|
100
|
66
|
|
|
74
|
if ( !defined $port || $port !~ m{^[1-9][0-9]*+$}sxmi ) { |
|
85
|
1
|
|
|
|
|
9
|
croak 'ERROR: port must be a number'; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
15
|
100
|
66
|
|
|
69
|
if ( !defined $methods || ref($methods) ne 'ARRAY' ) { |
|
89
|
1
|
|
|
|
|
10
|
croak 'ERROR: methods must be an array reference'; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
14
|
100
|
|
|
|
22
|
if ( @{$methods} == 0 ) { |
|
|
14
|
|
|
|
|
34
|
|
|
93
|
1
|
|
|
|
|
9
|
croak 'ERROR: no informed methods'; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
13
|
|
|
|
|
23
|
foreach my $method ( @{$methods} ) { |
|
|
13
|
|
|
|
|
24
|
|
|
97
|
23
|
100
|
|
|
|
217
|
if ( $method !~ m{^(?>socks[45]|https?)$}sxm ) { |
|
98
|
1
|
|
|
|
|
12
|
croak q() |
|
99
|
|
|
|
|
|
|
. "ERROR: '$method' is not a valid method\n" |
|
100
|
|
|
|
|
|
|
. ' Valid methods are: socks4/socks5/http/https'; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
12
|
|
|
|
|
52
|
my $self = { |
|
105
|
|
|
|
|
|
|
id => $id, |
|
106
|
|
|
|
|
|
|
host => $host, |
|
107
|
|
|
|
|
|
|
port => $port, |
|
108
|
|
|
|
|
|
|
methods => $methods |
|
109
|
|
|
|
|
|
|
}; |
|
110
|
|
|
|
|
|
|
|
|
111
|
12
|
|
|
|
|
58
|
return bless $self, $class; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 prefer_socks |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Sets preferred method to socks. This is used when getting the full proxy url. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Preferred method is set up *globally*. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub prefer_socks { |
|
123
|
1
|
|
|
1
|
1
|
3
|
$preferred_method = 'socks'; |
|
124
|
1
|
|
|
|
|
2
|
return; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 prefer_http |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Sets preferred method to http. This is used when getting the full proxy url. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Preferred method is set up *globally*. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub prefer_http { |
|
136
|
1
|
|
|
1
|
1
|
6
|
$preferred_method = 'http'; |
|
137
|
1
|
|
|
|
|
3
|
return; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 get_preferred_method |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Gets preferred method |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub get_preferred_method { |
|
147
|
0
|
|
|
0
|
1
|
0
|
return $preferred_method; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 get_id |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Gets host |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub get_id { |
|
157
|
4
|
|
|
4
|
1
|
2996
|
my $self = shift; |
|
158
|
4
|
|
|
|
|
25
|
return $self->{id}; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 get_host |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Gets host |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub get_host { |
|
168
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
|
169
|
4
|
|
|
|
|
16
|
return $self->{host}; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 get_port |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Gets port |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub get_port { |
|
179
|
4
|
|
|
4
|
1
|
10
|
my $self = shift; |
|
180
|
4
|
|
|
|
|
21
|
return $self->{port}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 get_methods |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Gets methods |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub get_methods { |
|
190
|
7
|
|
|
7
|
1
|
22
|
my $self = shift; |
|
191
|
7
|
|
|
|
|
26
|
return @{ $self->{methods} }; |
|
|
7
|
|
|
|
|
36
|
|
|
192
|
|
|
|
|
|
|
} |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 can_use_socks |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Returns truthy if proxy can use socks method |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub can_use_socks { |
|
201
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
202
|
3
|
|
|
|
|
6
|
return 0 < grep { m{^socks}sxmi } $self->get_methods(); |
|
|
12
|
|
|
|
|
45
|
|
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 can_use_http |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Returns truthy if proxy can use http method |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub can_use_http { |
|
212
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
213
|
2
|
|
|
|
|
5
|
return 0 < grep { m{^http}sxmi } $self->get_methods(); |
|
|
8
|
|
|
|
|
30
|
|
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 get_url |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Gets proxy url |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub get_url { |
|
223
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
|
224
|
|
|
|
|
|
|
|
|
225
|
2
|
|
|
|
|
4
|
my $method; |
|
226
|
2
|
100
|
66
|
|
|
5
|
if ( $self->can_use_socks && $preferred_method eq 'socks' ) { |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
227
|
1
|
|
|
|
|
3
|
$method = 'socks'; |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
elsif ( $self->can_use_http && $preferred_method eq 'http' ) { |
|
230
|
1
|
|
|
|
|
2
|
$method = 'http'; |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
elsif ( $self->can_use_socks ) { |
|
233
|
0
|
|
|
|
|
0
|
$method = 'socks'; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
elsif ( $self->can_use_http ) { |
|
236
|
0
|
|
|
|
|
0
|
$method = 'http'; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
else { |
|
239
|
0
|
|
|
|
|
0
|
croak 'ERROR: Cannot find a valid method'; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
2
|
|
|
|
|
7
|
return $method . q(://) . $self->get_host() . q(:) . $self->get_port(); |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 AUTHOR |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Julio de Castro, C<< >> |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head1 BUGS |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
252
|
|
|
|
|
|
|
the web interface at L. |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head1 SUPPORT |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
perldoc Geonode::Free::Proxy |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
You can also look for information at: |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=over 4 |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
L |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
L |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * Search CPAN |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
L |
|
278
|
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=back |
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
286
|
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This software is Copyright (c) 2021 by Julio de Castro. |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
This is free software, licensed under: |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
1; # End of Geonode::Free::Proxy |