File Coverage

blib/lib/Riak/Light/Driver.pm
Criterion Covered Total %
statement 29 29 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 9 9 100.0
pod 0 3 0.0
total 44 47 93.6


line stmt bran cond sub pod time code
1             #
2             # This file is part of Riak-Light
3             #
4             # This software is copyright (c) 2013 by Weborama.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             ## no critic (RequireUseStrict, RequireUseWarnings)
10             package Riak::Light::Driver;
11             {
12             $Riak::Light::Driver::VERSION = '0.10';
13             }
14             ## use critic
15              
16 14     14   52950 use English qw( -no_match_vars );
  14         103607  
  14         91  
17 14     14   17455 use Riak::Light::Connector;
  14         72  
  14         529  
18 14     14   141 use Moo;
  14         35  
  14         87  
19 14     14   6305 use Types::Standard -types;
  14         91  
  14         178  
20              
21             # ABSTRACT: Riak Driver, deal with the binary protocol
22              
23             has connector => ( is => 'ro', required => 1 );
24              
25             sub BUILDARGS {
26 19     19 0 23246 my ( undef, %args ) = @_;
27              
28 19 100       144 if ( exists $args{socket} ) {
29 16         615 my $connector = Riak::Light::Connector->new( socket => $args{socket} );
30              
31 16         11143 $args{connector} = $connector;
32             }
33              
34 19         583 +{%args};
35             }
36              
37             sub perform_request {
38 21     21 0 631 my ( $self, %request ) = @_;
39              
40 21         57 my $request_body = $request{body};
41 21         40 my $request_code = $request{code};
42              
43 21         175 my $message = pack( 'c a*', $request_code, $request_body );
44              
45 21         511 $self->connector->perform_request($message);
46             }
47              
48             sub read_response {
49 16     16 0 366 my ($self) = @_;
50 16 100       412 my $response = $self->connector->read_response()
51             or return $self->_parse_error();
52 8         150 $self->_parse_response($response);
53             }
54              
55             sub _parse_response {
56 8     8   64 my ( $self, $response ) = @_;
57 8         96 my ( $code, $body ) = unpack( 'c a*', $response );
58              
59 8         232 { code => $code, body => $body, error => undef };
60             }
61              
62             sub _parse_error {
63 8   100 8   526 { code => -1, body => undef, error => $ERRNO || "Socket Closed" };
64             }
65              
66             1;
67              
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Riak::Light::Driver - Riak Driver, deal with the binary protocol
76              
77             =head1 VERSION
78              
79             version 0.10
80              
81             =head1 DESCRIPTION
82              
83             Internal class
84              
85             =head1 AUTHORS
86              
87             =over 4
88              
89             =item *
90              
91             Tiago Peczenyj
92              
93             =item *
94              
95             Damien Krotkine
96              
97             =back
98              
99             =head1 COPYRIGHT AND LICENSE
100              
101             This software is copyright (c) 2013 by Weborama.
102              
103             This is free software; you can redistribute it and/or modify it under
104             the same terms as the Perl 5 programming language system itself.
105              
106             =cut
107              
108              
109             __END__