NAME

DBIx::Class::InflateColumn::Currency - Auto-create Data::Currency objects from columns.

SYNOPSIS

Load this component and then declare one or more columns as currency columns.

package Item;
__PACKAGE__->load_components(qw/InflateColumn::Currency/);
__PACKAGE__->add_columns(
    price => {
        data_type      => 'decimal',
        size           => [9,2],
        is_nullable    => 0,
        default_value  => '0.00',
        is_currency    => 1
    }
);

Then you can treat the specified column as a Data::Currency object.

print 'US Dollars: ', $item->price;
print 'Japanese Yen: ', $item->price->convert('JPY');

DESCRIPTION

This module inflates/deflates designated columns into Data::Currency objects.

METHODS

currency_code

Arguments: $code

Gets/sets the default currency code used when inflating currency columns.

__PACKAGE__->currency_code('USD');

You can also set this on a per column basis:

__PACKAGE__->add_columns(
    price => {
        data_type      => 'decimal',
        size           => [9,2],
        is_nullable    => 0,
        default_value  => '0.00',
        is_currency    => 1,
        currency_code  => 'USD'
    }
);

currency_code_column

Arguments: $name

Gets/sets the name of the column where the current rows currency code is stored.

__PACKAGE__->currency_code_column('my_code_column');

When set, the currency object will inherit its code from the value in this column. If the column is undefined/empty, currency_code will be used instead.

You can also set this on a per column basis:

__PACKAGE__->add_columns(
    price => {
        data_type             => 'decimal',
        size                  => [9,2],
        is_nullable           => 0,
        default_value         => '0.00',
        is_currency           => 1,
        currency_code_column  => 'some_other_column'
    }
);

currency_format

Arguments: $format

Gets/Sets the format to be used when displaying the currency as a string.

__PACKAGE__->currency_format('FMT_COMMON');

You can also set this on a per column basis:

__PACKAGE__->add_columns(
    price => {
        data_type       => 'decimal',
        size            => [9,2],
        is_nullable     => 0,
        default_value   => '0.00',
        is_currency     => 1,
        currency_format => 'FMT_STANDARD'
    }
);

See Locale::Currency::Format for the available formatting options.

currency_class

Arguments: $class

Gets/sets the currency class that the columns should be inflated into. The default class is Data::Currency.

__PACKAGE__->currency_class('MyCurrencySubclass');

You can also set this on a per column basis:

__PACKAGE__->add_columns(
    price => {
        data_type      => 'decimal',
        size           => [9,2],
        is_nullable    => 0,
        default_value  => '0.00',
        is_currency    => 1,
        currency_class => 'SomeOtherCurrencyClass'
    }
);

register_column

Chains with the "register_column" in DBIx::Class::Row method, and sets up currency columns appropriately. This would not normally be directly called by end users.

SEE ALSO

Data::Currency, Locale::Currency, Locale::Currency::Format, Finance::Currency::Convert::WebserviceX

AUTHOR

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/