line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::App::Plugin::Depends; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2421
|
use Moose::Role; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
19
|
|
4
|
3
|
|
|
3
|
|
14807
|
use namespace::autoclean; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
20
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub plugin_metaroles { |
7
|
2
|
|
|
2
|
0
|
6
|
my ($self, $class) = @_; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
return { |
10
|
2
|
|
|
|
|
7
|
attribute => ['MooseX::App::Plugin::Depends::Meta::Attribute'], |
11
|
|
|
|
|
|
|
class => ['MooseX::App::Plugin::Depends::Meta::Class'], |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
1; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__END__ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=encoding utf8 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
MooseX::App::Plugin::Depends - Adds dependent options |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
In your base class: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
package MyApp; |
30
|
|
|
|
|
|
|
use MooseX::App qw(Depends); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
option 'FileFormat' => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => enum( [qw(tsv csv xml)] ), |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
option 'WriteToFile' => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => 'Bool', |
42
|
|
|
|
|
|
|
depends => [qw(FileFormat)], |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
In your script: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#!/usr/bin/env perl |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use strict; |
50
|
|
|
|
|
|
|
use warnings; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
use MyApp; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
MyApp->new_with_options( WriteToFile => 1 ); |
55
|
|
|
|
|
|
|
# generates Error |
56
|
|
|
|
|
|
|
# Option 'WriteToFile' requires 'FileFormat' to be defined |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
MyApp->new_with_options( WriteToFile => 1, FileFormat => 'tsv ); |
59
|
|
|
|
|
|
|
# generates no errors |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
MyApp->new_with_options(); |
62
|
|
|
|
|
|
|
# generates no errors |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
In many real-world scenarios, sets of options are, by design, needed to be |
67
|
|
|
|
|
|
|
specified together. This plugin adds the ability to create dependent options |
68
|
|
|
|
|
|
|
to your application, options that require one or more other options |
69
|
|
|
|
|
|
|
for your application to perform properly. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |