File Coverage

blib/lib/Mo/utils/Currency.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 50 50 100.0


line stmt bran cond sub pod time code
1             package Mo::utils::Currency;
2              
3 3     3   166857 use base qw(Exporter);
  3         8  
  3         430  
4 3     3   21 use strict;
  3         6  
  3         102  
5 3     3   15 use warnings;
  3         5  
  3         228  
6              
7 3     3   2133 use Error::Pure qw(err);
  3         48624  
  3         77  
8 3     3   1718 use Locale::Currency;
  3         172448  
  3         570  
9 3     3   28 use Readonly;
  3         50  
  3         1397  
10              
11             Readonly::Array our @EXPORT_OK => qw(check_currency_code);
12              
13             our $VERSION = 0.01;
14              
15             my %codes;
16              
17             sub check_currency_code {
18 4     4 1 261986 my ($self, $key) = @_;
19              
20 4 100       11 _check_key($self, $key) && return;
21              
22 2 100       5 if (! keys %codes) {
23 1         6 %codes = map { $_ => 1 } Locale::Currency::all_currency_codes();
  176         392  
24             }
25              
26 2 100       17 if (! exists $codes{$self->{$key}}) {
27             err "Parameter '$key' must be a valid currency code.",
28 1         7 'Value', $self->{$key},
29             ;
30             }
31              
32 1         3 return;
33             }
34              
35             sub _check_key {
36 4     4   5 my ($self, $key) = @_;
37              
38 4 100 100     20 if (! exists $self->{$key} || ! defined $self->{$key}) {
39 2         7 return 1;
40             }
41              
42 2         4 return 0;
43             }
44              
45             1;
46              
47             __END__