Robert Stone > DBIx-Class-InflateColumn-Math-Currency-0.0.1 > DBIx::Class::InflateColumn::Math::Currency



Annotate this POD


View/Report Bugs
Module Version: 0.0.1   Source   Latest Release: DBIx-Class-InflateColumn-Math-Currency-0.2.0


DBIx::Class::InflateColumn::Math::Currency - Inflate and Deflate "decimal" columns into Math::Currency Objects


    package HorseTrack::Database::Schema::Result::Bet;
    use base 'DBIx::Class::Core';

    use strict;
    use warnings;


      id         => { data_type => 'integer' },
      gambler_id => { data_type => 'integer' },
      amount     => { data_type => 'decimal', size => [9,2] },


This module can be used to automagically inflate database columns of data type "decimal" into Math::Currency objects. It is used similiar to other InflateColumn DBIx modules.

Once your Result is properly defined you can now pass Math::Currency objects (and regular integers and floats for that matter, they need not be Math::Currency objects) into columns of data_type decimal and retrieve Math::Currency objects from these columns as well.

In the event anything other than a Math::Currency object, an integer, or a float, is provided this module will croak, stating as such.


Inflation occurs whenever the data is being taken FROM the database. In this case the database is storing the value with data_type of decimal, upon inflation a Math::Currency object is returned from the resultset.

    package HorseTrack::Bet;

    use strict;
    use warnings;

    use Moose;
    use namespace::autoclean;

    use Math::Currency;

    has 'id'       => ( is => 'rw', isa => 'Int' );
    has 'gamber_id => ( is => 'rw', isa => 'Int' );
    has 'amount'   => ( is => 'rw', isa => 'Math::Currency' );

    sub retrieve {
        my $self = shift;
        my $result = $schema->resultset('...')->search({ id => 1 })->single;

        my $bet = $self->new({
            id        => $result->id,
            gamber_id => $result->gamber_id,
            amount    => $result->amount,

        return $bet;



Deflation occurs whenever the data is being taken TO the database. In this case an object of type Math::Currency is being stored into the a database columns with a data_type of "decimal". Using the same object from the Inflation example:

        id        => $self->id,
        gamber_id => $self->gambler_id,
        amount    => $self->amount,


Strictly speaking, you don't actually call any of these methods yourself. DBIx handles the magic provided you have included the InflateColumn::Math::Currency component in your Result.

Therefore, there are no public methods to be consumed.


Robert Stone <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 for more information.

syntax highlighting: