File Coverage

blib/lib/WWW/SuperMan.pm
Criterion Covered Total %
statement 9 31 29.0
branch 0 6 0.0
condition n/a
subroutine 3 7 42.8
pod 0 3 0.0
total 12 47 25.5


line stmt bran cond sub pod time code
1             package WWW::SuperMan;
2 1     1   20509 use Slurp;
  1         350  
  1         68  
3 1     1   1238 use JSON;
  1         21751  
  1         10  
4 1     1   4511 use LWP::UserAgent;
  1         82267  
  1         284  
5              
6             our $VERSION = 0.01;
7              
8             sub new {
9 0     0 0   my($class, %cnf) = @_;
10             my $self = bless {
11             user => $cnf{ user },
12             pass => $cnf{ pass },
13 0           ua => LWP::UserAgent->new,
14             }, $class;
15              
16 0           return $self;
17             }
18             sub getUserInfo {
19 0     0 0   my ( $self ) = @_;
20 0           my $url = 'http://api2.sz789.net:88/GetUserInfo.ashx';
21              
22             my $res = $self->{ ua }->post( $url, {
23             username => $self->{user},
24             password => $self->{ pass }
25             }
26 0           );
27              
28 0 0         return {} unless $res->is_success;
29 0           return _deJson( $res );
30             }
31              
32             sub getCode {
33 0     0 0   my ( $self, $img_file ) = @_;
34 0           my $url = 'http://api2.sz789.net:88/RecvByte.ashx';
35              
36 0           my $file = slurp( $img_file );
37 0           my $b = unpack("H*" , $file );
38              
39             my $post = {
40             username => $self->{ user },
41             password => $self->{ pass },
42 0           imgdata => $b,
43             softId => '16635',
44             };
45              
46 0           my $res = $self->{ua}->post( $url, $post );
47 0 0         return {} unless $res->is_success;
48              
49 0           return _deJson( $res );
50             }
51              
52              
53             sub _deJson {
54 0     0     my $res = shift;
55 0           my $json = $res->content;
56 0           eval {
57 0           $json = from_json( $json );
58             };
59              
60 0 0         return {} if $@;
61 0           return $json;
62             }
63              
64             1;
65              
66             __END__