- my $base = $args{base} // $self->root;
-
- my @groups = ($args{inclusive} // 1) ? $base : @{$base->groups};
- my $algo = lc($args{algorithm} || 'ids');
-
- if ($algo eq 'dfs') {
- my %visited;
- return File::KDBX::Iterator->new(sub {
- my $next = shift @groups or return;
- if (!$visited{Hash::Util::FieldHash::id($next)}++) {
- while (my @children = @{$next->groups}) {
- unshift @groups, @children, $next;
- $next = shift @groups;
- $visited{Hash::Util::FieldHash::id($next)}++;
- }
- }
- $next;
- });
- }
- elsif ($algo eq 'bfs') {
- return File::KDBX::Iterator->new(sub {
- my $next = shift @groups or return;
- push @groups, @{$next->groups};
- $next;
- });
- }
- return File::KDBX::Iterator->new(sub {
- my $next = shift @groups or return;
- unshift @groups, @{$next->groups};
- $next;
- });