NAME

Developer::Dashboard::PathsRegistryArg - shared paths-registry constructor guard

SYNOPSIS

use Developer::Dashboard::PathsRegistryArg qw(require_paths_arg);

sub new {
    my ( $class, %args ) = @_;
    my $paths = require_paths_arg(%args);
    return bless { paths => $paths }, $class;
}

DESCRIPTION

Provides require_paths_arg, the single home for a guard that used to be written out identically (or near-identically) in seven modules' own new().

PURPOSE

This module exists to give the codebase one place to check that a constructor was handed a paths registry, instead of repeating the same $args{paths} || die 'Missing paths registry' line at every constructor.

WHY IT EXISTS

Seven modules under lib/ hand-rolled the same constructor guard (DD-785): Collector.pm, Doctor.pm, IndicatorStore.pm and PageStore.pm had byte-identical bodies; Housekeeper.pm differed only by a trailing comma; FileRegistry.pm and Prompt.pm needed the same guard plus extra fields of their own. A future change to the die wording, or to what counts as a valid paths registry, would have had to find every copy by hand.

This ticket scoped itself to these seven constructors deliberately, after finding during research that the same literal die string also appears 24 more times across four other files (CLI/Paths.pm, CLI/Which.pm, InternalCLI.pm, CLI/SeededPages.pm) inside per-function %args guards for CLI action handlers - a different call shape (several required keys, not one) with a much larger blast radius. Those are a related but separate finding, not folded into this extraction.

WHEN TO USE

Use require_paths_arg inside any constructor whose sole or partial job is to require a paths key in its argument hash and bless it (or store it alongside other fields) - never as a general-purpose "get me an argument or die" helper for unrelated keys.

HOW TO USE

Call it with the constructor's own %args hash and use its return value exactly as the former inline guard's $paths variable was used:

sub new {
    my ( $class, %args ) = @_;
    my $paths = require_paths_arg(%args);
    return bless { paths => $paths, extra_field => $args{extra_field} }, $class;
}

It never inspects or requires any key other than paths, so callers that need additional mandatory fields (FileRegistry, Prompt) keep their own separate guards for those.

WHAT USES IT

Developer::Dashboard::Collector, Developer::Dashboard::Doctor, Developer::Dashboard::IndicatorStore, Developer::Dashboard::PageStore, Developer::Dashboard::Housekeeper, Developer::Dashboard::FileRegistry and Developer::Dashboard::Prompt all call it in place of their own former copies of the same guard.

EXAMPLES

Example 1:

require_paths_arg( paths => $registry );

Returns $registry.

Example 2:

require_paths_arg();

Dies with Missing paths registry.