Jess Robinson > Locale-Object-0.78 > Locale::Object::Currency::Converter

Download:
Locale-Object-0.78.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  10
Open  4
View/Report Bugs
Module Version: 0.78   Source   Latest Release: Locale-Object-0.79

NAME ^

Locale::Object::Currency::Converter - convert between currencies

DESCRIPTION ^

Locale::Object::Currency::Converter allows you to convert between values of currencies represented by Locale::Object::Currency objects.

SYNOPSIS ^

    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;

PREREQUISITES ^

This module requires Finance::Currency::Convert::XE and Finance::Currency::Convert::Yahoo.

METHODS ^

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.

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_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.

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.

AUTHOR ^

Earle Martin <hex@cpan.org>

http://downlode.org/Code/Perl/

CREDITS ^

See the credits for Locale::Object.

LEGAL ^

Copyright 2003-2007 Earle Martin. All rights reserved.

This module is released under the same license as Perl itself, and is provided on an "as is" basis. No warranty of any kind is made, 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.

syntax highlighting: