Webqq/Client/Method/_get_group_info.pm

filter: Statementstmt 11.8% 7 / 59 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 10.0% 9 / 90 CC 20 SCAR 59.5
CC
20
Cov
8%
_get_group_info
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 381.9
« Webqq/Client/Plugin/LinkInfo.pm ↑ Summary Webqq/Client/Method/_login1.pm »
1 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use Webqq::Client::Util qw(console code2state code2client);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 0 ▶sub Webqq::Client::_get_group_info {
Subroutine _get_group_info: not called CC=20 SCAR=60.4
4 0 my $self = shift;
5 0 my $gcode = shift;
6 0 my $ua = $self->{ua};
7 0 my $api_url = 'http://s.web2.qq.com/api/get_group_info_ext2';
8 my @query_string = (
9 gcode => $gcode,
10 vfwebqq => $self->{qq_param}{vfwebqq},
11 0 t => time(),
12 );
13  
14 0 ▶ if($self->{type} eq 'webqq'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"} eq "webqq") 0 0 0
15 0 splice @query_string,2,0,(cb => "undefined");
16 }
17  
18 0 my @query_string_pairs;
19 0 ▶ push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string);
Branch: 1 branch
BranchTrueFalseTotal
@query_string and do { push @query_string_pairs, shift(@query_string) . '=' . shift(@query_string) } 0 0 0
20 0 ▶ my @headers = $self->{type} eq 'webqq'? (Referer => 'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=3')
Branch: 1 branch
BranchTrueFalseTotal
$self->{'type'} eq 'webqq' ? : 0 0 0
21 : (Referer => 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1')
22 ;
23 0 my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
24 0 ▶ if($response->is_success){
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
25 0 my $json;
26 0 eval{
27 0 $json = JSON->new->utf8->decode($response->content()) ;
28 };
29 0 ▶ $json = {} unless defined $json;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $json 0 0 0
30 0 ▶ my $ginfo_status = exists $json->{result}{ginfo}?"[ginfo-ok]":"[ginfo-not-ok]";
Branch: 1 branch
BranchTrueFalseTotal
exists $json->{'result'}{'ginfo'} ? : 0 0 0
31 0 ▶ my $minfo_status = exists $json->{result}{minfo}?"[minfo-ok]":"[minfo-not-ok]";
Branch: 1 branch
BranchTrueFalseTotal
exists $json->{'result'}{'minfo'} ? : 0 0 0
32
33 0 ▶ if($self->{debug}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 0 0
34 0 print substr($response->content(),0,80),"${ginfo_status}${minfo_status}...\n";
35 0 ▶ console $@."\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
36 }
37  
38 0 ▶ return undef unless exists $json->{result}{ginfo};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $json->{"result"}{"ginfo"} 0 0 0
39 #return undef unless exists $json->{result}{minfo};
40 0 delete $json->{result}{ginfo}{members};
41 0 for(keys %{$json->{result}{ginfo}}){
42 0 $json->{result}{ginfo}{$_} = encode("utf8",$json->{result}{ginfo}{$_});
43 }
44 #retcode等于0说明包含完整的ginfo和minfo
45 0 ▶ if($json->{retcode}==0){
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'retcode'} == 0) { } 0 0 0
46 0 ▶ return undef unless exists $json->{result}{minfo};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $json->{"result"}{"minfo"} 0 0 0
47 0 my %cards;
48 0 for (@{ $json->{result}{cards} }){
49 0 $cards{$_->{muin}} = $_->{card};
50 }
51 0 my %state;
52 0 for(@{ $json->{result}{stats} }){
53 0 $state{$_->{uin}}{client_type} = $_->{client_type};
54 0 $state{$_->{uin}}{state} = code2state($_->{'stat'});
55 }
56 0 for my $m(@{ $json->{result}{minfo} }){
57 0 ▶ $m->{card} = $cards{$m->{uin}} if exists $cards{$m->{uin}} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $cards{$m->{"uin"}} 0 0 0
58 0 ▶ if(exists $state{$m->{uin}}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state{$m->{'uin'}}) { } 0 0 0
59 0 $m->{state} = $state{$m->{uin}}{state};
60 0 $m->{client_type} = code2client($state{$m->{uin}}{client_type});
61 }
62 else{
63 0 $m->{state} = 'offline';
64 0 $m->{client_type} = 'unknown';
65 }
66 0 for(keys %$m){
67 0 $m->{$_} = encode("utf8",$m->{$_});
68 }
69 }
70 my $group_info = {
71 ginfo => $json->{result}{ginfo},
72 minfo => $json->{result}{minfo},
73 0 };
74 #查询结果同时进行缓存,以优化查询速度
75 #$self->{cache_for_group}->store($gcode,$group_info);
76 0 return $group_info;
77 }
78 #只存在ginfo
79 else{
80 my $group_info = {
81 ginfo => $json->{result}{ginfo},
82 0 };
83 0 return $group_info;
84 }
85 }
86 0 else{return undef;}
87 }
88 1 1;
« Webqq/Client/Plugin/LinkInfo.pm ↑ Summary Webqq/Client/Method/_login1.pm »