line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::cloudconvert; |
2
|
1
|
|
|
1
|
|
15882
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
22
|
use 5.008_005; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
485
|
use LWP; |
|
1
|
|
|
|
|
38965
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
638
|
use HTTP::Request::Common qw(POST); |
|
1
|
|
|
|
|
1678
|
|
|
1
|
|
|
|
|
319
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
0
|
14
|
my ($class, %config) = @_; |
12
|
1
|
|
|
|
|
4
|
bless \%config, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub convert { |
16
|
0
|
|
|
0
|
0
|
|
my ($self, $inputfile, $outputfile) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
my $ua = LWP::UserAgent->new( |
19
|
|
|
|
|
|
|
timeout => $self->{wait}, |
20
|
|
|
|
|
|
|
$self->{agent} ? (agent => $self->{agent}) : (), |
21
|
|
|
|
|
|
|
); # TODO: check SSL ? |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my %params = ( |
24
|
|
|
|
|
|
|
inputformat => $self->{from}, |
25
|
|
|
|
|
|
|
outputformat => $self->{to}, |
26
|
|
|
|
|
|
|
apikey => $self->{apikey}, |
27
|
|
|
|
|
|
|
input => "upload", |
28
|
|
|
|
|
|
|
download => "inline", |
29
|
|
|
|
|
|
|
file => [ $inputfile ] |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if ($self->{dry}) { |
33
|
0
|
|
|
|
|
|
foreach (keys %params) { |
34
|
0
|
0
|
|
|
|
|
print "$_: ".(ref $params{$_} ? $params{$_}->[0] : $params{$_}) . "\n" |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
print "inputfile: $inputfile\n"; |
37
|
0
|
|
|
|
|
|
print "outputfile: $outputfile\n"; |
38
|
0
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $response = $ua->request(POST $self->{url}, |
42
|
|
|
|
|
|
|
Content_Type => 'multipart/form-data', |
43
|
|
|
|
|
|
|
Content => \%params |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($response->code == '303') { |
47
|
0
|
|
|
|
|
|
$response = $ua->mirror( $response->header('location'), $outputfile ); |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
my $error = "conversion failed"; |
50
|
0
|
0
|
|
|
|
|
if (!$response->is_success) { |
51
|
0
|
0
|
|
|
|
|
if ($response->header('content-type') eq 'application/json') { |
52
|
0
|
|
|
|
|
|
my $content = from_json($response->decoded_content); |
53
|
0
|
|
|
|
|
|
$error = $content->{error}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
say STDERR $response->code, ": ", $error; |
57
|
0
|
|
|
|
|
|
return 1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |