File Coverage

lib/WebService/Shippo/Currency.pm
Criterion Covered Total %
statement 16 21 76.1
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 22 33 66.6


line stmt bran cond sub pod time code
1 7     7   38 use strict;
  7         14  
  7         169  
2 7     7   33 use warnings;
  7         11  
  7         170  
3 7     7   31 use MRO::Compat 'c3';
  7         10  
  7         395  
4              
5             package WebService::Shippo::Currency;
6             require WebService::Shippo::Request;
7             require JSON::XS;
8 7     7   33 use Carp ( 'confess' );
  7         10  
  7         4480  
9              
10             {
11             my %codes = (
12             AED => "United Arab Emirates Dirham",
13             AFN => "Afghan Afghani",
14             ALL => "Albanian Lek",
15             AMD => "Armenian Dram",
16             ANG => "Netherlands Antillean Guilder",
17             AOA => "Angolan Kwanza",
18             ARS => "Argentine Peso",
19             AUD => "Australian Dollar",
20             AWG => "Aruban Florin",
21             AZN => "Azerbaijani Manat",
22             BAM => "Bosnia-Herzegovina Convertible Mark",
23             BBD => "Barbadian Dollar",
24             BDT => "Bangladeshi Taka",
25             BGN => "Bulgarian Lev",
26             BHD => "Bahraini Dinar",
27             BIF => "Burundian Franc",
28             BMD => "Bermudan Dollar",
29             BND => "Brunei Dollar",
30             BOB => "Bolivian Boliviano",
31             BRL => "Brazilian Real",
32             BSD => "Bahamian Dollar",
33             BTC => "Bitcoin",
34             BTN => "Bhutanese Ngultrum",
35             BWP => "Botswanan Pula",
36             BYR => "Belarusian Ruble",
37             BZD => "Belize Dollar",
38             CAD => "Canadian Dollar",
39             CDF => "Congolese Franc",
40             CHF => "Swiss Franc",
41             CLF => "Chilean Unit of Account (UF)",
42             CLP => "Chilean Peso",
43             CNY => "Chinese Yuan",
44             COP => "Colombian Peso",
45             CRC => "Costa Rican Colón",
46             CUC => "Cuban Convertible Peso",
47             CUP => "Cuban Peso",
48             CVE => "Cape Verdean Escudo",
49             CZK => "Czech Republic Koruna",
50             DJF => "Djiboutian Franc",
51             DKK => "Danish Krone",
52             DOP => "Dominican Peso",
53             DZD => "Algerian Dinar",
54             EEK => "Estonian Kroon",
55             EGP => "Egyptian Pound",
56             ERN => "Eritrean Nakfa",
57             ETB => "Ethiopian Birr",
58             EUR => "Euro",
59             FJD => "Fijian Dollar",
60             FKP => "Falkland Islands Pound",
61             GBP => "British Pound Sterling",
62             GEL => "Georgian Lari",
63             GGP => "Guernsey Pound",
64             GHS => "Ghanaian Cedi",
65             GIP => "Gibraltar Pound",
66             GMD => "Gambian Dalasi",
67             GNF => "Guinean Franc",
68             GTQ => "Guatemalan Quetzal",
69             GYD => "Guyanaese Dollar",
70             HKD => "Hong Kong Dollar",
71             HNL => "Honduran Lempira",
72             HRK => "Croatian Kuna",
73             HTG => "Haitian Gourde",
74             HUF => "Hungarian Forint",
75             IDR => "Indonesian Rupiah",
76             ILS => "Israeli New Sheqel",
77             IMP => "Manx pound",
78             INR => "Indian Rupee",
79             IQD => "Iraqi Dinar",
80             IRR => "Iranian Rial",
81             ISK => "Icelandic Króna",
82             JEP => "Jersey Pound",
83             JMD => "Jamaican Dollar",
84             JOD => "Jordanian Dinar",
85             JPY => "Japanese Yen",
86             KES => "Kenyan Shilling",
87             KGS => "Kyrgystani Som",
88             KHR => "Cambodian Riel",
89             KMF => "Comorian Franc",
90             KPW => "North Korean Won",
91             KRW => "South Korean Won",
92             KWD => "Kuwaiti Dinar",
93             KYD => "Cayman Islands Dollar",
94             KZT => "Kazakhstani Tenge",
95             LAK => "Laotian Kip",
96             LBP => "Lebanese Pound",
97             LKR => "Sri Lankan Rupee",
98             LRD => "Liberian Dollar",
99             LSL => "Lesotho Loti",
100             LTL => "Lithuanian Litas",
101             LVL => "Latvian Lats",
102             LYD => "Libyan Dinar",
103             MAD => "Moroccan Dirham",
104             MDL => "Moldovan Leu",
105             MGA => "Malagasy Ariary",
106             MKD => "Macedonian Denar",
107             MMK => "Myanma Kyat",
108             MNT => "Mongolian Tugrik",
109             MOP => "Macanese Pataca",
110             MRO => "Mauritanian Ouguiya",
111             MTL => "Maltese Lira",
112             MUR => "Mauritian Rupee",
113             MVR => "Maldivian Rufiyaa",
114             MWK => "Malawian Kwacha",
115             MXN => "Mexican Peso",
116             MYR => "Malaysian Ringgit",
117             MZN => "Mozambican Metical",
118             NAD => "Namibian Dollar",
119             NGN => "Nigerian Naira",
120             NIO => "Nicaraguan Córdoba",
121             NOK => "Norwegian Krone",
122             NPR => "Nepalese Rupee",
123             NZD => "New Zealand Dollar",
124             OMR => "Omani Rial",
125             PAB => "Panamanian Balboa",
126             PEN => "Peruvian Nuevo Sol",
127             PGK => "Papua New Guinean Kina",
128             PHP => "Philippine Peso",
129             PKR => "Pakistani Rupee",
130             PLN => "Polish Zloty",
131             PYG => "Paraguayan Guarani",
132             QAR => "Qatari Rial",
133             RON => "Romanian Leu",
134             RSD => "Serbian Dinar",
135             RUB => "Russian Ruble",
136             RWF => "Rwandan Franc",
137             SAR => "Saudi Riyal",
138             SBD => "Solomon Islands Dollar",
139             SCR => "Seychellois Rupee",
140             SDG => "Sudanese Pound",
141             SEK => "Swedish Krona",
142             SGD => "Singapore Dollar",
143             SHP => "Saint Helena Pound",
144             SLL => "Sierra Leonean Leone",
145             SOS => "Somali Shilling",
146             SRD => "Surinamese Dollar",
147             STD => "São Tomé and Príncipe Dobra",
148             SVC => "Salvadoran Colón",
149             SYP => "Syrian Pound",
150             SZL => "Swazi Lilangeni",
151             THB => "Thai Baht",
152             TJS => "Tajikistani Somoni",
153             TMT => "Turkmenistani Manat",
154             TND => "Tunisian Dinar",
155             TOP => "Tongan Paʻanga",
156             TRY => "Turkish Lira",
157             TTD => "Trinidad and Tobago Dollar",
158             TWD => "New Taiwan Dollar",
159             TZS => "Tanzanian Shilling",
160             UAH => "Ukrainian Hryvnia",
161             UGX => "Ugandan Shilling",
162             USD => "United States Dollar",
163             UYU => "Uruguayan Peso",
164             UZS => "Uzbekistan Som",
165             VEF => "Venezuelan Bolívar Fuerte",
166             VND => "Vietnamese Dong",
167             VUV => "Vanuatu Vatu",
168             WST => "Samoan Tala",
169             XAF => "CFA Franc BEAC",
170             XAG => "Silver (troy ounce)",
171             XAU => "Gold (troy ounce)",
172             XCD => "East Caribbean Dollar",
173             XDR => "Special Drawing Rights",
174             XOF => "CFA Franc BCEAO",
175             XPD => "Palladium Ounce",
176             XPF => "CFP Franc",
177             XPT => "Platinum Ounce",
178             YER => "Yemeni Rial",
179             ZAR => "South African Rand",
180             ZMK => "Zambian Kwacha (pre-2013)",
181             ZMW => "Zambian Kwacha",
182             ZWL => "Zimbabwean Dollar"
183             );
184              
185             my $json = JSON::XS->new->utf8->convert_blessed->allow_blessed;
186              
187             # Attempts to freshen-up that list. I could use Locale::Codes or
188             # Locale::Currency for this but neither works consistently on all
189             # versions of a Perl and, under 5.14, they're particularly irksome.
190            
191             eval {
192             my $r
193             = WebService::Shippo::Request->get(
194             'http://openexchangerates.org/api/currencies.json' );
195             %codes = %{ $json->decode( $r->decoded_content ) }
196             if $r->is_success;
197             };
198              
199             sub validate_currency
200             {
201 0     0 0   my ( $invocant, $currency_code ) = @_;
202 0           my $k = uc( $currency_code );
203             confess "Invalid currency code ($currency_code)"
204 0 0         unless exists( $codes{$k} );
205 0 0         return ( uc( $currency_code ), $codes{$k} )
206             if wantarray;
207 0           return uc( $currency_code );
208             }
209             }
210              
211             BEGIN {
212 7     7   36 no warnings 'once';
  7         11  
  7         230  
213 7     7   277 *Shippo::Currency:: = *WebService::Shippo::Currency::;
214             }
215              
216             1;