line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
59735
|
use 5.006; # pragmas, our |
|
5
|
|
|
|
|
12
|
|
2
|
5
|
|
|
5
|
|
17
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
99
|
|
3
|
5
|
|
|
5
|
|
24
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
341
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package HTTP::Tiny::Mech; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.001002'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Wrap a WWW::Mechanize instance in an HTTP::Tiny compatible interface. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
1915
|
use parent 'HTTP::Tiny'; |
|
5
|
|
|
|
|
1219
|
|
|
5
|
|
|
|
|
23
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
5
|
|
|
5
|
1
|
13053
|
my ( $self, %args ) = @_; |
17
|
5
|
|
|
|
|
8
|
my ( $mechua, $has_mechua ); |
18
|
5
|
100
|
|
|
|
17
|
if ( exists $args{mechua} ) { |
19
|
2
|
|
|
|
|
3
|
$has_mechua = 1; |
20
|
2
|
|
|
|
|
6
|
$mechua = delete $args{mechua}; |
21
|
|
|
|
|
|
|
} |
22
|
5
|
|
|
|
|
52
|
my $instance = $self->SUPER::new(%args); |
23
|
5
|
100
|
|
|
|
419
|
if ($has_mechua) { |
24
|
2
|
|
|
|
|
7
|
$instance->{mechua} = $mechua; |
25
|
|
|
|
|
|
|
} |
26
|
5
|
|
|
|
|
14
|
return bless $instance, $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## no critic (Subroutines::RequireArgUnpacking) |
30
|
|
|
|
|
|
|
sub mechua { |
31
|
15
|
|
|
15
|
1
|
12529
|
my ( $self, $new_mechua, $has_new_mechua ) = ( $_[0], $_[1], @_ > 1 ); |
32
|
15
|
100
|
|
|
|
44
|
if ($has_new_mechua) { |
33
|
1
|
|
|
|
|
2
|
$self->{mechua} = $new_mechua; |
34
|
|
|
|
|
|
|
} |
35
|
15
|
100
|
|
|
|
96
|
return $self->{mechua} if exists $self->{mechua}; |
36
|
1
|
|
|
|
|
809
|
require WWW::Mechanize; |
37
|
1
|
|
|
|
|
102853
|
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
|
|
19723
|
my ( undef, $response ) = @_; |
52
|
|
|
|
|
|
|
return { |
53
|
4
|
|
|
|
|
10
|
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
|
|
5
|
my ( undef, $method, $uri, $opts ) = @_; |
63
|
2
|
|
|
|
|
470
|
require HTTP::Request; |
64
|
2
|
|
|
|
|
762
|
my $req = HTTP::Request->new( $method, $uri ); |
65
|
2
|
100
|
|
|
|
5443
|
$req->headers( $opts->{headers} ) if $opts->{headers}; |
66
|
2
|
100
|
|
|
|
11
|
$req->content( $opts->{content} ) if $opts->{content}; |
67
|
2
|
|
|
|
|
19
|
return $req; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get { |
79
|
2
|
|
|
2
|
1
|
13
|
my ( $self, $uri, $opts ) = @_; |
80
|
2
|
100
|
|
|
|
5
|
return $self->_unwrap_response( $self->mechua->get( $uri, ( $opts ? %{$opts} : () ) ) ); |
|
1
|
|
|
|
|
8
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub request { |
90
|
2
|
|
|
2
|
1
|
12
|
my ( $self, @request ) = @_; |
91
|
2
|
|
|
|
|
7
|
my $req = $self->_wrap_request(@request); |
92
|
2
|
|
|
|
|
8
|
my $response = $self->mechua->request($req); |
93
|
2
|
|
|
|
|
88
|
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__ |