Permalink
Browse files

First non-dev release

- 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 b509a068fc46858c1b80735f7844bb42088a4315
Showing with 249 additions and 141 deletions.
  1. +0 −7 Changes
  2. +0 −66 MANIFEST
  3. +3 −0 MANIFEST.SKIP
  4. +1 −0 MANIFEST.in
  5. +5 −0 Makefile.PL
  6. +15 −0 README.dist
  7. +1 −1 lib/Couchbase/Client.pm
  8. +1 −1 lib/Couchbase/Client/Async.pm
  9. +89 −57 lib/Couchbase/Client/Compat.pm
  10. +15 −0 lib/Couchbase/Test/ClientSync.pm
  11. +112 −0 t/02-compat.t
  12. +7 −9 xs/callbacks.c
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -6,3 +6,6 @@
.+_const\.pm
^author_utils
^INSTALL_DIR
.+\.in
.+\.kpf
README\.dist
View
@@ -55,6 +55,7 @@ constants/print_constants.pl
t/00-load.t
t/01-main.t
t/02-compat.t
t/tmp/CouchbaseMock.jar
src/Makefile.PL
View
@@ -119,6 +119,11 @@ use Log::Fu;
$MM_Options{NEEDS_LINKING} = 1;
$MM_Options{META_MERGE} = {
resources => {
repository => 'https://github.com/mnunberg/perl-Couchbase-Client'
}
};
WriteMakefile(
NAME => 'Couchbase::Client',
View
@@ -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
View
@@ -2,7 +2,7 @@ package Couchbase::Client;
BEGIN {
require XSLoader;
our $VERSION = '0.17_0';
our $VERSION = '0.18';
XSLoader::load(__PACKAGE__, $VERSION);
}
@@ -1,7 +1,7 @@
package Couchbase::Client::Async;
use strict;
use warnings;
our $VERSION = '0.17_0';
our $VERSION = '0.17';
use Couchbase::Client;
use Couchbase::Client::IDXConst;
use Log::Fu;
@@ -3,64 +3,97 @@ use strict;
use warnings;
use base qw(Couchbase::Client);
use Couchbase::Client::Errors;
sub new {
my ($cls,$options) = @_;
my $o = $cls->SUPER::new($options);
}
sub get {
my $self = shift;
$self->SUPER::get(@_)->value(@_);
use base qw(Exporter);
our @EXPORT_OK = qw(return_for_multi_wrap return_for_op);
#These errors are 'negative replies', all others are 'error' replies.
our %ErrorMap = (
COUCHBASE_NOT_STORED, 0,
COUCHBASE_KEY_EEXISTS, 0,
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 {
my $self = shift;
my $ret = $self->SUPER::get(@_);
if($ret->is_ok) {
return [ $ret->cas, $ret->value ];
} else {
sub return_for_op {
my ($retval, $op) = @_;
my $errval = $retval->errnum;
if ($errval) {
$errval = $ErrorMap{$errval};
}
if ($retval->errnum && (!defined $errval)) {
# Fatal error:
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);
}
}
foreach my $sub qw(set add replace append prepend cas) {
no strict 'refs';
*{$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;
}
};
sub new {
my ($cls,$options) = @_;
my $o = $cls->SUPER::new($options);
}
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';
*{$sub} = sub {
my $self = shift;
my $ret = $self->${\"SUPER::$sub"}(@_);
if($ret->is_ok) {
return $ret->value;
} elsif ($ret->errnum == COUCHBASE_NOT_STORED ||
$ret->errnum == COUCHBASE_KEY_ENOENT ||
$ret->errnum == COUCHBASE_KEY_EEXISTS ||
$ret->errnum == COUCHBASE_DELTA_BADVAL ||
$ret->errnum == COUCHBASE_E2BIG) {
return 0;
} else {
return undef;
}
my $ret = $self->{\"SUPER::$sub"}(@_);
$ret = return_for_op($ret, $sub);
return $ret;
};
my $multi = "$sub\_multi";
*{$multi} = sub {
my $self = shift;
my $ret = $self->{\"SUPER::$multi"}(@_);
return return_for_multi_wrap(\@_, $ret, $sub)
};
}
1;
__END__
=head1 NAME
@@ -77,32 +110,31 @@ of those pages for documentation of the methods supported.
=over
=item get
=item gets
=item get, get_multi
=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
=head2 SEE ALSO
L<Cache::Memcached>
@@ -259,4 +259,19 @@ sub T06_multi :Test(no_plan) {
"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;
Oops, something went wrong.

0 comments on commit b509a06

Please sign in to comment.