Commit | Line | Data |
65b76960 |
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"); |
3347c67e |
10 | has "${type}_argument_order" => (is => 'ro', default => sub { [] }); |
65b76960 |
11 | } |
12 | |
3347c67e |
13 | has "select_column_order" => (is => 'ro'); |
14 | |
65b76960 |
15 | method 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 | |
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 | ); |
65b76960 |
35 | } |
36 | |
37 | method new_insert_command ($args) { |
3347c67e |
38 | $self->_new_call_command(insert => $args); |
65b76960 |
39 | } |
40 | |
41 | method new_update_command ($args) { |
3347c67e |
42 | $self->_new_call_command(update => $args); |
65b76960 |
43 | } |
44 | |
45 | method new_delete_command ($args) { |
3347c67e |
46 | $self->_new_call_command(delete => $args); |
65b76960 |
47 | } |
48 | |
49 | __PACKAGE__->meta->make_immutable; |
50 | |
51 | 1; |