switch to hashref based for command args and results
[dbsrgits/DBIx-Data-Store-old.git] / lib / DBIx / Data / Store / CRUD.pm
CommitLineData
65b76960 1package DBIx::Data::Store::CRUD;
2
3use Moose;
4use Method::Signatures::Simple;
5
6has raw_store => (is => 'ro', required => 1); # DBIx::Data::Store object
7
8foreach my $type (qw(select insert update delete)) {
9 has "${type}_sql" => (is => 'ro', predicate => "has_${type}_sql");
3347c67e 10 has "${type}_argument_order" => (is => 'ro', default => sub { [] });
65b76960 11}
12
3347c67e 13has "select_column_order" => (is => 'ro');
14
65b76960 15method new_select_command ($args) {
16 die "$self->has_select_sql" unless $self->has_select_sql;
3347c67e 17 $self->raw_store->new_stream_command(
18 $self->select_sql,
19 $self->_unwrap_args_for(select => $args),
20 $self->select_column_order
21 );
22}
23
24method _unwrap_args_for ($type, $args) {
25 [ @{$args}{@{$self->${\"${type}_argument_order"}}} ]
26}
27
28method _new_call_command ($type, $args) {
29 my $has_meth = "has_${type}_sql";
30 die "${self}->${has_meth}" unless $self->$has_meth;
31 $self->raw_store->new_call_command(
32 $self->${\"${type}_sql"},
33 $self->_unwrap_args_for($type => $args)
34 );
65b76960 35}
36
37method new_insert_command ($args) {
3347c67e 38 $self->_new_call_command(insert => $args);
65b76960 39}
40
41method new_update_command ($args) {
3347c67e 42 $self->_new_call_command(update => $args);
65b76960 43}
44
45method new_delete_command ($args) {
3347c67e 46 $self->_new_call_command(delete => $args);
65b76960 47}
48
49__PACKAGE__->meta->make_immutable;
50
511;