| 1 | package AnyEvent::ImageShack; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use AnyEvent::HTTP; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use HTTP::Request::Common 'POST'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.2'; | |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT = qw(image_host); | |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub image_host { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
image_host: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my $cb = pop; | |||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my $url = ''; | |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | if ($file =~ /^http:\/\//) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | $url = $file; | |||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $file = undef; | |||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | my $opt = ref $_[0] ? $_[0] : { @_ }; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | 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'; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$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'
MC/DC0%0/1
$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'
$opt->{'user_agent'}
Truth table0%0/2
A
A= $opt->{'user_agent'}
| |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $AnyEvent::HTTP::MAX_PER_HOST ||= $opt->{'max_per_host'}; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$AnyEvent::HTTP::MAX_PER_HOST ||= $opt->{"max_per_host"}
MC/DC0%0/2
$AnyEvent::HTTP::MAX_PER_HOST ||= $opt->{"max_per_host"}
$AnyEvent::HTTP::MAX_PER_HOST
$opt->{"max_per_host"}
Truth table0%0/3
A ||= B
A= $AnyEvent::HTTP::MAX_PER_HOSTB= $opt->{"max_per_host"}
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $AnyEvent::HTTP::ACTIVE ||= $opt->{'active' }; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$AnyEvent::HTTP::ACTIVE ||= $opt->{"active"}
MC/DC0%0/2
$AnyEvent::HTTP::ACTIVE ||= $opt->{"active"}
$AnyEvent::HTTP::ACTIVE
$opt->{"active"}
Truth table0%0/3
A ||= B
A= $AnyEvent::HTTP::ACTIVEB= $opt->{"active"}
| |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | my $p = POST | ||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | optsize => $opt->{'size'} || 'resample', | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opt->{'tags'} || ''
$opt->{'remove_size'} || 1
$opt->{'size'} || 'resample'
MC/DC0%0/1
$opt->{'tags'} || ''
$opt->{'tags'}
MC/DC0%0/1
$opt->{'remove_size'} || 1
$opt->{'remove_size'}
MC/DC0%0/1
$opt->{'size'} || 'resample'
$opt->{'size'}
Truth table0%0/2
A
A= $opt->{'tags'}
Truth table0%0/2
A
A= $opt->{'remove_size'}
Truth table0%0/2
A
A= $opt->{'size'}
| |||||||||||||||||||||||||||||||||||||||||
| 37 | ] | ||||||||||||||||||||||||||||||||||||||||
| 38 | ; | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | http_post | ||||||||||||||||||||||||||||||||||||||||
| 41 | $p->uri, | ||||||||||||||||||||||||||||||||||||||||
| 42 | $p->content, | ||||||||||||||||||||||||||||||||||||||||
| 43 | recurse => 0, | ||||||||||||||||||||||||||||||||||||||||
| 44 | headers => { | ||||||||||||||||||||||||||||||||||||||||
| 45 | map { | ||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $_ => $p->header($_) | |||||||||||||||||||||||||||||||||||||||
| 47 | } $p->header_field_names | ||||||||||||||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $cb->($_[0] =~ /image_link>([^<>]+)</si); | |||||||||||||||||||||||||||||||||||||||
| 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<AnyEvent::HTTP> | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | =item max_per_host - maximum connections per one host for L<AnyEvent::HTTP> | ||||||||||||||||||||||||||||||||||||||||
| 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<http://github.com/konstantinov/AnyEvent-ImageShack> | ||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | =item * ImageShack API | ||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | L<http://code.google.com/p/imageshackapi/> | ||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||
| 118 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | L<AnyEvent>, L<AnyEvent::HTTP> | ||||||||||||||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||||||||||||||