[Dbix-class] Specifying parser for DBIx::Class::InflateColumn::DateTime explicitly?

Alex Povolotsky tarkhil at over.ru
Tue Jul 20 06:25:04 GMT 2010


On 07/20/10 02:19, Peter Rabbitson wrote:
> On Mon, Jul 19, 2010 at 05:08:50PM +0400, Alex Povolotsky wrote:
>    
>> Hello!
>>
>> How do I explicitly specify parser for
>> DBIx::Class::InflateColumn::DateTime explicitly?
>>
>> I'd like to parse incoming dates with DateTime::Format::ISO8601
>>
>>      
> What do you mean by this? You have an existing database with
> ISO8601 in a varchar column? Or something completely different?
> Please describe your scenario so you can be pointed to the most
> fitting solution.
>    

I'm receiving some XML data from external source, with DD.MM.YYYY 
formatting.

Here is the code

     my $data = $c->req->param('data');
     my $model: Stashed;
     my $parser = XML::Simple->new();
     eval {
       if ($data gt '') {
         my $ref = $parser->XMLin($data);
         $model->txn_do(sub {
                          my $recs = wrap_array($ref->{RECORD});
                          foreach my $rec (@$recs) {
                            my $table = lc($rec->{table});
                            my $rsname = "\u$table";
                            my $field = $rec->{FIELD};
                            my $cooked = { map { lc($_) => 
$field->{$_}->{value}} keys %$field };
                            
$model->resultset($rsname)->update_or_create($cooked);
                          }
                        });
         $xg->status(200);
         $xg->add('dbsn', undef, $model->resultset('Dbsn')->id_max());
       } else {
         $xg->error(400, 'Нет данных');
       }
     };

DD.MM.YYYY gets parsed, by default, as YY.MM.DD, which is quite wrong. I 
need to use more controllable parser...

Alex.




More information about the DBIx-Class mailing list