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.
Earle Martin <EMARTIN@cpan.org>
See the credits for Locale::Object.
Copyright 2003-2004 Fotango Ltd. All rights reserved. http://opensource.fotango.com/
This module is released under the same license as Perl itself, and is provided on an "as is" basis. The author and Fotango Ltd make no warranties of any kind, either expressed or implied, as to the accuracy and/or utility of any results obtained from its use. However, if you do find something wrong with the results, please let the author know. Thanks.
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.