File Coverage

blib/lib/Mojo/Webqq/Model/Remote/_get_user_info.pm
Criterion Covered Total %
statement 3 29 10.3
branch 0 8 0.0
condition n/a
subroutine 1 4 25.0
pod n/a
total 4 41 9.7


line stmt bran cond sub pod time code
1 1     1   7 use strict;
  1         2  
  1         330  
2             sub Mojo::Webqq::Model::_get_user_info{
3 0     0     my $self = shift;
4 0           my $callback = shift;
5 0           my $api_url ='https://s.web2.qq.com/api/get_self_info2';
6 0           my $headers = {
7             Referer => 'https://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1',
8             json => 1,
9             ua_request_timeout => $self->model_update_timeout,
10             ua_retry_times => 3,
11             };
12 0           my @query_string = (
13             t => time,
14             );
15 0 0         my $is_blocking = ref $callback eq "CODE"?0:1;
16             my $handle = sub{
17 0     0     my $json = shift;
18 0 0         return undef unless defined $json;
19 0 0         return undef if $json->{retcode} !=0;
20 0           my $user = $json->{result};
21 0           $user->{state} = $self->mode;
22 0           $user->{name} = delete $user->{nick};
23 0           $user->{client_type} = 'web';
24 0           $user->{birthday} = join( "-", @{ $user->{birthday} }{qw(year month day)} );
  0            
25 0           $user->{signature} = delete $user->{lnick};
26 0           $user->{sex} = delete $user->{gender};
27             #my $single_long_nick = $self->get_single_long_nick( $self->uid );
28             #$json->{result}{signature} = $single_long_nick if defined $single_long_nick;
29 0           $user->{uid} = $self->uid;
30 0           $user->{id} = delete $user->{uin};
31 0           return $user;
32 0           };
33 0 0         if($is_blocking){
34 0           return $handle->( $self->http_get($self->gen_url($api_url,@query_string),$headers,) );
35             }
36             else{
37             $self->http_get($self->gen_url($api_url,@query_string),$headers,sub{
38 0     0     my $json = shift;
39 0           $callback->( $handle->($json) );
40 0           });
41             }
42             }
43             1;