MouseX...pt::GLD(3pm)

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

πŸ‘‘ NAME πŸ‘‘

MouseX::Getopt::GLD β€” bestie, it's literally a Mouse role that processes your command line options using Getopt::Long::Descriptive πŸ’…

That's the whole vibe. You slap this role on your class and suddenly your object knows how to read @ARGV like it's nothing. No cap. ✨


🌸 SYNOPSIS 🌸

Okay so here's the whole lil story arc, in three acts πŸŽ€

Act 1: the class. You write a regular old Mouse class, but you with the role. And you mark the attributes you want to come from the command line:

## In your class
package My::App;
use Mouse;

with 'MouseX::Getopt::GLD';

has 'out' => (is => 'rw', isa => 'Str', required => 1);
has 'in'  => (is => 'rw', isa => 'Str', required => 1);

# ... rest of the class here

Notice how out and in are both required => 1? Yeah. The command line is gonna be the one supplying them. That's the whole point 🫢

Act 2: the script. You don't call new. You call new_with_options, and it does the ✨thing✨:

## in your script
#!/usr/bin/perl

use My::App;

my $app = My::App->new_with_options();
# ... rest of the script here

Act 3: the command line. You actually run it and pass the flags, and the object gets built from them:

## on the command line
% perl my_app_script.pl -in file.input -out file.dump

And that's it. That's the demo. It's giving effortless, honestly 😌πŸ”₯

Heads up bestie: this page is short on purpose β€” the role does the work, and the details of how the option parsing goes down live with Getopt::Long::Descriptive and its friends. This is just the entrance πŸ’œ

πŸ¦‹ SIGN-OFF πŸ¦‹

And that's the page, bestie πŸ’– This one came out of the User Contributed Perl Documentation pile, running on perl v5.32.1, dated 2021-09-16. Go forth and parse some options, you absolute icon πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from