line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FleetDB; |
2
|
1
|
|
|
1
|
|
503
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
55
|
|
5
|
1
|
|
|
1
|
|
2014
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
26786
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
1547
|
use JSON::XS::VersionOneAndTwo; |
|
1
|
|
|
|
|
10770
|
|
|
1
|
|
|
|
|
7
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.33'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
18
|
my ( $class, %args ) = @_; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
50
|
|
|
6
|
my $host = delete $args{host} || '127.0.0.1'; |
13
|
1
|
|
50
|
|
|
4
|
my $port = delete $args{port} || 3400; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
50
|
|
|
13
|
my $socket = IO::Socket::INET->new( |
16
|
|
|
|
|
|
|
PeerHost => $host, |
17
|
|
|
|
|
|
|
PeerPort => $port, |
18
|
|
|
|
|
|
|
Timeout => 60 |
19
|
|
|
|
|
|
|
) || die "Error connecting to $host:$port: $!"; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $self = bless { |
22
|
|
|
|
|
|
|
host => $host, |
23
|
|
|
|
|
|
|
port => $port, |
24
|
|
|
|
|
|
|
socket => $socket, |
25
|
|
|
|
|
|
|
}, $class; |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub query { |
30
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
31
|
0
|
|
|
|
|
|
my $socket = $self->{socket}; |
32
|
0
|
|
|
|
|
|
my $request = to_json( \@args ); |
33
|
0
|
|
|
|
|
|
warn "-> $request\n" if 0; |
34
|
0
|
0
|
|
|
|
|
$socket->print( $request . "\n" ) || die $!; |
35
|
0
|
|
0
|
|
|
|
my $response = $socket->getline || die $!; |
36
|
0
|
|
|
|
|
|
warn "<- $response" if 0; |
37
|
0
|
|
|
|
|
|
my $return = from_json($response); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
if ( $return->[0] != 0 ) { |
40
|
0
|
|
|
|
|
|
croak( $return->[1] ); |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
|
return $return->[1]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |