MooseX:...:Option(3)
π MooseX::App::Meta::Role::Attribute::Option(3) β¨
okay so this page lives in the User Contributed Perl Documentation section of the manual, and it's literally called MooseX::App::Meta::Role::Attribute::Option β say that five times fast, i dare you π«Ά
πΈ NAME πΈ
MooseX::App::Meta::Role::Attribute::Option β meta attribute role for options (yes that's the whole name, she's long but she's iconic π
π¦ DESCRIPTION π¦
so this meta attribute role? it auto-applies itself to every attribute that's supposed to be used as an option. no manual labor, no cap. you just declare stuff and she handles the meta-level glow-up β¨
π ACCESSORS π
in your app classes and your command classes, you can use the following attributes inside your option definitions or your parameter definitions. here's the whole vibe in one go:
option 'myoption' => (
is => 'rw',
isa => 'ArrayRef[Str]',
documentation => 'My special option',
cmd_flag => 'myopt',
cmd_aliases => [qw(mopt localopt)],
cmd_tags => [qw(Important!)],
cmd_env => 'MY_OPTION',
cmd_position => 1,
cmd_split => qr/,/,
cmd_negate => 'notoption'
);
and now let's break down every single one of those, bestie π
β cmd_flag
use this name instead of the attribute name as the option name. it's giving "go by my stage name" energy π
β cmd_type
this one marks whether the attribute should be used as an option or as a parameter value.
allowed values are:
optionβ a command line optionprotoβ a command line option that should be processed prior to other options (eg. a config-file option that sets other attribues). usually only used for plugin developmemt π οΈparameterβ a positional parameter command line value
β cmd_env
the environment variable name. only uppercase letters, numeric digits and underscores allowed, periodt. if the variable wasn't specified otherwise, the value gets taken from %ENV. π
β cmd_aliases
an Arrayref of alternative option names. your option's little entourage π«Ά
β cmd_tags
extra option tags that get displayed in the usage information, in brackets. cute little labels, y'know? π·οΈ
β cmd_position
overrides the order of the parameters in the usage message. she's particular about her lineup πββοΈ
β cmd_split
splits multiple values at the given separator string or regular expression. only works in conjunction with an 'ArrayRef[*]' type constraint. ie. '--myattr value1,value2' with cmd_split set to ',' would produce an arrayref with to elements. yes, splitting, slay πͺ
β cmd_count
similar to the Getopt::Long '+' modifier β cmd_count turns the attribute into a counter. every occurrence of the attribute in @ARGV (without any value) would increment the resulting value by one. one, two, three, and so on, no cap π₯
β cmd_negate
sets names for the negated variant of a boolean field. only works in conjunction with a 'Bool' type constraint. so you get the "notoption" twin π
π METHODS π
heads up: these methods are only of interest to plugin authors. if that's not you, you can absolutely scroll past, but honestly stay for the vibes π«
π₯ cmd_check
runs sanity checks on options and parameters. will usually only be executed if either HARNESS_ACTIVE or APP_DEVELOPER environment are set. she's doing a vibe check on your options, literally π§
π₯ cmd_name_possible
my @names = $attribute->cmd_name_possible();
returns a list of all possible option names. every single one π
π₯ cmd_name_list
my @names = $attribute->cmd_name_list();
similar to cmd_name_possible, this method returns a list of option names β except for names set via cmd_negate. so the negated ones don't make the cut π
ββοΈ
π₯ cmd_name_primary
my $name = $attribute->cmd_name_primary();
returns the primary option name. the main character energy one π
π₯ cmd_usage_name
my $name = $attribute->cmd_usage_name();
returns the name as used by the usage text.
π₯ cmd_usage_description
my $name = $attribute->cmd_usage_description();
returns the description as used by the usage text.
π₯ cmd_tags_list
my @tags = $attribute->cmd_tags_list();
returns a list of tags π·οΈβ¨
π₯ cmd_type_constraint_check
$attribute->cmd_type_constraint_check($value)
checks the type constraint. returns an error message if the check fails. she will let you know, gently but firmly π
π₯ cmd_type_constraint_description
$attribute->cmd_type_constraint_description($type_constraint,$singular)
creates a description of the selected type constraint. word art, but for types π¨
ngl, all of the above is straight from the source β every flag, every default, every quirk, untouched. i just dressed it up cute π
and that's the whole page, bestie! this one shipped as perl v5.42.0 on 2024-08-09 β mark your calendars, mwah ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-MooseX-App 1.430.1-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms