« blib/lib/Language/Farnsworth/Value/Boolean.pm
↑ Summary
blib/lib/Language/Farnsworth/Value/Array.pm »
| 1 | package Language::Farnsworth::Units::Currency; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 4 | ▶ | use Language::Farnsworth::Value; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | ▶ | use Language::Farnsworth::Value::Pari; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 4 | ▶ | use Language::Farnsworth::Units; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use Language::Farnsworth::Error; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | 4 | ▶ | use Finance::Currency::Convert::XE; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | {#this is a REALLY BAD THING TO DO BUT I DON'T WANT NO ROUNDING AT THIS LEVEL | ||||||||||||
| 17 | 4 | ▶ | no warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | package Finance::Currency::Convert::XE; | ||||||||||||
| 19 | |||||||||||||
| 20 | sub _format | ||||||||||||
| 21 | 0 | ▶ | { | ||||||||||
|
Subroutine
_format: not called CC=1 SCAR=6.9
| |||||||||||||
| 22 | 0 | return "%f"; | |||||||||||
| 23 | } | ||||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | #note that this is fairly C<en-US> centric! | ||||||||||||
| 27 | |||||||||||||
| 28 | 4 | my $defaultcurrency = "USD"; | |||||||||||
| 29 | |||||||||||||
| 30 | 4 | ▶ | my $obj = Finance::Currency::Convert::XE->new(target => $defaultcurrency) | ||||||||||
|
Condition50%1/2
'Finance::Currency::Convert::XE'->new('target', $defaultcurrency) || die("Failed to create object\n")
MC/DC0%0/1
'Finance::Currency::Convert::XE'->new('target', $defaultcurrency) || die("Failed to create object\n")
'Finance::Currency::Convert::XE'->new('target', $defaultcurrency)
Truth table50%1/2
A
A= 'Finance::Currency::Convert::XE'->new('target', $defaultcurrency)
| |||||||||||||
| 31 | || die "Failed to create object\n" ; | ||||||||||||
| 32 | |||||||||||||
| 33 | 4 | my @currencies = $obj->currencies; #go get a list of symbols | |||||||||||
| 34 | |||||||||||||
| 35 | #this is a quick and dirty list of proper names and symbols for defining them below | ||||||||||||
| 36 | 4 | my %symbols = (Afghanis=>'AFN',Baht=>'THB',Balboa=>'PAB',Bolivares_Fuertes=>'VEF',Bolivianos=>'BOB',Cedis=>'GHC', Colon=>'CRC',Colones=>'SVC', | |||||||||||
| 37 | Convertible_Marka=>'BAM',Cordobas=>'NIO',Denars=>'MKD',Dinars=>'RSD',Dollars=>'USD',Dong=>'VND',Euro=>'EUR',Forint=>'HUF',Francs=>'CHF',Guarani=>'PYG', | ||||||||||||
| 38 | Guilders=>'ANG',Hryvnia=>'UAH',Kips=>'LAK',Koruny=>'CZK',Krone=>'NOK',Kroner=>'DKK',Kronor=>'SEK',Kronur=>'ISK',Krooni=>'EEK',Kuna=>'HRK',Lati=>'LVL', | ||||||||||||
| 39 | Leke=>'ALL',Lempiras=>'HNL',Leva=>'BGN',Liras=>'TRL',Lira=>'TRY',Litai=>'LTL',Meticais=>'MZN',Nairas=>'NGN',New_Dollars=>'TWD',New_Lei=>'RON', | ||||||||||||
| 40 | New_Manats=>'AZN',New_Shekels=>'ILS',Pesos=>'MXN',Pounds=>'GBP',Pulas=>'BWP',Quetzales=>'GTQ',Rand=>'ZAR',Reais=>'BRL',Ringgits=>'MYR',Riyals=>'SAR', | ||||||||||||
| 41 | Rubles=>'BYR',Rubles=>'RUB',Rupees=>'INR',Rupiahs=>'IDR',Shillings=>'SOS',Soms=>'KGS',Sums=>'UZS',Switzerland_Francs=>'CHF',Tenge=>'KZT',Tugriks=>'MNT', | ||||||||||||
| 42 | Won=>'KRW',Yen=>'JPY',Yuan_Renminbi=>'CNY',Zimbabwe_Dollars=>'ZWD',Zlotych=>'PLN'); | ||||||||||||
| 43 | |||||||||||||
| 44 | sub init | ||||||||||||
| 45 | 4 | ▶ | { | ||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 46 | 4 | my $env = shift; | |||||||||||
| 47 | #doupdate([],$env,[]); #ignore this for now | ||||||||||||
| 48 | |||||||||||||
| 49 | 4 | $env->{funcs}->addfunc("updatecurrencies", [[undef, undef, undef, 0]], \&doupdate, $env); | |||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | sub doupdate | ||||||||||||
| 53 | 0 | ▶ | { | ||||||||||
|
Subroutine
doupdate: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||
| 54 | 0 | my ($args, $env, $branches)= @_; | |||||||||||
| 55 | |||||||||||||
| 56 | 0 | my $lock = $Language::Farnsworth::Units::lock; | |||||||||||
| 57 | 0 | $Language::Farnsworth::Units::lock = 0; | |||||||||||
| 58 | |||||||||||||
| 59 | 0 | for my $x (@currencies) | |||||||||||
| 60 | { | ||||||||||||
| 61 | 0 | print "Fetching currency $x\n"; | |||||||||||
| 62 | 0 | ▶ | my $currentval = $obj->convert( | ||||||||||
|
Condition0%0/2
$obj->convert('value', '1.00', 'source', $x, 'format', 'number') || die('Could not convert: ' . $obj->error . "\n")
MC/DC0%0/1
$obj->convert('value', '1.00', 'source', $x, 'format', 'number') || die('Could not convert: ' . $obj->error . "\n")
$obj->convert('value', '1.00', 'source', $x, 'format', 'number')
Truth table0%0/2
A
A= $obj->convert('value', '1.00', 'source', $x, 'format', 'number')
| |||||||||||||
| 63 | 'value' => '1.00', | ||||||||||||
| 64 | 'source' => $x, | ||||||||||||
| 65 | 'format' => 'number' | ||||||||||||
| 66 | ) || die "Could not convert: " . $obj->error . "\n"; | ||||||||||||
| 67 | 0 | $env->eval("$x := $currentval dollars;"); | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 0 | for my $name (keys %symbols) | |||||||||||
| 71 | { | ||||||||||||
| 72 | 0 | print "Setting up $name\n"; | |||||||||||
| 73 | 0 | eval {$env->eval("$name := ".$symbols{$name});}; | |||||||||||
| 74 | 0 | ▶ | if ($@) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | { | ||||||||||||
| 76 | 0 | ▶ | warn $@ if ("".$@ =~ "Undefined symbol"); #ignore ones that aren't there anymore, dunno WHY that happens though, i blame XE | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 0 | ▶ | die $@ if ("".$@ !~ "Undefined symbol"); #ignore ones that aren't there anymore, dunno WHY that happens though, i blame XE | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | } | ||||||||||||
| 79 | } | ||||||||||||
| 80 | |||||||||||||
| 81 | 0 | $Language::Farnsworth::Units::lock = $lock; | |||||||||||
| 82 | |||||||||||||
| 83 | 0 | return undef; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 4 | 1; | |||||||||||
| 87 | |||||||||||||