File Coverage

blib/lib/Mojo/Webqq/Model/Remote/_get_user_friends_ext.pm
Criterion Covered Total %
statement 3 26 11.5
branch 0 12 0.0
condition 0 3 0.0
subroutine 1 4 25.0
pod n/a
total 4 45 8.8


line stmt bran cond sub pod time code
1 1     1   8 use strict;
  1         3  
  1         365  
2             sub Mojo::Webqq::Model::_get_user_friends_ext {
3 0     0     my $self = shift;
4 0           my $callback = shift;
5 0           my $api = 'http://qun.qq.com/cgi-bin/qun_mgr/get_friend_list';
6 0 0         my $is_blocking = ref $callback eq "CODE"?0:1;
7             my $handle = sub{
8 0     0     my $json = shift;
9 0 0         return if not defined $json;
10 0 0         return if $json->{ec}!=0;
11             #{"ec":0,"result":{"0":{"mems":[{"name":"卖茶叶和眼镜per","uin":744891290}]},"1":{"gname":"朋友"},"2":{"gname":"家人"},"3":{"gname":"同学"}}}
12 0           my @result;
13 0           for my $category_index (keys %{$json->{result}}){
  0            
14 0 0 0       my $category = ($category_index==0 and !defined $json->{result}{$category_index}{gname})?"我的好友":($json->{result}{$category_index}{gname});
15 0 0         next if ref $json->{result}{$category_index}{mems} ne "ARRAY";
16 0           for my $f (@{ $json->{result}{$category_index}{mems} }){
  0            
17             my $friend = {
18             category => $self->xmlescape_parse($category),
19             displayname => $self->xmlescape_parse($f->{name}),
20             uid => $f->{uin},
21 0           } ;
22 0           push @result,$friend;
23             }
24             }
25 0           return \@result;
26 0           };
27 0 0         if($is_blocking){
28 0           return $handle->($self->http_post($api,{Referer=>"http://qun.qq.com/member.html",json=>1},form=>{bkn=>$self->get_csrf_token},) );
29             }
30             else{
31             $self->http_post($api,{Referer=>"http://qun.qq.com/member.html",json=>1},form=>{bkn=>$self->get_csrf_token},sub{
32 0     0     my $json = shift;
33 0           $callback->( $handle->($json) );
34 0           });
35             }
36             }
37             1;