Fix OO-style subscription
Also fix warning from autocleanup when you've already closed a
Blerg::Database.
OUTPUT:
RETVAL
-void subscription_list(const char *author, const char *str_offset, int direction)
+void _subscription_list(const char *author, const char *str_offset, int direction)
INIT:
HV *tmp;
struct blergref *list;
sub close {
my ($obj) = @_;
- $obj->_ensure_pointer;
+ if (!(defined $obj && defined $obj->{ptr})) {
+ # Welp, nothing to do here!
+ return;
+ }
Blerg::Database::_close($obj->{ptr});
delete $obj->{ptr};
}
sub subscription_list {
my ($obj) = @_;
- return Blerg::Database::subscription_list($obj->{name});
+ $obj->_ensure_pointer;
+ return Blerg::Database::_subscription_list($obj->{name}, 0, 1);
}
sub mute {
use strict;
use warnings;
-use Test::More tests => 30;
+use Test::More tests => 34;
BEGIN { use_ok('Blerg::Database') };
#########################
$ptrb = Blerg::Database::_open("b");
ok( Blerg::Database::subscription_add("a", "b") == 1 );
Blerg::Database::_store($ptrb, "Hello, A!");
-@list = Blerg::Database::subscription_list("a", 0, 1);
+@list = Blerg::Database::_subscription_list("a", 0, 1);
ok( @list == 1 );
ok( $list[0]->{author} eq 'b' );
ok( $list[0]->{record} == 0 );
ok( $blerg->store($data) == $n + 1 );
$n++;
ok( $blerg->fetch($n) eq $data );
+$blerg->close;
+
+# Subscription OO-style
+$ptra = Blerg::Database->open_existing('a');
+$ptrb = Blerg::Database->open_existing('b');
+@list = $ptra->subscription_list;
+ok( @list == 1 );
+ok( $list[0]->{author} eq 'b' );
+ok( $list[0]->{record} == 0 );
+ok( $ptrb->fetch($list[0]->{record}) eq 'Hello, A!' );
+$ptrb->close;
+$ptra->close;
END {
chdir;