From b40c0de7c32e5d9794c215587165edac1a0ae0c1 Mon Sep 17 00:00:00 2001 From: Shawn Laffan Date: Wed, 7 Aug 2019 18:13:11 +1000 Subject: [PATCH] Filter the set of exportable lists to just hashes Updates #161 --- lib/Biodiverse/Tree.pm | 2 +- lib/Biodiverse/TreeNode.pm | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/Biodiverse/Tree.pm b/lib/Biodiverse/Tree.pm index 89e8a5920..93d94d174 100644 --- a/lib/Biodiverse/Tree.pm +++ b/lib/Biodiverse/Tree.pm @@ -899,7 +899,7 @@ sub get_lists_for_export { my @sub_list; # get a list of available sub_lists (these are actually hashes) - foreach my $list ( sort $self->get_list_names_below ) { # get all lists + foreach my $list ( sort $self->get_list_names_below (no_array_lists => 1) ) { # get all lists if ( $list eq 'SPATIAL_RESULTS' ) { unshift @sub_list, $list; } diff --git a/lib/Biodiverse/TreeNode.pm b/lib/Biodiverse/TreeNode.pm index a5e846a1a..71a41ff25 100644 --- a/lib/Biodiverse/TreeNode.pm +++ b/lib/Biodiverse/TreeNode.pm @@ -2249,17 +2249,26 @@ sub get_lists { } sub get_list_names { - my $self = shift; - return wantarray ? keys %$self : [keys %$self]; + my ($self, %args) = @_; + + return wantarray ? keys %$self : [keys %$self] + if !$args{no_array_lists}; + + my @lists = grep {is_hashref $self->{$_}} keys %$self; + return wantarray ? @lists : \@lists; } -# get a list of all the lists contained in the tree below and including this node +# get a list of all the lists contained in the +# tree below and including this node +# Could linearise this sub get_list_names_below { my $self = shift; my %args = @_; my %list_hash; - my $lists = $self->get_list_names; + my $lists = $self->get_list_names ( + no_array_lists => $args{no_array_lists}, + ); @list_hash{@$lists} = 1 x scalar @$lists; foreach my $child ($self->get_children) { @@ -2267,7 +2276,8 @@ sub get_list_names_below { @list_hash{@$lists} = 1 x scalar @$lists; } - if (! $args{show_hidden_lists}) { # a bit of repeated cleanup, but we need to guarantee we get them if needed + # a bit of repeated cleanup, but we need to guarantee we get them if needed + if (! $args{show_hidden_lists}) { foreach my $key (keys %list_hash) { delete $list_hash{$key} if $key =~ /^_/; }