Skip to content

Commit

Permalink
First non-dev release
Browse files Browse the repository at this point in the history
- Fixed and added tests for stat command
- Fixed and added tests for compat wrappers
- Removed auto-generated files from git tracking
- Added repository in Makefile.PL
  • Loading branch information
mnunberg committed Feb 27, 2012
1 parent c25036b commit b509a06
Show file tree
Hide file tree
Showing 12 changed files with 249 additions and 141 deletions.
7 changes: 0 additions & 7 deletions Changes

This file was deleted.

66 changes: 0 additions & 66 deletions MANIFEST

This file was deleted.

3 changes: 3 additions & 0 deletions MANIFEST.SKIP
Expand Up @@ -6,3 +6,6 @@
.+_const\.pm .+_const\.pm
^author_utils ^author_utils
^INSTALL_DIR ^INSTALL_DIR
.+\.in
.+\.kpf
README\.dist
1 change: 1 addition & 0 deletions MANIFEST.in
Expand Up @@ -55,6 +55,7 @@ constants/print_constants.pl


t/00-load.t t/00-load.t
t/01-main.t t/01-main.t
t/02-compat.t
t/tmp/CouchbaseMock.jar t/tmp/CouchbaseMock.jar


src/Makefile.PL src/Makefile.PL
Expand Down
5 changes: 5 additions & 0 deletions Makefile.PL
Expand Up @@ -119,6 +119,11 @@ use Log::Fu;


$MM_Options{NEEDS_LINKING} = 1; $MM_Options{NEEDS_LINKING} = 1;


$MM_Options{META_MERGE} = {
resources => {
repository => 'https://github.com/mnunberg/perl-Couchbase-Client'
}
};


WriteMakefile( WriteMakefile(
NAME => 'Couchbase::Client', NAME => 'Couchbase::Client',
Expand Down
15 changes: 15 additions & 0 deletions README.dist
@@ -0,0 +1,15 @@
#!/bin/sh

# This file says how to make a proper distribution. It also contains shell
# scripts to accomplish that end.
# we need author_utils here.

# first, we update the manifest

perl ./author_utils/gen_manifest.pl

# then, we need to make our changes visible

git log > Changes

# perhaps more steps will be added here in the future
2 changes: 1 addition & 1 deletion lib/Couchbase/Client.pm
Expand Up @@ -2,7 +2,7 @@ package Couchbase::Client;


BEGIN { BEGIN {
require XSLoader; require XSLoader;
our $VERSION = '0.17_0'; our $VERSION = '0.18';
XSLoader::load(__PACKAGE__, $VERSION); XSLoader::load(__PACKAGE__, $VERSION);
} }


Expand Down
2 changes: 1 addition & 1 deletion lib/Couchbase/Client/Async.pm
@@ -1,7 +1,7 @@
package Couchbase::Client::Async; package Couchbase::Client::Async;
use strict; use strict;
use warnings; use warnings;
our $VERSION = '0.17_0'; our $VERSION = '0.17';
use Couchbase::Client; use Couchbase::Client;
use Couchbase::Client::IDXConst; use Couchbase::Client::IDXConst;
use Log::Fu; use Log::Fu;
Expand Down
146 changes: 89 additions & 57 deletions lib/Couchbase/Client/Compat.pm
Expand Up @@ -3,64 +3,97 @@ use strict;
use warnings; use warnings;
use base qw(Couchbase::Client); use base qw(Couchbase::Client);
use Couchbase::Client::Errors; use Couchbase::Client::Errors;

use base qw(Exporter);
sub new {
my ($cls,$options) = @_; our @EXPORT_OK = qw(return_for_multi_wrap return_for_op);
my $o = $cls->SUPER::new($options);
} #These errors are 'negative replies', all others are 'error' replies.

our %ErrorMap = (
sub get { COUCHBASE_NOT_STORED, 0,
my $self = shift; COUCHBASE_KEY_EEXISTS, 0,
$self->SUPER::get(@_)->value(@_); COUCHBASE_KEY_ENOENT, 0,
COUCHBASE_DELTA_BADVAL, 0,
COUCHBASE_E2BIG, 0,
);

sub return_for_multi_wrap {
my ($requests,$response,$op) = @_;

if(wantarray) {
#ugh, really?
my @retvals;
foreach my $req (@$requests) {
my $key = ref $req eq 'ARRAY' ? $req->[0] : $req;
my $retval = return_for_op($response->{$key}, $op);
push @retvals, $retval;
}
return @retvals;
} else {
#scalar:
while (my ($k,$v) = each %$response) {
$response->{$k} = return_for_op($v, $op);
}
return $response;
}
} }


sub gets { sub return_for_op {
my $self = shift; my ($retval, $op) = @_;
my $ret = $self->SUPER::get(@_);
if($ret->is_ok) { my $errval = $retval->errnum;
return [ $ret->cas, $ret->value ];
} else { if ($errval) {
$errval = $ErrorMap{$errval};
}

if ($retval->errnum && (!defined $errval)) {
# Fatal error:
return undef; return undef;
} }

if ($op =~ /^(?:get|incr|decr)$/) {
return $retval->value;
}

if ($op eq 'gets') {
return [$retval->cas, $retval->value];
}

if ($op =~ /^(?:set|cas|add|append|prepend|replace|remove|delete)/) {
return int($retval->errnum == 0);
}

} }



sub new {
foreach my $sub qw(set add replace append prepend cas) { my ($cls,$options) = @_;
no strict 'refs'; my $o = $cls->SUPER::new($options);
*{$sub} = sub {
my $self = shift;
my $ret = $self->${\"SUPER::$sub"}(@_);
if($ret->is_ok) {
return 1;
} elsif ($ret->errnum == COUCHBASE_NOT_STORED ||
$ret->errnum == COUCHBASE_KEY_EEXISTS ||
$ret->errnum == COUCHBASE_KEY_ENOENT) {
return 0;
} else {
return undef;
}
};
} }


foreach my $sub (qw(incr decr delete remove)) {
foreach my $sub (qw(
get gets
set append prepend replace add
remove delete
incr decr cas)) {
no strict 'refs'; no strict 'refs';
*{$sub} = sub { *{$sub} = sub {
my $self = shift; my $self = shift;
my $ret = $self->${\"SUPER::$sub"}(@_); my $ret = $self->{\"SUPER::$sub"}(@_);
if($ret->is_ok) { $ret = return_for_op($ret, $sub);
return $ret->value; return $ret;
} elsif ($ret->errnum == COUCHBASE_NOT_STORED || };
$ret->errnum == COUCHBASE_KEY_ENOENT ||
$ret->errnum == COUCHBASE_KEY_EEXISTS || my $multi = "$sub\_multi";
$ret->errnum == COUCHBASE_DELTA_BADVAL || *{$multi} = sub {
$ret->errnum == COUCHBASE_E2BIG) { my $self = shift;
return 0; my $ret = $self->{\"SUPER::$multi"}(@_);
} else { return return_for_multi_wrap(\@_, $ret, $sub)
return undef;
}
}; };
} }


1;

__END__ __END__
=head1 NAME =head1 NAME
Expand All @@ -77,32 +110,31 @@ of those pages for documentation of the methods supported.
=over =over
=item get =item get, get_multi
=item gets
=item set =item gets, gets_multi
=item cas =item set, set_multi
=item add =item cas, cas_multi
=item replace =item add, add_multi
=item append =item replace, replace_multi
=item prepend =item append, append_multi
=item incr =item prepend, prepend_multi
=item decr =item incr, incr_multi
=item delete =item decr, decr_multi
=item remove =item delete, remove, delete_multi, remove_multi
=back =back
=head2 SEE ALSO =head2 SEE ALSO
L<Cache::Memcached> L<Cache::Memcached>
Expand Down
15 changes: 15 additions & 0 deletions lib/Couchbase/Test/ClientSync.pm
Expand Up @@ -259,4 +259,19 @@ sub T06_multi :Test(no_plan) {
"all keys have been decremented"); "all keys have been decremented");
} }


sub T07_stats :Test(no_plan) {
my $self = shift;
my $o = $self->cbo;
my $stats = $o->stats();

ok($stats && ref $stats eq 'HASH', "Got a hashref");
ok(scalar keys %$stats, "stats not empty");

if($self->mock && $self->mock->nodes) {
ok(scalar keys %$stats == $self->mock->nodes, "Got expected stat count");
} else {
diag "Cannot determine expected stat count for real cluster";
}
}

1; 1;

0 comments on commit b509a06

Please sign in to comment.