File Coverage

blib/lib/Webqq/Client/Method/_recv_message.pm
Criterion Covered Total %
statement 3 30 10.0
branch 0 16 0.0
condition n/a
subroutine 1 3 33.3
pod n/a
total 4 49 8.1


line stmt bran cond sub pod time code
1 1     1   4 use JSON;
  1         1  
  1         4  
2             sub Webqq::Client::_recv_message{
3 0     0     my $self = shift;
4 0 0         return if $self->{is_stop};
5 0           my $ua = $self->{asyn_ua};
6 0 0         my $api_url = ($self->{qq_param}{is_https}?'https':'http') . '://d.web2.qq.com/channel/poll2';
7             my $callback = sub {
8 0     0     my $response = shift;
9 0 0         print $response->content() if $self->{debug};
10             #分析接收到的消息,并把分析后的消息放到接收消息队列中
11 0 0         $self->parse_receive_msg($response->content()) if $response->is_success;
12             #重新开始接收消息
13 0           my $rand_watcher_id = rand();
14             $self->{watchers}{$rand_watcher_id} = AE::timer 2,0,sub{
15 0           delete $self->{watchers}{$rand_watcher_id};
16 0           $self->_recv_message();
17 0           };
18 0           };
19              
20 0           my %r = (
21             clientid => $self->{qq_param}{clientid},
22             psessionid => $self->{qq_param}{psessionid},
23             key => "",
24             );
25 0 0         if($self->{type} eq 'webqq'){
26 0           $r{key} = 0;
27 0           $r{ids} = [];
28             }
29 0           my $post_content = [
30             r => JSON->new->utf8->encode(\%r),
31             ];
32 0 0         if($self->{type} eq 'webqq'){
33 0           push @$post_content,(
34             clientid => $self->{qq_param}{clientid},
35             psessionid => $self->{qq_param}{psessionid}
36             );
37             }
38 0 0         if($self->{debug}){
39 0           require URI;
40 0           my $uri = URI->new('http:');
41 0           $uri->query_form($post_content);
42 0           print $api_url,"\n";
43 0           print $uri->query(),"\n";
44             }
45              
46 0 0         my @headers = $self->{type} eq 'webqq'? (Referer=>"http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=3")
47             : (Referer=>"http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2")
48             ;
49 0           $ua->post(
50             $api_url,
51             $post_content,
52             @headers,
53             $callback
54             );
55            
56             }
57             1;