From: Matt S Trout Date: Tue, 1 Oct 2019 04:12:18 +0000 (+0000) Subject: clean up EC code and add pod X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1c52c0c610ec999b831c3a105d27c5b6f839a56;p=scpubgit%2FQ-Branch.git clean up EC code and add pod --- diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm index b5b81bc..358cdf1 100644 --- a/lib/SQL/Abstract/ExtraClauses.pm +++ b/lib/SQL/Abstract/ExtraClauses.pm @@ -38,6 +38,7 @@ sub apply_to { sub register_extensions { my ($self, $sqla) = @_; + my @clauses = $sqla->clauses_of('select'); my @before_setop; CLAUSE: foreach my $idx (0..$#clauses) { @@ -47,27 +48,9 @@ sub register_extensions { last CLAUSE; } } + die "Huh?" unless @before_setop; $sqla->clauses_of(select => @clauses); - $self->register( - clause_expanders => [ - 'select.group_by' - => sub { $_[0]->expand_maybe_list_expr($_[2], -ident) }, - 'select.having' - => sub { $_[0]->expand_expr($_[2]) }, - ], - (map +( - "${_}er" => [ - do { - my $x = $_; - (map +($_ => "_${x}_${_}"), qw(join from_list alias)) - } - ] - ), qw(expand render)), - binop_expander => [ as => '_expand_op_as' ], - renderer => [ as => '_render_as' ], - expander => [ cast => '_expand_cast' ], - ); $sqla->clauses_of(update => sub { my ($self, @clauses) = @_; @@ -82,8 +65,26 @@ sub register_extensions { }); $self->register( + (map +( + "${_}er" => [ + do { + my $x = $_; + (map +($_ => "_${x}_${_}"), qw(join from_list alias)) + } + ] + ), qw(expand render)), + binop_expander => [ as => '_expand_op_as' ], + renderer => [ as => '_render_as' ], + expander => [ cast => '_expand_cast' ], clause_expanders => [ + "select.from", '_expand_from_list', + 'select.group_by' + => sub { $_[0]->expand_maybe_list_expr($_[2], -ident) }, + 'select.having' + => sub { $_[0]->expand_expr($_[2]) }, 'update.from' => '_expand_from_list', + "update.target", '_expand_update_clause_target', + "update.update", '_expand_update_clause_target', 'delete.using' => '_expand_from_list', 'insert.rowvalues' => sub { +(from => $_[0]->expand_expr({ -values => $_[2] })); @@ -127,14 +128,6 @@ sub register_extensions { ); } - $self->register( - clause_expanders => [ - "select.from", '_expand_from_list', - "update.target", '_expand_update_clause_target', - "update.update", '_expand_update_clause_target', - ] - ); - return $sqla; } @@ -377,10 +370,18 @@ SQL::Abstract::ExtraClauses - new/experimental additions to L Applies the plugin to an L object. +=head2 register_extensions + +Registers the extensions described below + =head2 cb For plugin authors, creates a callback to call a method on the plugin. +=head2 register + +For plugin authors, registers callbacks more easily. + =head2 sqla Available only during plugin callback executions, contains the currently