line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::App::Plugin::MutexGroup; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2644
|
use Moose::Role; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
17107
|
use namespace::autoclean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub plugin_metaroles { |
7
|
2
|
|
|
2
|
0
|
6
|
my ($self, $class) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
return { |
10
|
2
|
|
|
|
|
11
|
attribute => ['MooseX::App::Plugin::MutexGroup::Meta::Attribute'], |
11
|
|
|
|
|
|
|
class => ['MooseX::App::Plugin::MutexGroup::Meta::Class'], |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__END__ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=encoding utf8 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
MooseX::App::Plugin::MutexGroup - Adds mutually exclusive options |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In your base class: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package MyApp; |
30
|
|
|
|
|
|
|
use MooseX::App qw(MutexGroup); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
option 'UseAmmonia' => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
isa => 'Bool', |
35
|
|
|
|
|
|
|
mutexgroup => 'NonMixableCleaningChemicals', |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
option 'UseChlorine' => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => 'Bool', |
41
|
|
|
|
|
|
|
mutexgroup => 'NonMixableCleaningChemicals' |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
In your script: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#!/usr/bin/env perl |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use strict; |
49
|
|
|
|
|
|
|
use warnings; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use MyApp; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
MyApp->new_with_options( UseAmmonia => 1, UseChlorine => 1 ); |
54
|
|
|
|
|
|
|
# generates Error |
55
|
|
|
|
|
|
|
# More than one attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *cannot* be specified |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
MyApp->new_with_options(); |
58
|
|
|
|
|
|
|
# generates Error |
59
|
|
|
|
|
|
|
# One attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *must* be specified |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
MyApp->new_with_options( UseAmmonia => 1 ); |
62
|
|
|
|
|
|
|
# generates no errors |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
MyApp->new_with_options( UseChlorine => 1 ); |
65
|
|
|
|
|
|
|
# generates no errors |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This plugin adds mutually exclusive options to your application. In the current implementation, all defined |
70
|
|
|
|
|
|
|
MutexGroups *must* have exactly one initialized option. This means that there is an implicit requiredness |
71
|
|
|
|
|
|
|
of one option from each MutexGroup. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |