From: Peter Rabbitson Date: Fri, 17 Jan 2014 06:12:26 +0000 (+0100) Subject: Support for undef and/or foreign attributes (e.g. CDBI::Sweet) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=333eae181a23079dec6a7bf7b4244d6e6c4f749d;p=dbsrgits%2FSQL-Abstract.git Support for undef and/or foreign attributes (e.g. CDBI::Sweet) Extra CDBI insanity (didn't work too well... once I hit _bindargs) --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index cffe6d8..3694f4c 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -26,6 +26,28 @@ sub puke (@) { Carp::croak "[$func] Fatal: ", @_; } +# original SQLA treated anything false as "use the default" +# in addition a lot of CPAN seems to supply undef's for "use the default" +# (say hi to Class::DBI::Sweet) +sub BUILDARGS { + my $class = shift; + my $args = { ref $_[0] eq 'HASH' ? %{$_[0]} : @_ }; + + defined $args->{$_} or delete $args->{$_} + for keys %$args; + + $args; +} + +# many subclasses on CPAN assume they can dump a bunch of extra new() +# parameters, and then get back at them via $obj->{foo}. YAY +# (Class::DBI::Sweet says hi back) +sub BUILD { + my ($self, $args) = @_; + %{$self} = (%$args, %$self); + $self; +} + has converter => (is => 'lazy', clearer => 'clear_converter'); has case => ( @@ -132,7 +154,9 @@ sub _build_renderer_roles { () } sub _converter_args { my ($self) = @_; Scalar::Util::weaken($self); + +{ + sqla_instance => $self, lower_case => $self->case, default_logic => $self->logic, bind_meta => not($self->bindtype eq 'normal'), @@ -152,6 +176,8 @@ sub _converter_args { renderer_will_quote => ( defined($self->quote_char) and $self->always_quote ), + + legacy_convert_handler => ($self->can('_convert') != \&_convert) ? 1 : 0, } } diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index c56c702..4798e8d 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -15,6 +15,13 @@ has lower_case => ( is => 'ro' ); +has legacy_convert_handler => ( + is => 'ro' +); +has sqla_instance => ( + is => 'ro', weak => 1 +); + has default_logic => ( is => 'ro', coerce => sub { uc($_[0]) }, default => sub { 'OR' } ); @@ -115,6 +122,12 @@ sub _ident_to_dq { sub _maybe_convert_dq { my ($self, $dq) = @_; + + # do in void ctx - nothing seems to be using any of this + if ($self->legacy_convert_handler and $dq->{type} eq 'Identifier') { + $self->sqla_instance->_convert( join '.', @{$dq->{elements}} ) + } + if (my $c = $self->{where_convert}) { Operator({ 'SQL.Naive' => 'apply' }, [ Identifier($self->_sqlcase($c)),