Webqq/Model/Remote/_get_user_friends.pm

filter: Statementstmt 1.6% 1 / 61 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 1.1% 1 / 86 CC 16 SCAR 48.5
CC
16
Cov
1%
__ANON__
182.0
_get_user_friends
12.0
__ANON__
6.0
CRAP 127.2
« Webqq/Client/Remote/_relink.pm ↑ Summary Webqq/Discuss.pm »
1 0 ▶sub Mojo::Webqq::Model::_get_user_friends{
Subroutine _get_user_friends: not called CC=3 SCAR=24.8
2 0 my $self = shift;
3 0 my $callback = shift;
4 0 my $api_url = 'https://s.web2.qq.com/api/get_user_friends2';
5 0 my $headers = {
6 Referer=>'https://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
7 json=>1,
8 ua_request_timeout => $self->model_update_timeout,
9 ua_retry_times => 3,
10 };
11 0 my %r = (
12 hash => $self->hash($self->ptwebqq,$self->uid),
13 vfwebqq => $self->vfwebqq,
14 );
15
16 0 ▶ my $is_blocking = ref $callback eq "CODE"?0:1;
Branch: 1 branch
BranchTrueFalseTotal
ref $callback eq 'CODE' ? : 0 0 0
17 0 ▶ my $handle = sub{
Subroutine __ANON__: not called CC=13 SCAR=52.0
18 0 my $json = shift;
19 0 my $friends_state = shift;
20 0 ▶ return undef unless defined $json;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $json 0 0 0
21 0 ▶ return undef if $json->{retcode}!=0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"retcode"} != 0 0 0 0
22 0 my %categories ;
23 my %info;
24 0 my %marknames;
25 0 my %vipinfo;
26 0 my %state;
27 0 ▶ if(defined $friends_state and ref $friends_state eq "ARRAY"){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $friends_state and ref $friends_state eq "ARRAY") 0 0 0
Condition0%0/3
defined $friends_state and ref $friends_state eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $friends_state and ref $friends_state eq "ARRAY"
defined $friends_state ref $friends_state eq "ARRAY"
Truth table0%0/3
A and B
A= defined $friends_stateB= ref $friends_state eq "ARRAY"
ABresult
0X0
100
111
28 0 for(@{$friends_state}){
29 0 $state{$_->{uin}}{state} = $_->{state};
30 0 $state{$_->{uin}}{client_type} = $_->{client_type};
31 }
32 }
33 0 for(@{ $json->{result}{categories}}){
34 0 $categories{ $_->{'index'} } = {'sort'=>$_->{'sort'},name=>$_->{name} };
35 }
36 0 ▶ $categories{0} = {sort=>0,name=>'我的好友'} if not defined $categories{0};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $categories{0} 0 0 0
37 0 for(@{ $json->{result}{info}}){
38 0 $info{$_->{uin}} = {face=>$_->{face},flag=>$_->{flag},nick=>$_->{nick}};
39 }
40 0 for(@{ $json->{result}{marknames} }){
41 0 $marknames{$_->{uin}} = {markname=>$_->{markname},type=>$_->{type}};
42 }
43 0 for(@{ $json->{result}{vipinfo} }){
44 0 $vipinfo{$_->{u}} = {vip_level=>$_->{vip_level},is_vip=>$_->{is_vip}};
45 }
46 0 for(@{$json->{result}{friends}}){
47 0 my $uin = $_->{uin};
48 0 ▶ if(exists $state{$_->{uin}}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $state{$_->{'uin'}}) { } 0 0 0
49 0 $_->{state} = $state{$uin}{state};
50 0 $_->{client_type} = $state{$uin}{client_type};
51 }
52 else{
53 0 $_->{state} = 'offline';
54 0 $_->{client_type} = 'unknown';
55 }
56 0 $_->{category} = $self->xmlescape_parse($categories{$_->{categories}}{name});
57 0 $_->{name} = $self->xmlescape_parse($info{$uin}{nick});
58 0 $_->{face} = $info{$uin}{face};
59 0 $_->{markname} = $self->xmlescape_parse($marknames{$uin}{markname});
60 0 $_->{is_vip} = $vipinfo{$uin}{is_vip};
61 0 $_->{vip_level} = $vipinfo{$uin}{vip_level};
62 0 delete $_->{categories};
63 0 $_->{id} = delete $_->{uin};
64 }
65 0 return $json->{result}{friends};
66 0 };
67 0 ▶ if($is_blocking){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_blocking) { } 0 0 0
68 0 my $json = $self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)},);
69 0 my $friends_state = $self->_get_friends_state();
70 0 return $handle->($json,$friends_state);
71 }
72 else{
73 $self->steps(
74 0 ▶ sub{
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 0 my $delay = shift;
76 0 $self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)},$delay->begin(0,1));
77 0 $self->_get_friends_state($delay->begin(0,1));
78 },
79 0 ▶ sub{
Subroutine __ANON__: not called CC=2 SCAR=17.9
80 0 my($delay,$json,$friends_state) = @_;
81 0 ▶ $callback->( $handle->($json,$friends_state) ) if ref $callback eq "CODE";
Branch: 1 branch
BranchTrueFalseTotal
if ref $callback eq "CODE" 0 0 0
82 },
83 0 );
84 }
85 }
86 1 1;
« Webqq/Client/Remote/_relink.pm ↑ Summary Webqq/Discuss.pm »