| 1 | package Data::Sah::Coerce::perl::To_str::From_str::to_cryptoexchange_currency_pair; | ||||||||||||
| 2 | |||||||||||||
| 3 | # AUTHOR | ||||||||||||
| 4 | 2 | our $DATE = '2019-11-28'; # DATE | |||||||||||
| 5 | 2 | our $DIST = 'Data-Sah-Coerce-perl-To_str-From_str-to_cryptoexchange_currency_pair'; # DIST | |||||||||||
| 6 | 2 | our $VERSION = '0.005'; # 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 cryptoexchange currency pair, e.g. LTC/USD', | ||||||||||||
| 16 | might_fail => 1, | ||||||||||||
| 17 | prio => 50, | ||||||||||||
| 18 | }; | ||||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 1 | ▶ | sub coerce { | ||||||||||
|
Subroutine
coerce: called CC=3 SCAR=11.1
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}{"CryptoCurrency::Catalog"} //= 0; | ||||||||||
|
Condition50%1/2
$res->{"modules"}{"CryptoCurrency::Catalog"} //= 0
MC/DC0%0/1
$res->{"modules"}{"CryptoCurrency::Catalog"} //= 0
$res->{"modules"}{"CryptoCurrency::Catalog"}
Truth table50%1/2
A
A= $res->{"modules"}{"CryptoCurrency::Catalog"}
| |||||||||||||
| 30 | 1 | ▶ | $res->{modules}{"Locale::Codes::Currency_Codes"} //= 0; | ||||||||||
|
Condition50%1/2
$res->{"modules"}{"Locale::Codes::Currency_Codes"} //= 0
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"}
| |||||||||||||
| 31 | 1 | $res->{expr_coerce} = join( | |||||||||||
| 32 | "", | ||||||||||||
| 33 | "do { my \$res; ", | ||||||||||||
| 34 | " my (\$cur1, \$cur2) = $dt =~ m!\\A(\\S+)/(\\S+)\\z! or do { \$res = ['Invalid currency pair syntax, please use CUR1/CUR2 syntax']; goto RETURN_RES }; ", | ||||||||||||
| 35 | |||||||||||||
| 36 | # check currency1 | ||||||||||||
| 37 | " my \$cat = CryptoCurrency::Catalog->new; ", | ||||||||||||
| 38 | " my \$rec; eval { \$rec = \$cat->by_code(\$cur1) }; ", | ||||||||||||
| 39 | " if (\$@) { \$res = ['Unknown cryptocurrency code: ' . \$cur1]; goto RETURN_RES } ", | ||||||||||||
| 40 | " \$cur1 = \$rec->{code}; ", | ||||||||||||
| 41 | |||||||||||||
| 42 | # check currency2 | ||||||||||||
| 43 | " \$cur2 = uc \$cur2; ", | ||||||||||||
| 44 | " if (\$Locale::Codes::Data{currency}{code2id}{alpha}{\$cur2}) { } else { ", | ||||||||||||
| 45 | " my \$rec; eval { \$rec = \$cat->by_code(\$cur2) }; ", | ||||||||||||
| 46 | " if (\$@) { \$res = ['Unknown fiat/cryptocurrency code: ' . \$cur2]; goto RETURN_RES } ", | ||||||||||||
| 47 | " } ", | ||||||||||||
| 48 | |||||||||||||
| 49 | # check currency1 differs from currency2 | ||||||||||||
| 50 | " if (\$cur1 eq \$cur2) { \$res = ['Currency and base currency must differ']; goto RETURN_RES } ", | ||||||||||||
| 51 | |||||||||||||
| 52 | " \$res = [undef, \"\$cur1/\$cur2\"]; ", | ||||||||||||
| 53 | |||||||||||||
| 54 | " RETURN_RES: \$res; ", | ||||||||||||
| 55 | "}", | ||||||||||||
| 56 | ); | ||||||||||||
| 57 | |||||||||||||
| 58 | 1 | $res; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 2 | 1; | |||||||||||
| 62 | # ABSTRACT: Coerce string into cryptoexchange currency pair, e.g. LTC/USD | ||||||||||||
| 63 | |||||||||||||
| 64 | __END__ | ||||||||||||