File: MutexGroup.pm

package info (click to toggle)
libmoosex-app-perl 1.43-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: perl: 4,011; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 1,623 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package MooseX::App::Plugin::MutexGroup;

use Moose::Role;
use namespace::autoclean;

sub plugin_metaroles {
    my ($self, $class) = @_;

    return {
        attribute => ['MooseX::App::Plugin::MutexGroup::Meta::Attribute'],
        class     => ['MooseX::App::Plugin::MutexGroup::Meta::Class'],
    }
}

1;

__END__

=encoding utf8

=head1 NAME

MooseX::App::Plugin::MutexGroup - Adds mutually exclusive options

=head1 SYNOPSIS

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'
 );

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

=head1 DESCRIPTION

This plugin adds mutually exclusive options to your application. In the current implementation, all defined
MutexGroups *must* have exactly one initialized option. This means that there is an implicit requiredness
of one option from each MutexGroup.

=cut