clauses transforms
Matt S Trout [Mon, 15 Apr 2019 02:03:18 +0000 (02:03 +0000)]
lib/SQL/Abstract/Clauses.pm
lib/SQL/Abstract/ExtraClauses.pm

index 877117d..3683f45 100644 (file)
@@ -302,6 +302,9 @@ sub clauses_of {
   unless (@clauses) {
     return @{$self->{clauses_of}{$of}||[]};
   }
+  if (ref($clauses[0]) eq 'CODE') {
+    @clauses = $self->${\($clauses[0])}(@{$self->{clauses_of}{$of}||[]});
+  }
   $self->{clauses_of}{$of} = \@clauses;
   return $self;
 }
index c46a632..00e4d2a 100644 (file)
@@ -28,8 +28,18 @@ sub register_defaults {
   $self->expander(as => '_expand_op_as');
   $self->renderer(as => '_render_as');
 
-  splice(@{$self->{clauses_of}{update}}, 2, 0, 'from');
-  splice(@{$self->{clauses_of}{delete}}, 1, 0, 'using');
+  $self->clauses_of(update => sub {
+    my ($self, @clauses) = @_;
+    splice(@clauses, 2, 0, 'from');
+    @clauses;
+  });
+
+  $self->clauses_of(delete => sub {
+    my ($self, @clauses) = @_;
+    splice(@clauses, 1, 0, 'using');
+    @clauses;
+  });
+
   $self->clause_expanders(
     'update.from' => '_expand_select_clause_from',
     'delete.using' => sub {