NAME

Developer::Dashboard::CLI::TableHelpers - shared path-registry and table rendering helpers for the lightweight file/path/which CLI commands

SYNOPSIS

use Developer::Dashboard::CLI::TableHelpers qw(
    build_paths aliases_table list_table mutation_table removal_table render_table
);
my $paths = build_paths();
print aliases_table( { home => '/home/mv' } );

DESCRIPTION

Provides the path-registry builder and the five table-rendering helpers that used to be written out identically (or near-identically) in CLI/Files.pm, CLI/Paths.pm and CLI/Which.pm.

PURPOSE

This module exists to give the codebase one place to build the lightweight CLI path registry and to render the small summary tables the file/path helper commands print, instead of repeating the same bodies verbatim at every call site.

WHY IT EXISTS

_build_paths was byte-identical in CLI/Files.pm and CLI/Which.pm, and functionally identical in CLI/Paths.pm (which carried an extra defined && check that could never be false, annotated # uncoverable branch false). _aliases_table, _list_table, _mutation_table and _removal_table were byte-identical between CLI/Files.pm and CLI/Paths.pm; _render_table differed only by one trailing blank line (DD-773). A future change to how these tables render, or to how the path registry is built, would otherwise have to find every site by hand, since nothing connected them by name.

WHEN TO USE

Use these helpers whenever CLI code needs the lightweight path registry used by the file/path/which commands, or needs to render a two-column, single-column, mutation-result or removal-result summary table in the same style those commands already use.

HOW TO USE

use Developer::Dashboard::CLI::TableHelpers qw(build_paths render_table);
my $paths = build_paths();
print render_table( [ 'Alias', 'Path' ], [ [ 'proj', '/home/mv/projects' ] ] );

WHAT USES IT

Developer::Dashboard::CLI::Files, Developer::Dashboard::CLI::Paths and Developer::Dashboard::CLI::Which all call build_paths in place of their own former copies; Files.pm and Paths.pm also call the four alias/list/mutation/removal table helpers and render_table in place of their own former copies.

EXAMPLES

Example 1:

my $paths = build_paths();
# $paths is a Developer::Dashboard::PathRegistry scoped to the current cwd

Example 2:

print list_table( 'Match', [ '/home/mv/projects/a', '/home/mv/projects/b' ] );
# File  Match
# -----------
# /home/mv/projects/a
# /home/mv/projects/b