NAME
CLI::Simple::Options - option normalization, validation, and finalization
DESCRIPTION
This role implements option normalization, validation, and finalization for CLI::Simple. For application-facing declarations, supported types, constraints, and collection semantics, see "OPTION DECLARATIONS AND VALIDATION" in CLI::Simple.
METHODS AND SUBROUTINES
normalize_option_specs
my ($specs, $metadata) = $self->normalize_option_specs($declarations);
Returns an array reference of Getopt::Long specifications and a hash reference of associated option metadata. The supplied declarations are not modified.
Metadata is keyed by the first name in the option specification, with hyphens converted to underscores. Duplicate canonical names cause an exception. Each entry includes spec, the original specification, and the declared attributes. When a type can be inferred, inferred_type records it and type defaults to that value unless an explicit type was supplied. Recognized collection suffixes produce a collection entry of array or hash. Unknown modifiers do not produce an inferred type. Declaration constraints are checked during normalization.
validate_options
$self->validate_options;
Validates all defined option values against their metadata. Required options must be defined after providers and defaults are applied. Optional undefined values are skipped. Collection specifications validate each array element or hash value. A defined collection must have the expected reference type; each element or value must be a defined scalar. Fails with an exception on invalid values. Returns the application instance.
finalize_options
$self->finalize_options;
Invokes each declared finalize code reference once for a defined option value, after validation. The callback receives the application instance and current value, in that order. For type => file, slurp => 1 first reads the validated pathname and passes its contents to the callback. With no callback, the contents become the stored option value. slurp is only supported for scalar file options. The result replaces the accessor contents without further validation. Optional undefined values are skipped. A callback exception is reported with the option name. Finalizers may return references or undef. Options are processed in sorted canonical name order. Returns the application instance.