MooseX:...e::Trait(3)
π NAME π
MooseX::Role::Cmd::Meta::Attribute::Trait β the optional meta attribute trait that lets you give your command-line options custom names π
(oh and psst, bestie, this one lives in the User Contributed Perl Documentation section of your manual, so you know it's the good stuff β¨)
πΈ SYNOPSIS πΈ
okay so picture this: you're building a command-line thing and you want your attributes to just know how they should show up as options. boom. here's the whole vibe:
package MyApp::Cmd::SomeScript;
with 'MooseX::Role::Cmd';
has 'basic' => (
isa => 'Str',
is => 'rw',
);
has 'prefix' => (
traits => [ 'CmdOpt' ],
isa => 'Str',
is => 'rw',
cmdopt_prefix => '-',
);
has 'rename' => (
traits => [ 'CmdOpt' ],
isa => 'Str',
is => 'rw',
cmdopt_name => '+alt_name',
);
$cmd = MyApp::Cmd::SomeScript->new( basic => 'foo', prefix => 'bar', rename => 'foobar' );
$cmd->run();
# somescript --basic foo -prefix bar +alt_name foobar
like, look at that last line π it literally just works. -prefix instead of --prefix? +alt_name instead of rename? yes queen. we love a flexible trait. π
π¦ DESCRIPTION π¦
So what this module actually does: it hands MooseX::Role::Cmd a lil bit of extra markup so that role can figure out how to use your command line parameters. that's the whole job. it's giving "backstage crew for your CLI" energy and honestly? iconic. π
β¨ ATTRIBUTES β¨
π cmdopt_prefix
Forces the command prefix to be a certain character. This was introduced to allow parameters to be specified as -param or --param
so like, if you're tired of everything defaulting to -- and you want a single lil dash era, this is your girl. π«Ά
π has_cmdopt_prefix
Test for attribute above
π cmdopt_name
Forces the command options name to be the passed string. This was introduced to allow parameters to have a different name to the attribute.
heads up bestie: This option will override thecmdopt_prefixattribute. so if you set both,cmdopt_namewins. no cap. π
π has_cmdopt_name
Test for attribute above
π§ cmdopt_env
This attribute trait can be used to specify an environment variable rather than a command line option.
has 'home_dir' => (
traits => [ 'CmdOpt' ],
is => 'rw',
isa => 'Str',
cmdopt_env => 'APP_HOME',
default => '/my/app/home'
);
# $ENV{APP_HOME} = /my/app/home
not everything has to be a flag!! sometimes the vibe lives in the environment instead and this trait is how you say so. π±
β has_cmdopt_env
Test for attribute above
π BUGS π
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
fr fr, every single piece of complex software has bugs hiding in it somewhere and this module is not the exception π if you catch one, either email the author or drop it in cpan-RT. don't suffer in silence, bestie.
π AUTHOR π
Ian Sillitoe <ian.sillitoe@gmail.com>
π₯ SEE ALSO π₯
The idea for this code was ripped kicking and screaming from MooseX::Getopt::Meta::Attribute::Trait
literally kicking and screaming, that's the lore, I don't make the rules π
πΈ COPYRIGHT AND LICENSE πΈ
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page, you made it, I'm so proud of you π₯Ήβ¨
this lil beauty comes to you as perl v5.42.0, dated 2025-07-25, filed under MooseX:...e::Trait(3) β go forth and name your options whatever your heart desires πππ¦
π¦ where this page comes from
- fedora 43: perl-MooseX-Role-Cmd 0.10-39.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms