convert delete to extended clauses system
Matt S Trout [Tue, 9 Apr 2019 00:36:25 +0000 (00:36 +0000)]
lib/SQL/Abstract/Clauses.pm

index 4da4500..0ae82ac 100644 (file)
@@ -26,13 +26,8 @@ sub register_defaults {
   $self->{clauses_of}{delete} = [ qw(delete_from where returning) ];
   $self->{expand}{delete} = sub { shift->_expand_statement(@_) };
   $self->{render}{delete} = sub { shift->_render_statement(delete => @_) };
-  $self->{expand_clause}{'delete.delete_from'} = sub {
-    $_[0]->_expand_maybe_list_expr($_[1], -ident)
-  };
-  $self->{expand_clause}{'delete.where'} = 'expand_expr';
-  $self->{expand_clause}{'delete.returning'} = sub {
-    shift->_expand_maybe_list_expr(@_, -ident);
-  };
+  $self->{expand_clause}{"delete.$_"} = "_expand_delete_clause_$_"
+    for @{$self->{clauses_of}{delete}};
   $self->{clauses_of}{insert} = [
     'insert_into', 'fields', 'values', 'returning'
   ];
@@ -87,6 +82,16 @@ sub _expand_update_clause_returning {
   +(returning => shift->_expand_maybe_list_expr(@_, -ident));
 }
 
+sub _expand_delete_clause_delete_from {
+  +(delete_from => shift->_expand_maybe_list_expr(@_, -ident));
+}
+
+sub _expand_delete_clause_where { +(where => shift->expand_expr(@_)); }
+
+sub _expand_delete_clause_returning {
+  +(returning => shift->_expand_maybe_list_expr(@_, -ident));
+}
+
 sub _expand_statement {
   my ($self, $type, $args) = @_;
   my $ec = $self->{expand_clause};