NAME
Developer::Dashboard::DirEntries - shared dot-filtered directory listing helper
SYNOPSIS
use Developer::Dashboard::DirEntries qw(sorted_dir_entries);
opendir my $dh, $some_dir or die "Unable to read $some_dir: $!";
for my $entry ( sorted_dir_entries($dh) ) { ... }
DESCRIPTION
Provides sorted_dir_entries, the single home for a filter that used to be written out identically at six call sites across three modules.
PURPOSE
This module exists to give the codebase one place to read a directory's entries excluding . and .., sorted, instead of repeating the same grep/sort idiom verbatim at every call site.
WHY IT EXISTS
Six sites in SkillDispatcher.pm, DockerCompose.pm and CLI/Which.pm carried byte-identical sort grep { $_ ne '.' && $_ ne '..' } readdir($dh) expressions with no shared helper (DD-762). Each instance was correct, but a future change to what counts as a filterable entry would have to find every site by hand, since nothing connects them by name.
WHEN TO USE
Use sorted_dir_entries whenever code needs to iterate a directory's real entries (excluding the self/parent pseudo-entries) in a stable order. It does not own opening or closing the handle - callers keep that responsibility, since error handling and root resolution differ per caller.
HOW TO USE
Open the directory yourself first, with whatever error handling your caller needs, then pass the open handle straight to sorted_dir_entries. It never opens or closes anything on its own, so it is safe to call from inside a loop that reuses one handle, or from code that has already validated the directory exists:
opendir my $dh, $dir or die "Unable to read $dir: $!";
for my $entry ( sorted_dir_entries($dh) ) {
...
}
closedir $dh;
WHAT USES IT
Developer::Dashboard::SkillDispatcher, Developer::Dashboard::DockerCompose and Developer::Dashboard::CLI::Which all call it in place of their own former copies of the same filter.
EXAMPLES
Example 1:
opendir my $dh, '/tmp' or die $!;
my @names = sorted_dir_entries($dh);
Returns every entry under /tmp except . and .., sorted.