logo
Free, Micro AI Code Reviews That Run on Git Commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt git-lrc - Free, Micro AI Code Reviews That Run on Git Commit | Product Hunt

MooseX::App::Plugin::Depends - Adds dependent options

Description

       In many real-world scenarios, sets of options are, by design, needed to be specified together. This
       plugin adds the ability to create dependent options to your application, options that require one or more
       other options for your application to perform properly.

perl v5.36.0                                       2023-10-22                  MooseX::App::Plugin::Depends(3pm)

Name

       MooseX::App::Plugin::Depends - Adds dependent options

Synopsis

       In your base class:

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

        use Moose::Util::TypeConstraints;

        option 'FileFormat' => (
          is  => 'ro',
          isa => enum( [qw(tsv csv xml)] ),
        );

        option 'WriteToFile' => (
          is       => 'ro',
          isa      => 'Bool',
          depends => [qw(FileFormat)],
        );

       In your script:

        #!/usr/bin/env perl

        use strict;
        use warnings;

        use MyApp;

        MyApp->new_with_options( WriteToFile => 1 );
        # generates Error
        # Option 'WriteToFile' requires 'FileFormat' to be defined

        MyApp->new_with_options( WriteToFile => 1, FileFormat => 'tsv );
        # generates no errors

        MyApp->new_with_options();
        # generates no errors

See Also