Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions bin/ledger2beancount
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use warnings;
use strict;

use experimental 'smartmatch';
use List::Util qw/any/;
use utf8;
use feature 'unicode_strings';
use open qw/:std :utf8/;
Expand Down Expand Up @@ -543,7 +543,7 @@ sub create_metadata($$$$) {
$metadata->[KEY] = map_metadata $metadata->[KEY];

# Check if we should store as metadata or as links
if (defined $config->{link_tags} && lc $metadata->[KEY] ~~ [ map lc $_, @{$config->{link_tags}} ]) {
if (defined $config->{link_tags} && do { my $key = lc $metadata->[KEY]; any { $_ eq $key } map lc $_, @{$config->{link_tags}} }) {
return create_tag $metadata->[DEPTH], [ "^" . map_tag $metadata->[VALUE] ];
} else {
$metadata->[TYPE] = META;
Expand Down Expand Up @@ -1264,7 +1264,7 @@ sub map_metadata($) {

# Certain tags won't show up in the beancount file, so there's no need
# to warn about them.
if (!($key ~~ [$config->{narration_tag}, $config->{payee_tag}, $config->{payer_tag}])) {
if (!(any { defined $_ && $_ eq $key } $config->{narration_tag}, $config->{payee_tag}, $config->{payer_tag})) {
$ledger_metadata{$ledger_key} = 1;
}

Expand Down Expand Up @@ -1326,7 +1326,7 @@ sub map_account($) {
print_warning_once("Account $account not allowed; it needs a sub-account, e.g. $account:Subaccount");
$account .= ":Subaccount";
}
if (!($root ~~ @beancount_root_names)) {
if (!(any { $_ eq $root } @beancount_root_names)) {
my $root_type = get_root_type $root;
if ($root_type) {
print_warning_once("Non-standard root name $root used; setting beancount option name_$root_type");
Expand Down Expand Up @@ -1440,7 +1440,7 @@ sub print_warning($) {
sub print_warning_once($) {
my ($warning) = @_;

push @conversion_notes, $warning if !($warning ~~ @conversion_notes);
push @conversion_notes, $warning if !(any { $_ eq $warning } @conversion_notes);
}


Expand Down Expand Up @@ -1886,7 +1886,7 @@ sub set_txn_payee($@) {
}
}
# Return metadata but skip all metadata where the key is in @skip_tags.
@metadata = grep { $_->[TYPE] != META || !($_->[KEY] ~~ @skip_tags)} @metadata;
@metadata = grep { my $m = $_; $m->[TYPE] != META || !(any { $_ eq $m->[KEY] } @skip_tags)} @metadata;

return $header, @metadata;
}
Expand Down Expand Up @@ -1929,7 +1929,7 @@ sub process_txn($$@) {
$header->[TAG] = \@tags if @tags;

my @header_data = grep { $_->[TYPE] == META } @{$metadata};
push @header_data, (grep { $_->[TYPE] ~~ [ META, TAG ] } reverse @ledger_apply);
push @header_data, (grep { $_->[TYPE] == META || $_->[TYPE] == TAG } reverse @ledger_apply);
if (defined $+{auxdate} && defined $config->{auxdate_tag}) {
push @header_data, create_metadata 1, $config->{auxdate_tag}, pp_date($+{auxdate}, $year), 1;
}
Expand Down Expand Up @@ -2108,8 +2108,8 @@ sub process_txn($$@) {
# prices).
my $commodity1 = $i->[AMOUNT]->[CURRENCY];
my $commodity2 = $i->[PRICE]->[AMOUNT]->[CURRENCY];
if (defined $i->[PRICE]->[AMOUNT]->[FIXATED] || $commodity1 ~~ @{$config->{currency_is_commodity}} ||
((length $commodity1 != 3 || length $commodity2 != 3) && !($commodity1 ~~ @{$config->{commodity_is_currency}} || $commodity2 ~~ @{$config->{commodity_is_currency}}))) {
if (defined $i->[PRICE]->[AMOUNT]->[FIXATED] || (any { $_ eq $commodity1 } @{$config->{currency_is_commodity}}) ||
((length $commodity1 != 3 || length $commodity2 != 3) && !((any { $_ eq $commodity1 } @{$config->{commodity_is_currency}}) || (any { $_ eq $commodity2 } @{$config->{commodity_is_currency}})))) {
$i->[COST] = $i->[PRICE];
$i->[PRICE] = undef;
}
Expand Down Expand Up @@ -2697,29 +2697,29 @@ while (@input) {
# Check for renames
foreach (sort keys %ledger_accounts) {
my $map = map_account $_;
if ($_ ne $map && !($map ~~ [values %{$config->{account_map}}]) &&
!($map ~~ [values %account_regex_map])) {
if ($_ ne $map && !(any { $_ eq $map } values %{$config->{account_map}}) &&
!(any { $_ eq $map } values %account_regex_map)) {
print_warning "Account $_ renamed to $map";
}
}

foreach (sort keys %ledger_commodities) {
my $map = map_commodity $_;
if ($_ ne $map && $_ ne qq("$map") && !($map ~~ [values %{$config->{commodity_map}}])) {
if ($_ ne $map && $_ ne qq("$map") && !(any { $_ eq $map } values %{$config->{commodity_map}})) {
print_warning "Commodity $_ renamed to $map";
}
}

foreach (sort keys %ledger_tags) {
my $map = map_tag $_;
if ($_ ne $map && !($map ~~ [values %{$config->{tag_map}}])) {
if ($_ ne $map && !(any { $_ eq $map } values %{$config->{tag_map}})) {
print_warning "Tag $_ renamed to $map";
}
}

foreach (sort keys %ledger_metadata) {
my $map = map_metadata $_;
if ($_ ne $map && !($map ~~ [values %{$config->{metadata_map}}])) {
if ($_ ne $map && !(any { $_ eq $map } values %{$config->{metadata_map}})) {
print_warning "Metadata key $_ renamed to $map";
}
}
Expand Down Expand Up @@ -2786,7 +2786,7 @@ if (scalar keys %root_names) {
# development if we add a wrong entry to %root_mappings.
foreach my $root (keys %root_mappings) {
my $type = $root_mappings{$root};
if (!(ucfirst $type ~~ @beancount_root_names)) {
if (do { my $t = ucfirst $type; !(any { $_ eq $t } @beancount_root_names) }) {
die "Invalid %root_mappings entry for $root: invalid type $type";
}
}
Expand Down
Loading