From: Matt S Trout Date: Thu, 21 Jul 2005 16:20:57 +0000 (+0000) Subject: Refactored Ima::DBI support to allow pluggable __FOO__ handlers X-Git-Tag: v0.03001~134 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef29a097f034c0e4043011e7dda097a791d39c7d;p=dbsrgits%2FDBIx-Class.git Refactored Ima::DBI support to allow pluggable __FOO__ handlers --- diff --git a/lib/DBIx/Class/CDBICompat/ImaDBI.pm b/lib/DBIx/Class/CDBICompat/ImaDBI.pm index 36f66b0..f702f14 100644 --- a/lib/DBIx/Class/CDBICompat/ImaDBI.pm +++ b/lib/DBIx/Class/CDBICompat/ImaDBI.pm @@ -4,6 +4,13 @@ use strict; use warnings; use NEXT; +use base qw/Class::Data::Inheritable/; + +__PACKAGE__->mk_classdata('_transform_sql_handlers' => + { + 'TABLE' => sub { return $_[0]->_table_name }, + 'ESSENTIAL' => sub { join(' ', $_[0]->columns('Essential')) }, + } ); sub db_Main { return $_[0]->_get_dbh; @@ -44,8 +51,10 @@ sub set_sql { sub transform_sql { my ($class, $sql, @args) = @_; my $table = $class->_table_name; - $sql =~ s/__TABLE__/$table/g; - $sql =~ s/__ESSENTIAL__/join(' ', $class->columns('Essential'))/eg; + foreach my $key (keys %{ $class->_transform_sql_handlers }) { + my $h = $class->_transform_sql_handlers->{$key}; + $sql =~ s/__$key(?:\(([^\)]+)\))?__/$h->($class, $1)/eg; + } return sprintf($sql, @args); }