line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Command::Wrapper; |
2
|
4
|
|
|
4
|
|
2216981
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
105
|
|
3
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
154
|
|
4
|
4
|
|
|
4
|
|
30
|
use utf8; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3479
|
use File::Which qw/which/; |
|
4
|
|
|
|
|
4195
|
|
|
4
|
|
|
|
|
318
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
1720
|
use HTTP::Command::Wrapper::Curl; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
126
|
|
11
|
4
|
|
|
4
|
|
1720
|
use HTTP::Command::Wrapper::Wget; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
999
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub create { |
14
|
9
|
|
|
9
|
1
|
14674
|
my $class = shift; |
15
|
9
|
|
|
|
|
16
|
my $opt = {}; |
16
|
9
|
|
|
|
|
14
|
my $type = undef; |
17
|
|
|
|
|
|
|
|
18
|
9
|
100
|
|
|
|
29
|
$opt = $_[0] if ref $_[0] eq 'HASH'; |
19
|
9
|
100
|
|
|
|
25
|
$opt = $_[1] if ref $_[1] eq 'HASH'; |
20
|
|
|
|
|
|
|
|
21
|
9
|
100
|
|
|
|
25
|
$type = $_[0] unless ref $_[0]; |
22
|
9
|
100
|
|
|
|
28
|
$type = $class->_detect_type unless defined $type; |
23
|
|
|
|
|
|
|
|
24
|
9
|
100
|
|
|
|
68
|
return HTTP::Command::Wrapper::Curl->new($opt) if $type eq 'curl'; |
25
|
5
|
100
|
|
|
|
26
|
return HTTP::Command::Wrapper::Wget->new($opt) if $type eq 'wget'; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
13
|
die 'Command not detected (curl or wget)'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _detect_type { |
31
|
3
|
|
|
3
|
|
3919
|
my $class = shift; |
32
|
|
|
|
|
|
|
|
33
|
3
|
100
|
|
|
|
12
|
return 'curl' if $class->_which('curl'); |
34
|
2
|
100
|
|
|
|
18
|
return 'wget' if $class->_which('wget'); |
35
|
1
|
|
|
|
|
8
|
return undef; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
2
|
|
16244
|
sub _which { which($_[1]) } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
__END__ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=encoding utf-8 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
HTTP::Command::Wrapper - The command based HTTP client (wget/curl wrapper). Too minimum dependencies! |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use HTTP::Command::Wrapper; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $client = HTTP::Command::Wrapper->create; # auto detecting (curl or wget) |
54
|
|
|
|
|
|
|
my $content = $client->fetch('https://github.com/'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
print "$content\n"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
HTTP::Command::Wrapper is a very simple HTTP client module. |
61
|
|
|
|
|
|
|
It can wrap C<wget> or C<curl> command, and can use same interface. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 REQUIREMENTS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
C<wget> or C<curl> |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 CLASS METHODS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head3 C<create($options = {})> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Create new wrapper instance using automatic commands detecting. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head3 C<create($type, $options = {})> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Create new wrapper instance. C<'wget'> or C<'curl'> can be specified as C<$type> value. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head4 C<$options> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C<verbose =E<gt> 1> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Turn on verbose output, with all the available data. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<quiet =E<gt> 1> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Turn off output. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head3 C<fetch($url, $headers = [])> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Fetch http/https contents from C<$url>. Return a content body as string. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head3 C<fetch_able($url, $headers = [])> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Return true if C<$url> contents can fetch (status code is C<200>). |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 C<download($url, $path, $headers = [])> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Fetch http/https contents from C<$url>. Save in file. Return process exit code as boolean. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The MIT License (MIT) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Copyright (c) 2015 Pine Mizune |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
114
|
|
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal |
115
|
|
|
|
|
|
|
in the Software without restriction, including without limitation the rights |
116
|
|
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
117
|
|
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is |
118
|
|
|
|
|
|
|
furnished to do so, subject to the following conditions: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in |
121
|
|
|
|
|
|
|
all copies or substantial portions of the Software. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
124
|
|
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
125
|
|
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
126
|
|
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
127
|
|
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
128
|
|
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
129
|
|
|
|
|
|
|
THE SOFTWARE. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Pine Mizune E<lt>pinemz@gmail.comE<gt> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|