From: Matt S Trout Date: Sat, 14 Apr 2012 15:05:00 +0000 (+0000) Subject: factor some stuff out and enable writeable quoting attributes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=29a3e5dc9d7bfc9881a29291e2db29f22c8a8084;p=dbsrgits%2FSQL-Abstract.git factor some stuff out and enable writeable quoting attributes --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index ff11248..e45071b 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -106,11 +106,17 @@ has injection_guard => ( } ); -has renderer => (is => 'lazy'); +has renderer => (is => 'lazy', clearer => 'clear_renderer'); -has name_sep => (is => 'ro', default => sub { '.' }); +has name_sep => ( + is => 'rw', default => sub { '.' }, + trigger => sub { shift->clear_renderer }, +); -has quote_char => (is => 'ro'); +has quote_char => ( + is => 'rw', + trigger => sub { shift->clear_renderer }, +); has always_quote => (is => 'ro', default => sub { 1 }); @@ -333,24 +339,38 @@ sub select { shift->_render_sqla(select => @_) } sub _select_to_dq { my ($self, $table, $fields, $where, $order) = @_; + + my $final_dq = $self->_select_body_to_dq($table, $fields, $where); + + if ($order) { + $final_dq = $self->_order_by_to_dq($order, undef, $final_dq); + } + + return $final_dq; +} + +sub _select_body_to_dq { + my ($self, $table, $fields, $where) = @_; + $fields ||= '*'; my $source_dq = $self->_source_to_dq($table, $where); - my $final_dq = { + return +{ type => DQ_SELECT, select => [ - map $self->_ident_to_dq($_), + map $self->_select_field_to_dq($_), ref($fields) eq 'ARRAY' ? @$fields : $fields ], from => $source_dq, }; +} - if ($order) { - $final_dq = $self->_order_by_to_dq($order, undef, $final_dq); - } - - return $final_dq; +sub _select_field_to_dq { + my ($self, $field) = @_; + ref($field) + ? $self->_literal_to_dq($$field) + : $self->_ident_to_dq($field) } #======================================================================