NAME

Interchange6::Currency - Currency objects for Interchange 6

VERSION

0.101

DESCRIPTION

Currency objects for Interchange6 Open Source eCommerce with Unicode CLDR localization and rate conversion.

Extends CLDR::Number::Format::Currency with accurate calculation functions using Math::BigFloat.

Many useful standard operators are overloaded and return currency objects if appropriate.

Although this class was written to satisfy the specific requirements of Interchange6 it is suitable for use as a standalone module. See "SEE ALSO" for other currency modules.

ATTRIBUTES

value

Value as simple decimal, e.g.: 3.45

All values are coerced into Math::BigFloat.

converter_class

Defaults to Finance::Currency::Convert::WebserviceX.

The class name which handles conversion to a new currency_code.

The converter class can be any class that supports the following method signature:

 sub convert {
     my ($self, $price, $from, $to) = @_;

     return $converted_price;
 };

In addition this module supports the following converters:

converter

Vivified "converter_class".

METHODS

BUILD

Sets precision for automatic rounding of "value" to "maximum_fraction_digits" in CLDR::Number::Format::Currency.

clone %new_attrs?

Returns clone of the currency object possibly with new attribute values (if any are supplied).

convert $new_corrency_code

Convert to new currency using "converter".

NOTE: If /convert is called in void context then the currency object is mutated in place. If called in list or scalar context then the original object is not modified and a new Interchange6::Currency object is returned instead.

as_string

Stringified formatted currency, e.g.: $3.45

stringify

Alias for "as_string".

add $arg

Add $arg to "value" in place.

subtract $arg

Subtract $arg from "value" in place.

multiply $arg

Multiply "value" by $arg in place.

divide $arg

Divide "value" by $arg in place.

modulo $arg

Return "value" % $arg as currency object.

cmp_value $arg

Equivalent to "value" <=> $arg.

cmp $arg

String comparison.

Not always useful in itself since string comparison of stringified currency objects might not produce what you expect depending on locale and currency code.

SEE ALSO

Other modules which perform currency maths:

Other Interchange6 eCommerce modules:

AUTHORS

Peter Mottram (SysPete), peter@sysnix.com

ACKNOWLEDGEMENTS

Shutterstock, Inc for the excellent CLDR::Number and all of the authors of Math::BigFLoat and Moo.

LICENSE AND COPYRIGHT

Copyright 2015-2016 Peter Mottram (SysPete).

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

Unicode is a registered trademark of Unicode, Inc., in the United States and other countries.