DBIx::Class::InflateColumn::Time - Inflate and Deflate "time" columns into DateTime::Duration Objects
package HorseTrack::Database::Schema::Result::Race; use base 'DBIx::Class::Core'; use strict; use warnings; __PACKAGE__->load_components("InflateColumn::Time"); __PACKAGE__->add_columns( race_number => { data_type => 'integer'}, duration => { data_type => 'time'}, );
This module can be used to automagically inflate database columns of data type "time" into DateTime::Duration objects. It is used similiar to other InflateColumn DBIx modules.
Once your Result is properly defined you can now pass DateTime::Duration objects into columns of data_type time and retrieve DateTime::Duration objects from these columns as well
Inflation occurs whenever the data is being taken FROM the database. In this case the database is storing the value with data_type of time, upon inflation a DateTime::Duration object is returned from the resultset.
package HorseTrack::Race; use strict; use warnings; use Moose; use namespace::autoclean; use DateTime::Duration; has 'race_number' => ( is => 'rw', isa => 'Int' ); has 'duration' => ( is => 'rw', isa => 'DateTime::Duration' ); sub retrieve { my $self = shift; my $result = $schema->resultset('...')->search({ race_number => 1 })->single; my $race = $self->new({ race_number => $result->race_number, duration => $result->duration, }); return $race; } __PACKAGE__->meta->make_immutable(); 1;
Deflation occurs whenever the data is being taken TO the database. In this case an object of type DateTime::Duration is being stored into the a database columns with a data_type of "time". Using the same object from the Inflation example:
$schema->resultset('...')->create({ race_number => $self->race_number, duration => $self->duration, });
Strictly speaking, you don't actually call any of these methods yourself. DBIx handles the magic provided you have included the InflateColumn::Time component in your Result.
Therefore, there are no public methods to be consumed.
Robert Stone <drzigman AT cpan DOT org >
<drzigman AT cpan DOT org >
Copyright 2013 Robert Stone
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU Lesser General Public License as published by the Free Software Foundation; or any compatible license.
See http://dev.perl.org/licenses/ for more information.
To install DBIx::Class::InflateColumn::Time, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::InflateColumn::Time
CPAN shell
perl -MCPAN -e shell install DBIx::Class::InflateColumn::Time
For more information on module installation, please visit the detailed CPAN module installation guide.