line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::ImageShack; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
755
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
4
|
1
|
|
|
1
|
|
1165
|
use AnyEvent::HTTP; |
|
1
|
|
|
|
|
67081
|
|
|
1
|
|
|
|
|
110
|
|
5
|
1
|
|
|
1
|
|
1162
|
use HTTP::Request::Common 'POST'; |
|
1
|
|
|
|
|
34597
|
|
|
1
|
|
|
|
|
77
|
|
6
|
1
|
|
|
1
|
|
11
|
use base 'Exporter'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
387
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw(image_host); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub image_host { |
12
|
0
|
|
|
0
|
1
|
|
my $file = shift; |
13
|
0
|
|
|
|
|
|
my $cb = pop; |
14
|
0
|
|
|
|
|
|
my $url = ''; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
if ($file =~ /^http:\/\//) { |
17
|
0
|
|
|
|
|
|
$url = $file; |
18
|
0
|
|
|
|
|
|
$file = undef; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
0
|
|
|
|
|
my $opt = ref $_[0] ? $_[0] : { @_ }; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
0
|
|
|
|
$AnyEvent::HTTP::USERAGENT = $opt->{'user_agent'} || 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.205 Safari/534.16'; |
23
|
0
|
|
0
|
|
|
|
$AnyEvent::HTTP::MAX_PER_HOST ||= $opt->{'max_per_host'}; |
24
|
0
|
|
0
|
|
|
|
$AnyEvent::HTTP::ACTIVE ||= $opt->{'active' }; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
0
|
|
|
|
my $p = POST |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
27
|
|
|
|
|
|
|
'http://www.imageshack.us/upload_api.php', |
28
|
|
|
|
|
|
|
Content_Type => 'multipart/form-data', |
29
|
|
|
|
|
|
|
Content => [ |
30
|
|
|
|
|
|
|
fileupload => $file ? [ $file ] : [ '' ], |
31
|
|
|
|
|
|
|
url => $url, |
32
|
|
|
|
|
|
|
tags => $opt->{'tags'} || '', |
33
|
|
|
|
|
|
|
rembar => $opt->{'remove_size'} || 1, |
34
|
|
|
|
|
|
|
optimage => 1, |
35
|
|
|
|
|
|
|
key => $opt->{'key'}, |
36
|
|
|
|
|
|
|
optsize => $opt->{'size'} || 'resample', |
37
|
|
|
|
|
|
|
] |
38
|
|
|
|
|
|
|
; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
http_post |
41
|
|
|
|
|
|
|
$p->uri, |
42
|
|
|
|
|
|
|
$p->content, |
43
|
|
|
|
|
|
|
recurse => 0, |
44
|
|
|
|
|
|
|
headers => { |
45
|
|
|
|
|
|
|
map { |
46
|
|
|
|
|
|
|
$_ => $p->header($_) |
47
|
|
|
|
|
|
|
} $p->header_field_names |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
sub { |
50
|
0
|
|
|
0
|
|
|
$cb->($_[0] =~ /image_link>([^<>]+)
|
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
AnyEvent::ImageShack - simple non-blocking client for image hosting ImageShack.us |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 VERSION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
0.2 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNOPSIS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
use AnyEvent::ImageShack; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $c = AnyEvent->condvar; |
69
|
|
|
|
|
|
|
image_host('url/or/path/to/image.png', key => 'developer_key123', sub { warn shift; $c->send }); |
70
|
|
|
|
|
|
|
$c->recv; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over 4 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item image_host $image, option => value, ..., $callback |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Host image C<$image> to ImageShack.us |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=back |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 OPTIONS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item user_agent - UserAgent string |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item active - number of active connections for L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item max_per_host - maximum connections per one host for L |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item key - developer key for ImageShack API |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item tags - tags for hosted image |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item remove_size - remove information about size from thumbnails (by default 1) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item size - resize image to specified resolution (by default don't resize) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SUPPORT |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * Repository |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * ImageShack API |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=back |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L, L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Copyright 2010-2012 Dmitry Konstantinov. All right reserved. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |