MouseX...tribute(3pm)

πŸ“¦
version 0.38 Β· 4 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– MouseX::Getopt::Meta::Attribute β€” the optional meta attribute for custom option names ✨

okay bestie, so the manual name is MouseX...tribute(3pm) (it's MouseX::Getopt::Meta::Attribute(3pm) but the header got a lil' shy and truncated itself, we don't judge 🫢). Anyway. You know how MouseX::Getopt just... makes up command line flags for you? Yeah, this is the thing that lets you be the main character and pick your own. πŸ‘‘


✨ SYNOPSIS ✨

package App;
use Mouse;

with 'MouseX::Getopt';

has 'data' => (
    metaclass => 'MouseX::Getopt::Meta::Attribute',
    is        => 'ro',
    isa       => 'Str',
    default   => 'file.dat',

    # tells MouseX::Getopt to use --somedata as the
    # command line flag instead of the normal
    # autogenerated one (--data)
    cmd_flag  => 'somedata',

    # tells MouseX::Getopt to also allow --moosedata,
    # -m, and -d as aliases for this same option on
    # the commandline.
    cmd_aliases => [qw/ moosedata m d /],

    # Or, you can use a plain scalar for a single alias:
    cmd_aliases => 'm',
);

like, look at that. cmd_flag and cmd_aliases are the whole moment. 🌸


πŸ’… DESCRIPTION πŸ’…

So this is a custom attribute metaclass, and what it does is let you say "hey, use this specific command line flag" instead of the default one that MouseX::Getopt would've autogenerated for you. No cap, that's the whole gig.

Is it the prettiest way to do this? honestly? no. The docs themselves are like "this is certainly not the prettiest way to go about this" β€” and they're being real. But for now, it works, and it works for the people who need this kind of feature. we love a functional mess πŸ’€


πŸ¦‹ Custom Metaclass alias πŸ¦‹

Okay so this part is lowkey iconic: it now takes advantage of the Moose 0.19 feature that supports custom attribute metaclass aliases. Which means β€” plot twist β€” you can also use this as the Getopt alias. Like this:

has 'foo' => (metaclass => 'Getopt', cmd_flag => 'f');

see how short that is?? it's giving efficiency. ✨

cmd_flag πŸŽ€

Changes the commandline flag to be this value, instead of the default β€” and the default is literally just the same as the attribute name. So data becomes --data unless you say otherwise, and you are saying otherwise.

cmd_aliases 🌈

Adds more aliases for this commandline flag. Super useful for short options and that kind of thing β€” you know, the -m, -d, single-letter girlies. πŸ’…

has_cmd_flag

has_cmd_aliases

(yeah bestie, these two are just... listed. that's what the original says, and I'm not about to invent lore for them. πŸ™ˆ)


fr fr reminder: cmd_aliases takes either an arrayref like [qw/ moosedata m d /] or a plain scalar like 'm' if you only want a single alias. both are valid, pick your fighter. ⭐

okay that's the whole page!! this one came from the User Contributed Perl Documentation, and it's perl v5.32.1, dated 2021-09-16. shoutout to that exact version and date, they ate and left no crumbs. mwah, go write some cute command line flags πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from