line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Tinyish; |
2
|
1
|
|
|
1
|
|
68187
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
5
|
use Carp (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
122
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $PreferredBackend; # for tests |
9
|
|
|
|
|
|
|
our @Backends = map "HTTP::Tinyish::$_", qw( LWP HTTPTiny Curl Wget ); |
10
|
|
|
|
|
|
|
my %configured; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my($class, %attr) = @_; |
14
|
0
|
|
|
|
|
|
bless \%attr, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
for my $method (qw/get head put post delete mirror patch/) { |
18
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
417
|
|
19
|
0
|
|
|
0
|
0
|
|
eval <<"HERE"; |
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub $method { |
21
|
|
|
|
|
|
|
my \$self = shift; |
22
|
|
|
|
|
|
|
\$self->_backend_for(\$_[0])->$method(\@_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
HERE |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub request { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
$self->_backend_for($_[1])->request(@_); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _backend_for { |
33
|
0
|
|
|
0
|
|
|
my($self, $url) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my($scheme) = $url =~ m!^(https?):!; |
36
|
0
|
0
|
|
|
|
|
Carp::croak "URL Scheme '$url' not supported." unless $scheme; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
for my $backend ($self->backends) { |
39
|
0
|
0
|
|
|
|
|
$self->configure_backend($backend) or next; |
40
|
0
|
0
|
|
|
|
|
if ($backend->supports($scheme)) { |
41
|
0
|
|
|
|
|
|
return $backend->new(%$self); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
Carp::croak "No backend configured for scheme $scheme"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub backends { |
49
|
0
|
0
|
|
0
|
0
|
|
$PreferredBackend ? ($PreferredBackend) : @Backends; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub configure_backend { |
53
|
0
|
|
|
0
|
0
|
|
my($self, $backend) = @_; |
54
|
0
|
0
|
|
|
|
|
unless (exists $configured{$backend}) { |
55
|
|
|
|
|
|
|
$configured{$backend} = |
56
|
0
|
|
|
|
|
|
eval { require_module($backend); $backend->configure }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
$configured{$backend}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub require_module { |
62
|
0
|
|
|
0
|
0
|
|
local $_ = shift; |
63
|
0
|
|
|
|
|
|
s!::!/!g; |
64
|
0
|
|
|
|
|
|
require "$_.pm"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |