Perinc...idation(3pm)
β¨ NAME β¨
Perinci::CmdLine::Manual::Explanation::ArgumentValidation β bestie, it's literally the manual for argument validation π
(and yeah, the page header shortens it to Perinc...idation(3pm) which is giving β¨abbreviatedβ¨ energy, but we know the whole name now π«Ά).
πΈ VERSION πΈ
This doc describes version 2.000.2 of Perinci::CmdLine::Manual::Explanation::ArgumentValidation, which ships in the Perl distribution Perinci-CmdLine. It dropped on 2026-03-30 β
π DESCRIPTION π
okay so here's the tea: argument validation happens BEFORE the arguments get handed off to the function. No cap. And it covers three whole things:
- making sure required arguments β meaning arguments where the
reqproperty is set to true β are actually specified π (yes bestie, they're mandatory, you can't skip). - checking that the values of the specified arguments conform to the argument schema (that's the
schemaproperty, which is described in Sah format π). - making sure argument relation rules are followed β those live in the
args_relsproperty inside theargsfunction metadata property π.
And also, every argument that the user specified β OR that has a default value / default rules sitting in its schema β gets vibe-checked against its schema. Like, for real:
# argument specification
# this argument has a default clause in its schema
foo => {
schema => ['str*', default=>'on'],
...
}
# this argument has a default-value rule clause in its schema
mod => {
schema => ['perl::modname*', 'x.perl.default_value_rules'=>['Perl::this_mod']],
...
}
π FAQ π
π How to find out if an argument is set explicitly by the user or is getting a default value from the schema/argument specification?
Use the special argument -set_ARGNAME π
π How to get the original value on an argument sent by user before the argument is being coerced/filtered/given default value by the schema?
Use the special argument -orig_ARGNAME π¦
π How to get the default value of an argument from the schema/argument specification?
Use the special argument -default_ARGNAME π
π What's the difference between setting a default in the argument specification vs in the schema?
Okay this one's important, so sit with me for a sec π§
There are two ways to set a default value. Way number one is via the default property in the argument specification:
# in the function metadata property...
args => {
foo => {
schema => 'str*',
default => 'on',
},
...
}
This means, if user does not specify the argument:
# via CLI
% progname
# via wrapped function call
funcname()
then the function will get a foo key in its %args automatically π₯ As well as -set_foo set to false, -default_foo set to "on". And we know β from -set_foo β that foo gets its value from the default and not from the user explicitly setting it. Slay, now you can tell the difference π
Way number two is by setting the default value in the schema's default clause or the x.perl.default_value_rules property (and bestie, that second one is the icon that allows dynamic default values β¨):
# in the function metadata property...
args => {
bar => {
schema => ['str*', default=>'on'],
...
},
baz => {
schema => ['perl::modname*', 'x.perl.default_value_rules'=>['Perl::this_mod']],
...
},
...
}
This means that if the argument value is set to undefined value (undef), it will get set the default from schema during argument validation π:
# via CLI
% progname --baz-json 'null'
# via wrapped function call
funcname(baz=>undef)
Function will receive bar key in its %args set to "on", baz set to e.g. Some::Module instead of undef. %args will also contain -set_bar (false), -set_baz (true), -orig_baz (undef) as well as -default_bar ("on") and -default_baz ("Some::Module"). π
And you can know from -set_bar that the argument is set by default value and not explicitly by user π«Ά
π HOMEPAGE π
Please visit the project's homepage at <https://metacpan.org/release/Perinci-CmdLine>.
π¦ SOURCE π¦
Source repository is at <https://github.com/perlancar/perl-Perinci-CmdLine>.
π AUTHOR π
perlancar <perlancar@cpan.org>
π CONTRIBUTING π
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2026 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
π₯ BUGS π₯
Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-CmdLine>.
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature π
ngl, a test-file or patch that actually shows the bug is the whole move β it's giving main character energy and it makes everyone's life easier π
okay that's the whole page bestie!! this was perl v5.40.1, dated 2026-04-05, and it's the Perinc...idation(3pm) page from User Contributed Perl Documentation. iykyk π§β¨π
π¦ where this page comes from
- ubuntu stonking: libperinci-cmdline-perl 2.000.2-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms