File Coverage

blib/lib/Webqq/Client/Method/get_dwz.pm
Criterion Covered Total %
statement 6 22 27.2
branch 0 6 0.0
condition 0 3 0.0
subroutine 2 4 50.0
pod 1 1 100.0
total 9 36 25.0


line stmt bran cond sub pod time code
1 1     1   4 use JSON;
  1         1  
  1         3  
2 1     1   79 use Webqq::Client::Util qw(console);
  1         2  
  1         171  
3             sub Webqq::Client::get_dwz {
4 0     0 1   my $self = shift;
5 0           my $url = shift;
6 0           my $api = 'http://dwz.cn/create.php';
7 0           my $ua = $self->{ua};
8 0           my $res;
9             my $dwz;
10 0           eval{
11 0     0     local $SIG{ALRM} = sub{die "timeout";};
  0            
12 0           alarm 5;
13 0           $res = $ua->post($api,[url=>$url],);
14 0           alarm 0;
15 0 0         if($res->is_success){
16 0           my $json = JSON->new->utf8->decode($res->content);
17 0 0         $dwz = $json->{tinyurl} if $json->{status}==0;
18             };
19             };
20 0 0 0       console "[Webqq::Client::get_dwz] $@\n" if $@ and $self->{debug};
21              
22 0           return $dwz;
23            
24             };
25             1;