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

Alexander Hartmaier alexander.hartmaier at t-systems.at
Tue Jul 20 09:38:27 GMT 2010


The inflatecolumn plugins create objects from strings coming out of the
database and stringify objects you pass you the column accessors back to
strings.

If you set the column to a string (the one from your xml file) the
plugin doesn't touch it.

So what you want is to create DateTime objects from the strings and pass
those to the column accessor.

--
Best regards, Alex


Am Dienstag, den 20.07.2010, 08:25 +0200 schrieb Alex Povolotsky:
> 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.
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list