Skip to content

Commit

Permalink
use mop
Browse files Browse the repository at this point in the history
  • Loading branch information
dams committed Jul 18, 2013
1 parent d7dde56 commit 97d6498
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/Bloomd/Client.pm
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,8 @@
package Bloomd::Client;


# ABSTRACT: Perl client to the bloomd server # ABSTRACT: Perl client to the bloomd server


use feature ':5.12'; use feature ':5.12';
use Moo; use mop;
use Method::Signatures;
use List::MoreUtils qw(any mesh); use List::MoreUtils qw(any mesh);
use Carp; use Carp;
use Socket qw(:crlf); use Socket qw(:crlf);
Expand All @@ -19,32 +17,48 @@ The protocol. ro, defaults to 'tcp'
=cut =cut


has protocol => ( is => 'ro', default => sub {'tcp'} ); class Bloomd::Client {

has $protocol is ro = 'tcp';


=attr host =attr host
The host to connect to. ro, defaults to '127.0.0.1' The host to connect to. ro, defaults to '127.0.0.1'
=cut =cut


has host => ( is => 'ro', default => sub {'127.0.0.1'} ); has $host is ro = '127.0.0.1';


=attr port =attr port
The port to connect to. ro, defaults to '8673' The port to connect to. ro, defaults to '8673'
=cut =cut


has port => ( is => 'ro', default => sub {8673} ); has $port is ro = 8673;
has _socket => ( is => 'lazy', predicate => 1, clearer => 1 ); has $_socket;

method _socket {
$_socket //= $self->_build__socket();
}

method _has_socket {
# XXX not a real predicate
defined $_socket
}

method _clear_socket {
# XXX not a real clearer
undef $_socket;
}


=attr timeout =attr timeout
The timeout (on read and write), in seconds. Can be a float. ro, defaults to 10. The timeout (on read and write), in seconds. Can be a float. ro, defaults to 10.
=cut =cut


has timeout => ( is => 'ro', , default => sub { 10 } ); has $timeout is ro = 10;


=head1 SYNOPSIS =head1 SYNOPSIS
Expand Down Expand Up @@ -77,12 +91,12 @@ method _build__socket {


my $seconds = int( $self->timeout ); my $seconds = int( $self->timeout );
my $useconds = int( 1_000_000 * ( $self->timeout - $seconds ) ); my $useconds = int( 1_000_000 * ( $self->timeout - $seconds ) );
my $timeout = pack( 'l!l!', $seconds, $useconds ); my $_timeout = pack( 'l!l!', $seconds, $useconds );


$socket->setsockopt( SOL_SOCKET, SO_RCVTIMEO, $timeout ) $socket->setsockopt( SOL_SOCKET, SO_RCVTIMEO, $_timeout )
or croak "setsockopt(SO_RCVTIMEO): $!"; or croak "setsockopt(SO_RCVTIMEO): $!";


$socket->setsockopt( SOL_SOCKET, SO_SNDTIMEO, $timeout ) $socket->setsockopt( SOL_SOCKET, SO_SNDTIMEO, $_timeout )
or croak "setsockopt(SO_SNDTIMEO): $!"; or croak "setsockopt(SO_SNDTIMEO): $!";


return $socket; return $socket;
Expand Down Expand Up @@ -115,7 +129,7 @@ Returns true if the filter didn't exist and was created successfully.
=cut =cut


method create ($name, $capacity?, $prob?, $in_memory?) { method create ($name, $capacity, $prob, $in_memory) {
my $args = my $args =
( $capacity ? "capacity=$capacity" : '' ) ( $capacity ? "capacity=$capacity" : '' )
. ( $prob ? " prob=$prob" : '' ) . ( $prob ? " prob=$prob" : '' )
Expand All @@ -132,7 +146,8 @@ on them.
=cut =cut


method list ($prefix? = '') { method list ($prefix) {
$prefix //= '';
my @keys = qw(name prob size capacity items); my @keys = qw(name prob size capacity items);
[ [
map { map {
Expand Down Expand Up @@ -302,4 +317,5 @@ method _check_line($line) {
return $line; return $line;
} }


}
1; 1;

0 comments on commit 97d6498

Please sign in to comment.