blib/lib/CLDR/Number/Format/Currency.pm

filter: Statementstmt 95.3% 62 / 65 Branchbran 71.4% 20 / 28 Conditioncond 53.3% 8 / 15 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 16 / 16 Podpod 50.0% 1 / 2 totaltotal 80.1% 109 / 136 CC 21 SCAR 14.4
CC
21
Cov
83%
_trigger_cash
9.8
_build_currency_sign
6.0
__ANON__
3.3
CRAP 4.2
« Build ↑ Summary blib/lib/CLDR/Number/Role/Base.pm »
1 package CLDR::Number::Format::Currency;
2  
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use CLDR::Number::Data::Currency;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $VERSION = '0.00_03';
10  
11 6 with qw( CLDR::Number::Role::Format );
12  
13 has currency_code => (
14 is => 'rw',
15 isa => sub {
16 17 ▶ croak 'uninitialized value' if !defined $_[0];
Subroutine __ANON__: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 17 17
17 17 ▶ croak qq{invalid value "$_[0]"} if $_[0] !~ m{ ^ [A-Z]{3} $ }x;
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0] =~ / ^ [A-Z]{3} $ /x 0 17 17
18 },
19 17 ▶ coerce => sub { defined $_[0] ? uc $_[0] : $_[0] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 17 0 17
20 6 trigger => 1,
21 );
22  
23 has currency_sign => (
24 is => 'rw',
25 isa => sub {
26 26 ▶ croak "currency_sign is not defined" if !defined $_[0];
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_[0] 0 26 26
27 },
28 6 );
29  
30 # TODO: accounting NYI
31 has accounting => (
32 is => 'rw',
33 12 ▶ coerce => sub { $_[0] ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 12 12
34 6 default => 0,
35 );
36  
37 has cash => (
38 is => 'rw',
39 12 ▶ coerce => sub { $_[0] ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 12 12
40 6 trigger => 1,
41 default => 0,
42 );
43  
44 6 has _pattern_type => (
45 is => 'ro',
46 default => 'currency',
47 );
48  
49 after _trigger_locale => sub {
50 14 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
51  
52 14 ▶ if ($self->currency_code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->currency_code) 9 5 14
53 9 $self->_build_currency_sign;
54 }
55  
56 14 ▶ if (my $decimal = $self->_get_data(symbols => 'currency_decimal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $decimal = $self->_get_data("symbols", "currency_decimal")) 2 12 14
57 2 $self->decimal_sign($decimal);
58 }
59 6 };
60  
61 ▶sub BUILD {}
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
62  
63 sub _trigger_currency_code {
64 17 ▶ my ($self, $currency_code) = @_;
Subroutine _trigger_currency_code: called CC=1 SCAR=0.0
65  
66 17 $self->_build_currency_sign;
67 17 $self->_trigger_cash;
68 }
69  
70 sub _build_currency_sign {
71 26 ▶ my ($self) = @_;
Subroutine _build_currency_sign: called CC=6 SCAR=18.0
72 26 my $data = $CLDR::Number::Data::Currency::LOCALES;
73 26 my $currency_sign;
74  
75 26 ▶ return if $self->_has_init_arg('currency_sign');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_init_arg("currency_sign") 2 24 26
76  
77 24 for my $locale (@{$self->_locale_inheritance}) {
78 21 ▶ next if !exists $data->{$locale} || !exists $data->{$locale}{$self->currency_code};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$locale} and exists $data->{$locale}{$self->currency_code} 7 14 21
Condition66%2/3
exists $data->{$locale} and exists $data->{$locale}{$self->currency_code}
!ll&&!rl&&r
0714
MC/DC50%1/2
exists $data->{$locale} and exists $data->{$locale}{$self->currency_code}
exists $data->{$locale} exists $data->{$locale}{$self->currency_code}
Truth table66%2/3
A and B
A= exists $data->{$locale}B= exists $data->{$locale}{$self->currency_code}
ABresult
0X0
100
111
79 14 $currency_sign = $data->{$locale}{$self->currency_code};
80 14 last;
81 }
82  
83 24 ▶ $self->currency_sign($currency_sign || $self->currency_code);
Condition66%2/3
$currency_sign || $self->currency_code
l!l&&r!l&&!r
14100
MC/DC0%0/2
$currency_sign || $self->currency_code
$currency_sign $self->currency_code
Truth table66%2/3
A || B
A= $currency_signB= $self->currency_code
ABresult
1X1
011
000
84 }
85  
86 sub _trigger_cash {
87 17 ▶ my ($self) = @_;
Subroutine _trigger_cash: called CC=7 SCAR=22.8
88 17 my $currencies = $CLDR::Number::Data::Currency::CURRENCIES;
89 my $currency_data
90 = $self->currency_code && exists $currencies->{$self->currency_code}
91 ? $currencies->{$self->currency_code}
92 17 ▶ : $currencies->{DEFAULT};
Branch: 1 branch
BranchTrueFalseTotal
$self->currency_code && exists $$currencies{$self->currency_code} ? : 5 12 17
Condition66%2/3
$self->currency_code and exists $$currencies{$self->currency_code}
!ll&&!rl&&r
0125
MC/DC50%1/2
$self->currency_code and exists $$currencies{$self->currency_code}
$self->currency_code exists $$currencies{$self->currency_code}
Truth table66%2/3
A and B
A= $self->currency_codeB= exists $$currencies{$self->currency_code}
ABresult
0X0
100
111
93  
94 17 ▶ if ($self->cash && exists $currency_data->{cash_digits}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cash and exists $currency_data->{'cash_digits'}) { } 0 17 17
Condition33%1/3
$self->cash and exists $currency_data->{"cash_digits"}
!ll&&!rl&&r
1700
MC/DC0%0/2
$self->cash and exists $currency_data->{"cash_digits"}
$self->cash exists $currency_data->{"cash_digits"}
Truth table33%1/3
A and B
A= $self->cashB= exists $currency_data->{"cash_digits"}
ABresult
0X0
100
111
95 0 $self->minimum_fraction_digits($currency_data->{cash_digits});
96 0 $self->maximum_fraction_digits($currency_data->{cash_digits});
97 }
98 else {
99 17 $self->minimum_fraction_digits($currency_data->{digits});
100 17 $self->maximum_fraction_digits($currency_data->{digits});
101 }
102  
103 17 ▶ if ($self->cash && exists $currency_data->{cash_rounding}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cash and exists $currency_data->{'cash_rounding'}) { } 0 17 17
Condition33%1/3
$self->cash and exists $currency_data->{"cash_rounding"}
!ll&&!rl&&r
1700
MC/DC0%0/2
$self->cash and exists $currency_data->{"cash_rounding"}
$self->cash exists $currency_data->{"cash_rounding"}
Truth table33%1/3
A and B
A= $self->cashB= exists $currency_data->{"cash_rounding"}
ABresult
0X0
100
111
104 0 $self->rounding_increment($currency_data->{cash_rounding});
105 }
106 else {
107 17 $self->rounding_increment($currency_data->{rounding});
108 }
109 }
110  
111 sub format {
112 23 ▶ my ($self, $num) = @_;
Subroutine format: called CC=2 SCAR=6.9
Pod documented
113  
114 23 ▶ croak 'Missing required attribute: currency_code'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->currency_code 1 22 23
115 unless $self->currency_code;
116  
117 22 my $format = $self->_format_number($num);
118 22 $format =~ s{ยค}{$self->currency_sign}e;
119  
120 22 return $format;
121 }
122  
123 6 1;
124  
125 __END__
« Build ↑ Summary blib/lib/CLDR/Number/Role/Base.pm »