Locale::Object::Currency::Converter - convert between currencies
Locale::Object::Currency::Converter allows you to convert between values of currencies represented by Locale::Object::Currency objects.
Locale::Object::Currency::Converter
use Locale::Object::Currency; use Locale::Object::Currency::Converter; my $usd = Locale::Object::Currency->new( code => 'USD' ); my $gbp = Locale::Object::Currency->new( code => 'GBP' ); my $eur = Locale::Object::Currency->new( code => 'EUR' ); my $jpy = Locale::Object::Currency->new( code => 'JPY' ); my $converter = Locale::Object::Currency::Converter->new( from => $usd, to => $gbp, service => 'XE' ); my $result = $converter->convert(5); my $rate = $converter->rate; my $timestamp = $converter->timestamp; print $converter->use_xe; print $converter->use_yahoo; $converter->from($eur); $converter->to($jpy); $converter->service('Yahoo'); $converter->refresh;
This module requires Finance::Currency::Convert::XE and Finance::Currency::Convert::Yahoo.
new()
my $converter = Locale::Object::Currency::Converter->new();
Creates a new converter object. With no arguments, creates a blank object. Possible arguments are from, to and service, all or none of which may be given. from and to must be Locale::Object::Currency objects. service must be one of either 'XE' or 'Yahoo', to specify the conversion should be done by http://xe.com/ucc/ or http://finance.yahoo.com/ respectively.
from
to
service
use_xe()
print $converter->use_xe;
Returns 1 or 0 depending on whether a use Finance::Currency::Convert::XE; was successful. If 1, you can do conversions using the XE.com service.
use Finance::Currency::Convert::XE;
use_yahoo()
print $converter->use_yahoo;
Returns 1 or 0 depending on whether a use Finance::Currency::Convert::Yahoo; was successful. If 1, you can do conversions using the finance.yahoo.com service.
use Finance::Currency::Convert::Yahoo;
from()
$converter->from($eur);
Sets a currency to do conversions from. Takes a Locale::Object::Currency object.
to()
$converter->to($jpy);
Sets a currency to do conversions to. Takes a Locale::Object::Currency object.
service()
$converter->service('Yahoo');
Sets which currency conversion service to use. Depends on two other modules; see use_xe() and use_yahoo() above.
convert()
my $result = $converter->convert(5);
Does the currency conversion. Takes a numeric argument representng the amount of the 'from' currency to convert into the 'to' currency, gives the result. Will croak if you didn't select a conversion service, 'from' and 'to' currency when you did new() or afterwards with the associated methods (see above).
rate()
my $rate = $converter->rate;
Returns the conversion rate between your 'from' currency and your 'to' currency, as of the time you last did a conversion. If you haven't done any conversions yet, will do one first (the result for converting 1 unit of a currency into another currency is the rate) and give you that.
timestamp()
my $timestamp = $converter->timestamp;
Returns the time timestamp of the last time the currency exchange rate was stored, either the last time you did a convert() or a refresh().
refresh()
$converter->refresh;
Will update the stored conversion rate and timestamp by doing another conversion. Doesn't return anything.
Originally by Earle Martin
Originally by Earle Martin. To the extent possible under law, the author has dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty. You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
To install Locale::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Object
CPAN shell
perl -MCPAN -e shell install Locale::Object
For more information on module installation, please visit the detailed CPAN module installation guide.