if (my ($obj) = $self->_key_cache_get_raw($raw)) {
$self->_merge($obj, $raw)
} else {
- $self->_inflate($raw)
+ $self->_add_to_key_cache($self->_inflate($raw))
}
};
push @cache, $obj;
}
- \@cache;
+ \@cache
}
method _add_to_member_cache ($to_add) {
return unless $self->_member_cache_built;
push @{$self->_member_cache}, $to_add;
+ $to_add
}
## key cache - by primary/unique key
method _add_to_key_cache ($to_add) {
$self->_key_cache->{$self->_object_to_id($to_add)} = $to_add;
- return
+ $to_add
}
method _key_cache_has_raw ($raw) {
method _add_to_store ($new) {
my $new_raw = $self->_deflate($new);
$self->_merge($new, $self->_store->new_insert_command($new_raw)->execute);
- $self->_add_to_caches($new);
- return
+ $new;
}
method _add_to_caches ($new) {
$self->_add_to_member_cache($new);
$self->_add_to_key_cache($new);
+ $new
}
1;
use DBIx::Data::Store::Command::Call;
use DBIx::Data::Store::Command::Row;
use DBIx::Data::Store::Command::Stream;
+use DBIx::Data::Store::Command::Closure;
has 'connection' => (is => 'ro', lazy_build => 1); # , isa => 'DBIx::Connector'
);
}
+method new_closure_command ($code) {
+ return DBIx::Data::Store::Command::Closure->new(
+ run => $code, against => $self->connection
+ );
+}
+
__PACKAGE__->meta->make_immutable;
1;
--- /dev/null
+package DBIx::Data::Store::Command::Closure;
+
+use Moose;
+use Method::Signatures::Simple;
+
+has [ 'run', 'against' ] => (is => 'ro', required => 1);
+
+method execute {
+ $self->against->run($self->run);
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
has 'insert_call_command' => (is => 'ro', required => 1);
+has '_last_insert_id_command' => (is => 'ro', lazy_build => 1);
+
has 'raw_store' => (is => 'ro', required => 1);
+method _build__last_insert_id_command {
+ $self->raw_store->new_closure_command(sub {
+ +{ $self->id_column => shift->last_insert_id((undef) x 4) }
+ });
+}
+
method execute {
$self->insert_call_command->execute;
- return { $self->id_column => $self->_get_last_insert_id }
+ return $self->_last_insert_id_command->execute;
};
-method _get_last_insert_id {
- # this should probably involve some sort of call to the raw
- # store to get the command object from it, but meh
- $self->raw_store->connection->run(sub {
- shift->last_insert_id((undef) x 4)
- });
-}
-
__PACKAGE__->meta->make_immutable;
1;
use DBIx::Data::Store::CRUD;
use DBIx::Data::Collection::Set;
use DBI;
+use Scalar::Util qw(refaddr);
+
+use Devel::Dwarn;
use strict;
use warnings FATAL => 'all';
my $doug = $set->add({ name => 'Doug' });
-use Devel::Dwarn;
+ok($doug->{id}, 'id filled out in new row');
+
+my ($set_doug) = grep $_->{name} eq 'Doug', $set->flatten;
+
+ok($set_doug, 'new row exists in flatten');
-Dwarn $doug;
+cmp_ok(refaddr($doug), '==', refaddr($set_doug), 'Same hashref returned');
done_testing;