5ba2e89cc0bf50835c3435cad0ddfa4eb1616f84
[dbsrgits/DBIx-Data-Store-old.git] / lib / DBIx / Data / Store / CRUD.pm
1 package DBIx::Data::Store::CRUD;
2
3 use Moose;
4 use Method::Signatures::Simple;
5
6 has raw_store => (is => 'ro', required => 1); # DBIx::Data::Store object
7
8 foreach my $type (qw(select insert update delete)) {
9   has "${type}_sql" => (is => 'ro', predicate => "has_${type}_sql");
10   has "${type}_argument_order" => (is => 'ro', default => sub { [] });
11 }
12
13 has "select_column_order" => (is => 'ro');
14
15 method new_select_command ($args) {
16   die "$self->has_select_sql" unless $self->has_select_sql;
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
24 method _unwrap_args_for ($type, $args) {
25   [ @{$args}{@{$self->${\"${type}_argument_order"}}} ]
26 }
27
28 method _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   );
35 }
36
37 method new_insert_command ($args) {
38   $self->_new_call_command(insert => $args);
39 }
40
41 method new_update_command ($args) {
42   $self->_new_call_command(update => $args);
43 }
44
45 method new_delete_command ($args) {
46   $self->_new_call_command(delete => $args);
47 }
48
49 __PACKAGE__->meta->make_immutable;
50
51 1;