DBIx::Class::InflateColumn::Currency - Auto-create Data::Currency objects from columns.
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');
This module inflates/deflates designated columns into Data::Currency objects.
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' } );
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.
currency_code
__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' } );
Gets/Sets the format to be used when displaying the currency as a string.
__PACKAGE__->currency_format('FMT_COMMON');
__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.
Gets/sets the currency class that the columns should be inflated into. The default class is Data::Currency.
__PACKAGE__->currency_class('MyCurrencySubclass');
__PACKAGE__->add_columns( price => { data_type => 'decimal', size => [9,2], is_nullable => 0, default_value => '0.00', is_currency => 1, currency_class => 'SomeOtherCurrencyClass' } );
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.
Data::Currency, Locale::Currency, Locale::Currency::Format, Finance::Currency::Convert::WebserviceX
Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/
To install DBIx::Class::InflateColumn::Currency, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Class::InflateColumn::Currency
CPAN shell
perl -MCPAN -e shell install DBIx::Class::InflateColumn::Currency
For more information on module installation, please visit the detailed CPAN module installation guide.