File Coverage

blib/lib/Webqq/Client/Method/change_state.pm
Criterion Covered Total %
statement 6 23 26.0
branch 0 8 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 35 25.7


line stmt bran cond sub pod time code
1 1     1   4 use JSON;
  1         2  
  1         4  
2 1     1   154 use Webqq::Client::Util qw(console);
  1         2  
  1         266  
3             sub Webqq::Client::change_state{
4 0     0 1   my $self = shift;
5 0 0         return undef if $self->{type} ne 'smartqq';
6 0           my $state = shift;
7 0           my $api_url = 'http://d.web2.qq.com/channel/change_status2';
8 0           my $ua = $self->{ua};
9 0           my @headers = (
10             Referer=>'http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2'
11             );
12 0           my @query_string = (
13             newstatus => $state,
14             clientid => $self->{qq_param}{clientid},
15             psessionid => $self->{qq_param}{psessionid},
16             t => time,
17             );
18              
19 0           my @query_string_pairs;
20 0           push @query_string_pairs , shift(@query_string) . "=" . shift(@query_string) while(@query_string);
21 0           my $response = $ua->get($api_url.'?'.join("&",@query_string_pairs),@headers);
22 0 0         if($response->is_success){
  0            
23 0 0         print $response->content(),"\n" if $self->{debug};
24 0           my $json = JSON->new->utf8->decode( $response->content() );
25 0 0         return undef if $json->{retcode} !=0;
26 0           console "登录状态已修改为:$state\n";
27 0           return $state;
28             }
29             else{return undef}
30             }
31             1;