line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
88613
|
use 5.006; # pragmas, our |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
189
|
|
2
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
119
|
|
3
|
3
|
|
|
3
|
|
44
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
273
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package HTTP::Tiny::Mech; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.001001'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Wrap a WWW::Mechanize instance in an HTTP::Tiny compatible interface. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
3004
|
use parent 'HTTP::Tiny'; |
|
3
|
|
|
|
|
997
|
|
|
3
|
|
|
|
|
17
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
5
|
|
|
5
|
1
|
29100
|
my ( $self, %args ) = @_; |
17
|
5
|
|
|
|
|
8
|
my ( $mechua, $has_mechua ); |
18
|
5
|
100
|
|
|
|
25
|
if ( exists $args{mechua} ) { |
19
|
2
|
|
|
|
|
6
|
$has_mechua = 1; |
20
|
2
|
|
|
|
|
8
|
$mechua = delete $args{mechua}; |
21
|
|
|
|
|
|
|
} |
22
|
5
|
|
|
|
|
48
|
my $instance = $self->SUPER::new(%args); |
23
|
5
|
100
|
|
|
|
604
|
if ($has_mechua) { |
24
|
2
|
|
|
|
|
6
|
$instance->{mechua} = $mechua; |
25
|
|
|
|
|
|
|
} |
26
|
5
|
|
|
|
|
23
|
return bless $instance, $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
30
|
|
|
|
|
|
|
sub mechua { |
31
|
15
|
|
|
15
|
1
|
8791
|
my ( $self, $new_mechua, $has_new_mechua ) = ( $_[0], $_[1], @_ > 1 ); |
32
|
15
|
100
|
|
|
|
183
|
if ($has_new_mechua) { |
33
|
1
|
|
|
|
|
3
|
$self->{mechua} = $new_mechua; |
34
|
|
|
|
|
|
|
} |
35
|
15
|
100
|
|
|
|
146
|
return $self->{mechua} if exists $self->{mechua}; |
36
|
1
|
|
|
|
|
1486
|
require WWW::Mechanize; |
37
|
1
|
|
|
|
|
283943
|
return ( $self->{mechua} = WWW::Mechanize->new() ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
## use critic |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _unwrap_response { |
51
|
4
|
|
|
4
|
|
29356
|
my ( undef, $response ) = @_; |
52
|
|
|
|
|
|
|
return { |
53
|
4
|
|
|
|
|
17
|
status => $response->code, |
54
|
|
|
|
|
|
|
reason => $response->message, |
55
|
|
|
|
|
|
|
headers => $response->headers, |
56
|
|
|
|
|
|
|
success => $response->is_success, |
57
|
|
|
|
|
|
|
content => $response->content, |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _wrap_request { |
62
|
2
|
|
|
2
|
|
7
|
my ( undef, $method, $uri, $opts ) = @_; |
63
|
2
|
|
|
|
|
1266
|
require HTTP::Request; |
64
|
2
|
|
|
|
|
1050
|
my $req = HTTP::Request->new( $method, $uri ); |
65
|
2
|
100
|
|
|
|
22418
|
$req->headers( $opts->{headers} ) if $opts->{headers}; |
66
|
2
|
100
|
|
|
|
21
|
$req->content( $opts->{content} ) if $opts->{content}; |
67
|
2
|
|
|
|
|
26
|
return $req; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get { |
79
|
2
|
|
|
2
|
1
|
15
|
my ( $self, $uri, $opts ) = @_; |
80
|
2
|
100
|
|
|
|
8
|
return $self->_unwrap_response( $self->mechua->get( $uri, ( $opts ? %{$opts} : () ) ) ); |
|
1
|
|
|
|
|
10
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub request { |
90
|
2
|
|
|
2
|
1
|
19
|
my ( $self, @request ) = @_; |
91
|
2
|
|
|
|
|
27
|
my $req = $self->_wrap_request(@request); |
92
|
2
|
|
|
|
|
10
|
my $response = $self->mechua->request($req); |
93
|
2
|
|
|
|
|
140
|
return $self->_unwrap_response($response); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |