Skip to content

Commit

Permalink
Filter the set of exportable lists to just hashes
Browse files Browse the repository at this point in the history
Updates #161
  • Loading branch information
shawnlaffan committed Aug 7, 2019
1 parent 293e9ae commit b40c0de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Biodiverse/Tree.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 15 additions & 5 deletions lib/Biodiverse/TreeNode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2249,25 +2249,35 @@ 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) {
$lists = $child->get_list_names_below (%args);
@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 =~ /^_/;
}
Expand Down

0 comments on commit b40c0de

Please sign in to comment.