From: Matt S Trout Date: Fri, 20 Apr 2012 09:18:45 +0000 (+0000) Subject: make renderer and converter classes more pluggable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dfaa96848a33006cabf31ea32ccaf6be2aee202c;p=dbsrgits%2FSQL-Abstract.git make renderer and converter classes more pluggable --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index b941f3c..4b9eaa1 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -93,13 +93,23 @@ has convert => (is => 'ro'); has array_datatypes => (is => 'ro'); has converter_class => ( - is => 'ro', default => sub { 'SQL::Abstract::Converter' } + is => 'rw', lazy => 1, builder => '_build_converter_class', + trigger => sub { shift->clear_converter }, ); +sub _build_converter_class { + use_module('SQL::Abstract::Converter') +} + has renderer_class => ( - is => 'ro', default => sub { 'Data::Query::Renderer::SQL::Naive' } + is => 'rw', lazy => 1, builder => '_build_renderer_class', + trigger => sub { shift->clear_renderer }, ); +sub _build_renderer_class { + use_module('Data::Query::Renderer::SQL::Naive') +} + sub _converter_args { my ($self) = @_; Scalar::Util::weaken($self); @@ -128,7 +138,7 @@ sub _converter_args { sub _build_converter { my ($self) = @_; - use_module($self->converter_class)->new($self->_converter_args); + $self->converter_class->new($self->_converter_args); } sub _renderer_args { @@ -147,7 +157,7 @@ sub _renderer_args { sub _build_renderer { my ($self) = @_; - use_module($self->renderer_class)->new($self->_renderer_args); + $self->renderer_class->new($self->_renderer_args); } sub _render_dq {