Hi, I'm building an application which uses UTF8 everywhere. Unfortunately DBD::mysql doesn't mark UTF8 strings that are loaded from the database as Unicode scalars in perl. I found in a patch for DBD::mysql but I don't want to introduce such ugly dependency.
Luckyly I'm using Rose::DB::Object to abstract the access to database and I think it will be the best if I insert octets=>Unicode conversion in my R:D:O classes. After reading the extensive documentation of R:D:O classes I added trigger on the columns that store chars/varchars/texts like that: # the column 'name' is varchar __PACKAGE__->meta->column('name')->add_trigger( inflate => sub { my $self = shift; my $value = shift; if (!Encode::is_utf8($value)) { $value = Encode::decode_utf8($value); }; return $value; }); This approach works just fine but the main disadvantage is that I have to put such code for each column and for each class I have or ever create. An alternative approach is to define new layer of classes on top of for e.g. R:D:O::Metadata::Column::Varchar/Char/Text where to perform the UTF decoding and then to change the type-to-class mapping in R:D:O::Metadata. All my derived classes will use the new meta data object and they will have Unicode support. However I couldn't implement the 2nd approach because of lack of knowledge how MethodMaker works and how can I redefine automatically created method with my custom one. So, my questions are: 1. Am I doing the Right Thing by adding trigger to a column to perform UTF8 conversion/inflation 2. Could someone show an example code how to extend R:D:O::Metadata::Column::Varchar column type so it can inflate the values loaded from DB. 3. Do think of some other approach to convert octets coming from database into Unicode scalars Thank you in advance ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_idv37&alloc_id865&op=click _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object