NAME
DBIx::Quick::Converter - Role to convert fields after database recover and before inserts and updates.
SYNOPSIS
package MyApp::DB::Converters::DateTime;
use strict;
use warnings;
use Moo;
use DateTime::Format::Pg;
sub to_db {
shift;
my $dt = shift;
return undef if !$dt;
return DateTime::Format::Pg->new->format_datetime($dt);
}
sub from_db {
shift;
my $date = shift;
return undef if !$date;
return DateTime::Format::Pg->new->parse_datetime($date);
}
with 'DBIx::Quick::Converter';
DESCRIPTION
This is Moo role that must be implemented by objects sent to the converter attribute of the field declaration in DBIx::Quick.
METHODS NEEDED TO BE IMPLEMENTED
to_db
The subroutine that transforms data into the format which you want to store in the database.
Takes one argument.
from_db
The subroutine that transforms the database data into your wanted format in perl, for example a DateTime object.
Takes one argument.