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 option
  • proto β€” 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