MooseX:...texGroup(3)

🌸 NAME 🌸

MooseX::App::Plugin::MutexGroup β€” this little baddie (it's a plugin, section 3 of the User Contributed Perl Documentation, iykyk) adds mutually exclusive options to your app. Slay.


✨ SYNOPSIS ✨

Okay so first, in your base class 🫢:

package MyApp;
use MooseX::App qw(MutexGroup);

option 'UseAmmonia' => (
  is         => 'ro',
  isa        => 'Bool',
  mutexgroup => 'NonMixableCleaningChemicals',
);

option 'UseChlorine' => (
  is         => 'ro',
  isa        => 'Bool',
  mutexgroup => 'NonMixableCleaningChemicals'
);

Then in your script πŸ’…:

#!/usr/bin/env perl

use strict;
use warnings;

use MyApp;

MyApp->new_with_options( UseAmmonia => 1, UseChlorine => 1 );
# generates Error
# More than one attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *cannot* be specified

MyApp->new_with_options();
# generates Error
# One attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *must* be specified

MyApp->new_with_options( UseAmmonia => 1 );
# generates no errors

MyApp->new_with_options( UseChlorine => 1 );
# generates no errors

Like, the vibes are: pick one chemical, bestie. Not both, not neither. πŸ§ͺπŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

This plugin adds mutually exclusive options to your application, and honestly? Iconic behaviour.

In the current implementation, every defined MutexGroup must have exactly one initialized option. Read that again, because it's the whole plot twist 😭 β€” that means there's an implicit requiredness of one option from each MutexGroup.

So yeah: exactly one, always. No cap. πŸ”₯


πŸŽ€ sign-off πŸŽ€

That's the whole page, bestie β€” brought to you by perl v5.42.0, dated 2024-08-09, and filed under MooseX:...texGroup(3). Go forth and pick exactly one option, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from