blib/lib/Mo/utils/Currency.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Mo::utils::Currency;
2  
3 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Locale::Currency;
9 use Readonly;
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 my ($self, $key) = @_;
19  
20 _check_key($self, $key) && return;
21  
22 if (! keys %codes) {
23 %codes = map { $_ => 1 } Locale::Currency::all_currency_codes();
24 }
25  
26 if (! exists $codes{$self->{$key}}) {
27 err "Parameter '$key' must be a valid currency code.",
28 'Value', $self->{$key},
29 ;
30 }
31  
32 return;
33 }
34  
35 sub _check_key {
36 my ($self, $key) = @_;
37  
38 if (! exists $self->{$key} || ! defined $self->{$key}) {
39 return 1;
40 }
41  
42 return 0;
43 }
44  
45 1;
46  
47 __END__
↑ Summary