blib/lib/Data/Sah/Coerce/perl/To_str/From_str/ToCurrencyPair.pm

filter: Statementstmt 100% 20 / 20 Branchbran n/a Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 86.6% 26 / 30 CC 2 SCAR 2.9
CC
2
Cov
95%
coerce
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary
1 package Data::Sah::Coerce::perl::To_str::From_str::ToCurrencyPair;
2  
3 # AUTHOR
4 2 our $DATE = '2019-11-28'; # DATE
5 2 our $DIST = 'Data-Sah-Coerce-perl-To_str-From_str-ToCurrencyPair'; # DIST
6 2 our $VERSION = '0.004'; # VERSION
7  
8 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub meta {
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
13 +{
14 1 v => 4,
15 summary => 'Coerce string into currency pair, e.g. USD/IDR',
16 might_fail => 1,
17 prio => 50,
18 };
19 }
20  
21 1 ▶sub coerce {
Subroutine coerce: called CC=2 SCAR=7.0
Pod undocumented
22 1 my %args = @_;
23  
24 1 my $dt = $args{data_term};
25  
26 1 my $res = {};
27  
28 1 $res->{expr_match} = "!ref($dt)";
29 1 ▶ $res->{modules}{"Locale::Codes::Currency_Codes"} //= 0;
Condition50%1/2
$res->{"modules"}{"Locale::Codes::Currency_Codes"} //= 0
l!l
01
MC/DC0%0/1
$res->{"modules"}{"Locale::Codes::Currency_Codes"} //= 0
$res->{"modules"}{"Locale::Codes::Currency_Codes"}
Truth table50%1/2
A
A= $res->{"modules"}{"Locale::Codes::Currency_Codes"}
Aresult
11
00
30 1 $res->{expr_coerce} = join(
31 "",
32 "do { my \$res; ",
33 " my (\$cur1, \$cur2) = $dt =~ m!\\A(\\S+)/(\\S+)\\z! or do { \$res = ['Invalid currency pair syntax, please use CUR1/CUR2 syntax']; goto RETURN_RES }; ",
34  
35 # check currency1 differs from currency2
36 " if (\$cur1 eq \$cur2) { \$res = ['Base currency and quote currency must differ']; goto RETURN_RES } ",
37  
38 # check currency1
39 " \$cur1 = uc \$cur1; ",
40 " unless (\$Locale::Codes::Data{currency}{code2id}{alpha}{\$cur1}) { ",
41 " \$res = ['Unknown base currency code: ' . \$cur1]; goto RETURN_RES; ",
42 " } ",
43  
44 # check currency2
45 " \$cur2 = uc \$cur2; ",
46 " unless (\$Locale::Codes::Data{currency}{code2id}{alpha}{\$cur2}) { ",
47 " \$res = ['Unknown quote currency code: ' . \$cur2]; goto RETURN_RES; ",
48 " } ",
49  
50 " \$res = [undef, \"\$cur1/\$cur2\"]; ",
51  
52 " RETURN_RES: \$res; ",
53 "}",
54 );
55  
56 1 $res;
57 }
58  
59 2 1;
60 # ABSTRACT: Coerce string into currency pair, e.g. USD/IDR
61  
62 __END__
↑ Summary