Webqq/Client/Method/_get_offpic.pm

filter: Statementstmt 26.3% 10 / 38 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 19.4% 13 / 67 CC 13 SCAR 42.4
CC
13
Cov
16%
__ANON__
110.0
_get_offpic
20.0
BEGIN
1.0
CRAP 69.6
« Webqq/Client/Method/_get_img_verify_code.pm ↑ Summary Webqq/Client/Method/_get_group_sig.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use File::Temp qw/:seekable/;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Webqq::Client::Util qw(console);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 0 ▶sub Webqq::Client::_get_offpic {
Subroutine _get_offpic: not called CC=4 SCAR=30.0
5 0 my $self = shift;
6 0 ▶ return if $self->{type} ne 'smartqq';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} ne "smartqq" 0 0 0
7 0 my $file_path = shift;
8 0 my $from_uin = shift;
9 0 my $cb = shift;
10 0 my $api = 'http://w.qq.com/d/channel/get_offpic2';
11 0 ▶ if(ref $cb eq 'CODE'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cb eq "CODE") 0 0 0
12 my @query_string = (
13 file_path => $file_path,
14 f_uin => $from_uin,
15 clientid => $self->{qq_param}{clientid},
16 psessionid => $self->{qq_param}{psessionid},
17 0 );
18 0 ▶ my $callback = sub{
Subroutine __ANON__: not called CC=10 SCAR=47.0
19 0 my $response = shift;
20 0 ▶ if($response->is_success){
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
21 0 ▶ return unless $response->header("content-type") =~/^image\/(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->header("content-type") =~ m[^image/(.*)] 0 0 0
22 0 ▶ my $type = $1=~/jpe?g/i ? ".jpg"
Branch: 4 branches
BranchTrueFalseTotal
$1 =~ /jpe?g/i ? : 0 0 0
$1 =~ /png/i ? : 0 0 0
$1 =~ /bmp/i ? : 0 0 0
$1 =~ /gif/i ? : 0 0 0
23 : $1=~/png/i ? ".png"
24 : $1=~/bmp/i ? ".bmp"
25 : $1=~/gif/i ? ".gif"
26 : undef
27 ;
28 0 ▶ return unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
29 0 my $tmp = File::Temp->new(
30 TEMPLATE => "webqq_offpic_XXXX",
31 SUFFIX => $type,
32 TMPDIR => 1,
33 UNLINK => 1,
34 );
35 0 binmode $tmp;
36 0 print $tmp $response->content();
37 0 close $tmp;
38 0 eval{
39 0 ▶ open(my $fh,"<:raw",$tmp->filename) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $tmp->filename or die $! 0 0 0
40 0 $cb->($fh,$tmp->filename);
41 0 close $fh;
42 };
43 0 ▶ console "[Webqq::Client::_get_offpic] $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
44 }
45 0 };
46 0 require URI;
47 0 my $uri = URI->new('http:');
48 0 $uri->query_form(\@query_string);
49 0 ▶ print "GET $api?" . $uri->query() . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
50 0 $self->{asyn_ua}->get($api ."?". $uri->query(),$callback);
51 }
52 };
53 1 1;
« Webqq/Client/Method/_get_img_verify_code.pm ↑ Summary Webqq/Client/Method/_get_group_sig.pm »