File Coverage

blib/lib/Finance/USDX.pm
Criterion Covered Total %
statement 24 31 77.4
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 33 42 78.5


line stmt bran cond sub pod time code
1             package Finance::USDX;
2             $Finance::USDX::VERSION = '0.03';
3 1     1   16699 use parent 'Exporter';
  1         255  
  1         5  
4             our @EXPORT = ('usdx');
5              
6 1     1   68 use 5.006;
  1         2  
  1         33  
7 1     1   4 use strict;
  1         5  
  1         29  
8 1     1   3 use warnings;
  1         1  
  1         24  
9              
10 1     1   552 use Finance::Quote;
  1         70038  
  1         210  
11              
12             =encoding UTF-8
13              
14             =head1 NAME
15              
16             Finance::USDX - Compute USDX (US Dollar Index)
17              
18             =head1 SYNOPSIS
19              
20             use Finance::USDX;
21              
22             # get "live" USDX using YAHOO finance values (through Finance::Quote)
23             my $usdx = usdx();
24              
25             # compute USDX given specfic conversion rates
26             my $usdx = usdx(eurusd => 1.2976, usdjpy => 79.846,
27             gbpusd => 1.5947, usdcad => 0.9929,
28             usdsek => 6.6491, usdchf => 0.9331);
29              
30             =head1 DESCRIPTION
31              
32             Just exports an 'usdx' subroutine that returns the current USDX value.
33              
34             =head2 usdx
35              
36             If called without arguments, returns the "current" USDX value using
37             data from YAHOO finance website, using Finance::Quote module.
38              
39             If called with argument, then the hashtable must have six key/value
40             pairs, with rates for currency convertion. Note that two of the keys
41             are not usd->other convertions. All exact keys are required.
42              
43             =cut
44              
45             sub usdx {
46 2     2 1 7 my ($eurusd, $usdjpy, $gbpusd, $usdcad, $usdsek, $usdchf);
47 2         5 my @keys = qw(eurusd usdjpy gbpusd usdcad usdsek usdchf);
48 2 50       5 if (@_) {
49 2         7 my %values = @_;
50 2         5 for my $k (@keys) {
51 12 50       21 die "Call to 'usdx' misses key '$k'" unless exists($values{$k});
52 12         457 eval "\$$k = \$values{\$k};"
53             }
54             } else {
55 0         0 my $q = Finance::Quote->new;
56 0         0 $eurusd = $q->currency('EUR' => 'USD');
57 0         0 $usdjpy = $q->currency('USD' => 'JPY');
58 0         0 $gbpusd = $q->currency('GBP' => 'USD');
59 0         0 $usdcad = $q->currency('USD' => 'CAD');
60 0         0 $usdsek = $q->currency('USD' => 'SEK');
61 0         0 $usdchf = $q->currency('USD' => 'CHF');
62             }
63 2         30 my $usdx = 50.14348112 * $eurusd**(-0.576) * $usdjpy**(0.136) * $gbpusd**(-0.119) * $usdcad**(0.091) * $usdsek**(0.042) * $usdchf**(0.036);
64 2         14 return $usdx;
65             }
66              
67             =head1 AUTHOR
68              
69             Alberto Simões, C<< >>
70              
71             =head1 BUGS
72              
73             Please report any bugs or feature requests to C
74             rt.cpan.org>, or through the web interface at
75             L. I
76             will be notified, and then you'll automatically be notified of
77             progress on your bug as I make changes.
78              
79             =head1 SUPPORT
80              
81             You can find documentation for this module with the perldoc command.
82              
83             perldoc Finance::USDX
84              
85             You can also look for information at:
86              
87             =over 4
88              
89             =item * RT: CPAN's request tracker (report bugs here)
90              
91             L
92              
93             =item * AnnoCPAN: Annotated CPAN documentation
94              
95             L
96              
97             =item * CPAN Ratings
98              
99             L
100              
101             =item * Search CPAN
102              
103             L
104              
105             =back
106              
107             =head1 LICENSE AND COPYRIGHT
108              
109             Copyright 2012 Alberto Simões.
110              
111             This program is free software; you can redistribute it and/or modify it
112             under the terms of either: the GNU General Public License as published
113             by the Free Software Foundation; or the Artistic License.
114              
115             See http://dev.perl.org/licenses/ for more information.
116              
117              
118             =cut
119              
120             1; # End of Finance::USDX