make sure extraclauses doesn't kill already extant overrides for from
Matt S Trout [Mon, 7 Oct 2019 01:14:38 +0000 (01:14 +0000)]
lib/SQL/Abstract/Plugin/ExtraClauses.pm

index 10d5839..79912bf 100644 (file)
@@ -45,7 +45,6 @@ sub register_extensions {
     renderer => [ as => '_render_as' ],
     expander => [ cast => '_expand_cast' ],
     clause_expanders => [
-      "select.from", '_expand_from_list',
       'select.group_by'
         => sub { $_[0]->expand_expr({ -list => $_[2] }, -ident) },
       'select.having'
@@ -63,6 +62,24 @@ sub register_extensions {
     ],
   );
 
+  $sqla->expander(old_from => $sqla->clause_expander('select.from'));
+  $sqla->wrap_clause_expander('select.from', sub {
+    my ($orig) = @_;
+    sub {
+      my ($sqla, undef, $args) = @_;
+      if (ref($args) eq 'HASH') {
+        return $self->_expand_from_list(undef, $args);
+      }
+      if (
+        ref($args) eq 'ARRAY'
+        and grep { !ref($_) and $_ =~ /^-/ } @$args
+      ) {
+        return $self->_expand_from_list(undef, $args);
+      }
+      return $sqla->$orig(undef, $args);
+    }
+  });
+
   # set ops
   $sqla->wrap_expander(select => sub {
     $self->cb('_expand_select', $_[0], \@before_setop);