The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Class::InflateColumn::Time - Inflate and Deflate "time" columns into DateTime::Duration Objects

SYNOPSIS

    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'},
    );

DESCRIPTION

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

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

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,
    });

METHODS

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.

AUTHORS

Robert Stone <drzigman AT cpan DOT org >

COPYRIGHT & LICENSE

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.