From: Matt S Trout Date: Tue, 20 Aug 2019 00:45:33 +0000 (+0000) Subject: create sql part joining control code X-Git-Tag: v1.90_01~144 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b84764fb689d878da0e77c303b33816ca745d9c4;p=dbsrgits%2FSQL-Abstract.git create sql part joining control code --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 97e1816..9bb6b9c 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -2,6 +2,7 @@ package SQL::Abstract; # see doc at end of file use strict; use warnings; +use Module::Runtime (); use Carp (); use List::Util (); use Scalar::Util (); @@ -239,6 +240,13 @@ sub new { ',' => '_render_op_multop', }; + if ($opt{lazy_join_sql_parts}) { + my $mod = Module::Runtime::use_module('SQL::Abstract::Parts'); + $opt{join_sql_parts} ||= sub { $mod->new(@_) }; + } + + $opt{join_sql_parts} ||= sub { join $_[0], @_[1..$#_] }; + return bless \%opt, $class; } @@ -1198,7 +1206,7 @@ sub join_query_parts { : ((ref($_) eq 'ARRAY') ? $_ : [ $_ ]) ), @parts; return [ - join($join, map $_->[0], @final), + $self->{join_sql_parts}->($join, map $_->[0], @final), (map @{$_}[1..$#$_], @final), ]; } @@ -1315,7 +1323,9 @@ sub _order_by_chunks { return () unless defined(my $expanded = $self->_expand_order_by($arg)); - return $self->_chunkify_order_by($expanded); + my @res = $self->_chunkify_order_by($expanded); + (ref() ? $_->[0] : $_) .= '' for @res; + return @res; } sub _chunkify_order_by { diff --git a/lib/SQL/Abstract/Parts.pm b/lib/SQL/Abstract/Parts.pm new file mode 100644 index 0000000..95f7069 --- /dev/null +++ b/lib/SQL/Abstract/Parts.pm @@ -0,0 +1,19 @@ +package SQL::Abstract::Parts; + +use strict; +use warnings; + +use overload '""' => 'stringify', fallback => 1; + +sub new { + my ($proto, @args) = @_; + bless(\@args, ref($proto) || $proto); +} + +sub stringify { + my ($self) = @_; + my ($join, @parts) = @$self; + return join $join, @parts; +} + +1;