Remove some more trailing whitespace
Florian Ragwitz
13 years ago
205 | 205 | opt_string => $opt_string, |
206 | 206 | required => $attr->is_required && !$attr->has_default && !$attr->has_builder && !exists $config_from_file->{$attr->name}, |
207 | 207 | # NOTE: |
208 | # this "feature" was breaking because | |
209 | # Getopt::Long::Descriptive would return | |
210 | # the default value as if it was a command | |
208 | # this "feature" was breaking because | |
209 | # Getopt::Long::Descriptive would return | |
210 | # the default value as if it was a command | |
211 | 211 | # line flag, which would then override the |
212 | 212 | # one passed into a constructor. |
213 | 213 | # See 100_gld_default_bug.t for an example |
31 | 31 | { |
32 | 32 | ( ( $opt->{required} && !exists($constructor_params->{$opt->{init_arg}}) ) ? (required => $opt->{required}) : () ), |
33 | 33 | # NOTE: |
34 | # remove this 'feature' because it didn't work | |
34 | # remove this 'feature' because it didn't work | |
35 | 35 | # all the time, and so is better to not bother |
36 | # since Moose will handle the defaults just | |
36 | # since Moose will handle the defaults just | |
37 | 37 | # fine anyway. |
38 | 38 | # - SL |
39 | 39 | #( exists $opt->{default} ? (default => $opt->{default}) : () ), |
194 | 194 | C<new_with_options> will throw an exception. |
195 | 195 | |
196 | 196 | If L<Getopt::Long::Descriptive> is installed and any of the following |
197 | command line params are passed, the program will exit with usage | |
197 | command line params are passed, the program will exit with usage | |
198 | 198 | information. You can add descriptions for each option by including a |
199 | 199 | B<documentation> option for each attribute to document. |
200 | 200 |
11 | 11 | { |
12 | 12 | package App; |
13 | 13 | use Moose; |
14 | ||
14 | ||
15 | 15 | with 'MooseX::Getopt'; |
16 | 16 | |
17 | 17 | has 'data' => ( |
18 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
18 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
19 | 19 | is => 'ro', |
20 | 20 | isa => 'Str', |
21 | 21 | default => 'file.dat', |
23 | 23 | ); |
24 | 24 | |
25 | 25 | has 'cow' => ( |
26 | metaclass => 'Getopt', | |
26 | metaclass => 'Getopt', | |
27 | 27 | is => 'ro', |
28 | 28 | isa => 'Str', |
29 | 29 | default => 'moo', |
31 | 31 | ); |
32 | 32 | |
33 | 33 | has 'horse' => ( |
34 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
34 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
35 | 35 | is => 'ro', |
36 | 36 | isa => 'Str', |
37 | 37 | default => 'bray', |
47 | 47 | |
48 | 48 | has 'verbose' => ( |
49 | 49 | is => 'ro', |
50 | isa => 'Bool', | |
51 | ); | |
52 | ||
50 | isa => 'Bool', | |
51 | ); | |
52 | ||
53 | 53 | has 'libs' => ( |
54 | 54 | is => 'ro', |
55 | 55 | isa => 'ArrayRef', |
56 | 56 | default => sub { [] }, |
57 | ); | |
58 | ||
57 | ); | |
58 | ||
59 | 59 | has 'details' => ( |
60 | 60 | is => 'ro', |
61 | 61 | isa => 'HashRef', |
69 | 69 | ); |
70 | 70 | |
71 | 71 | has '_private_stuff_cmdline' => ( |
72 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
72 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
73 | 73 | is => 'ro', |
74 | 74 | isa => 'Int', |
75 | 75 | default => 832, |
76 | 76 | cmd_flag => 'p', |
77 | 77 | ); |
78 | ||
78 | ||
79 | 79 | } |
80 | 80 | |
81 | 81 | foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { |
83 | 83 | isa_ok($attr, 'Moose::Meta::Attribute'); |
84 | 84 | isa_ok($attr, 'MooseX::Getopt::Meta::Attribute'); |
85 | 85 | can_ok($attr, 'cmd_flag'); |
86 | can_ok($attr, 'cmd_aliases'); | |
86 | can_ok($attr, 'cmd_aliases'); | |
87 | 87 | } |
88 | 88 | |
89 | 89 | { |
93 | 93 | isa_ok($app, 'App'); |
94 | 94 | |
95 | 95 | ok(!$app->verbose, '... verbosity is off as expected'); |
96 | is($app->length, 24, '... length is 24 as expected'); | |
97 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
98 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
99 | is_deeply($app->details, {}, '... details is {} as expected'); | |
96 | is($app->length, 24, '... length is 24 as expected'); | |
97 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
98 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
99 | is_deeply($app->details, {}, '... details is {} as expected'); | |
100 | 100 | } |
101 | 101 | |
102 | 102 | { |
106 | 106 | isa_ok($app, 'App'); |
107 | 107 | |
108 | 108 | ok($app->verbose, '... verbosity is turned on as expected'); |
109 | is($app->length, 50, '... length is 50 as expected'); | |
110 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
111 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
112 | is_deeply($app->details, {}, '... details is {} as expected'); | |
109 | is($app->length, 50, '... length is 50 as expected'); | |
110 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
111 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
112 | is_deeply($app->details, {}, '... details is {} as expected'); | |
113 | 113 | } |
114 | 114 | |
115 | 115 | { |
119 | 119 | isa_ok($app, 'App'); |
120 | 120 | |
121 | 121 | ok($app->verbose, '... verbosity is turned on as expected'); |
122 | is($app->length, 24, '... length is 24 as expected'); | |
123 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
124 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
125 | is_deeply($app->details, {}, '... details is {} as expected'); | |
122 | is($app->length, 24, '... length is 24 as expected'); | |
123 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
124 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
125 | is_deeply($app->details, {}, '... details is {} as expected'); | |
126 | 126 | } |
127 | 127 | |
128 | 128 | { |
132 | 132 | isa_ok($app, 'App'); |
133 | 133 | |
134 | 134 | ok($app->verbose, '... verbosity is turned on as expected'); |
135 | is($app->length, 24, '... length is 24 as expected'); | |
136 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
137 | is_deeply($app->libs, | |
138 | ['libs/', 'includes/lib'], | |
139 | '... libs is [libs/, includes/lib] as expected'); | |
140 | is_deeply($app->details, {}, '... details is {} as expected'); | |
135 | is($app->length, 24, '... length is 24 as expected'); | |
136 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
137 | is_deeply($app->libs, | |
138 | ['libs/', 'includes/lib'], | |
139 | '... libs is [libs/, includes/lib] as expected'); | |
140 | is_deeply($app->details, {}, '... details is {} as expected'); | |
141 | 141 | } |
142 | 142 | |
143 | 143 | { |
147 | 147 | isa_ok($app, 'App'); |
148 | 148 | |
149 | 149 | ok(!$app->verbose, '... verbosity is turned on as expected'); |
150 | is($app->length, 24, '... length is 24 as expected'); | |
151 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
152 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
153 | is_deeply($app->details, | |
154 | { os => 'mac', name => 'foo' }, | |
155 | '... details is { os => mac, name => foo } as expected'); | |
150 | is($app->length, 24, '... length is 24 as expected'); | |
151 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
152 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
153 | is_deeply($app->details, | |
154 | { os => 'mac', name => 'foo' }, | |
155 | '... details is { os => mac, name => foo } as expected'); | |
156 | 156 | } |
157 | 157 | |
158 | 158 | { |
163 | 163 | isa_ok($app, 'App'); |
164 | 164 | |
165 | 165 | ok(!$app->verbose, '... verbosity is turned off as expected'); |
166 | is($app->length, 24, '... length is 24 as expected'); | |
167 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
168 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
169 | is_deeply($app->details, {}, '... details is {} as expected'); | |
166 | is($app->length, 24, '... length is 24 as expected'); | |
167 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
168 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
169 | is_deeply($app->details, {}, '... details is {} as expected'); | |
170 | 170 | } |
171 | 171 | |
172 | 172 | # Test cmd_alias without cmd_flag |
12 | 12 | package App; |
13 | 13 | use Moose; |
14 | 14 | use Moose::Util::TypeConstraints; |
15 | ||
15 | ||
16 | 16 | use Scalar::Util 'looks_like_number'; |
17 | ||
17 | ||
18 | 18 | with 'MooseX::Getopt'; |
19 | 19 | |
20 | 20 | subtype 'ArrayOfInts' |
21 | 21 | => as 'ArrayRef' |
22 | 22 | => where { scalar (grep { looks_like_number($_) } @$_) }; |
23 | ||
23 | ||
24 | 24 | MooseX::Getopt::OptionTypeMap->add_option_type_to_map( |
25 | 25 | 'ArrayOfInts' => '=i@' |
26 | 26 | ); |
27 | ||
27 | ||
28 | 28 | has 'nums' => ( |
29 | 29 | is => 'ro', |
30 | 30 | isa => 'ArrayOfInts', |
31 | 31 | default => sub { [0] } |
32 | ); | |
33 | ||
32 | ); | |
33 | ||
34 | 34 | } |
35 | 35 | |
36 | 36 | { |
38 | 38 | |
39 | 39 | my $app = App->new_with_options; |
40 | 40 | isa_ok($app, 'App'); |
41 | ||
42 | is_deeply($app->nums, [0], '... nums is [0] as expected'); | |
41 | ||
42 | is_deeply($app->nums, [0], '... nums is [0] as expected'); | |
43 | 43 | } |
44 | 44 | |
45 | 45 | { |
47 | 47 | |
48 | 48 | my $app = App->new_with_options; |
49 | 49 | isa_ok($app, 'App'); |
50 | ||
51 | is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); | |
50 | ||
51 | is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); | |
52 | 52 | } |
53 | 53 | |
54 | 54 | # Make sure it really used our =i@, instead of falling back |
12 | 12 | package App; |
13 | 13 | use Moose; |
14 | 14 | use Moose::Util::TypeConstraints; |
15 | ||
15 | ||
16 | 16 | use Scalar::Util 'looks_like_number'; |
17 | ||
17 | ||
18 | 18 | with 'MooseX::Getopt'; |
19 | 19 | |
20 | 20 | subtype 'ArrayOfInts' |
21 | 21 | => as 'ArrayRef' |
22 | 22 | => where { scalar (grep { looks_like_number($_) } @$_) }; |
23 | ||
23 | ||
24 | 24 | has 'nums' => ( |
25 | 25 | is => 'ro', |
26 | 26 | isa => 'ArrayOfInts', |
27 | 27 | default => sub { [0] } |
28 | ); | |
29 | ||
28 | ); | |
29 | ||
30 | 30 | } |
31 | 31 | |
32 | 32 | { |
34 | 34 | |
35 | 35 | my $app = App->new_with_options; |
36 | 36 | isa_ok($app, 'App'); |
37 | ||
38 | is_deeply($app->nums, [0], '... nums is [0] as expected'); | |
37 | ||
38 | is_deeply($app->nums, [0], '... nums is [0] as expected'); | |
39 | 39 | } |
40 | 40 | |
41 | 41 | { |
43 | 43 | |
44 | 44 | my $app = App->new_with_options; |
45 | 45 | isa_ok($app, 'App'); |
46 | ||
47 | is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); | |
46 | ||
47 | is_deeply($app->nums, [3, 5], '... nums is [3, 5] as expected'); | |
48 | 48 | } |
49 | 49 |
12 | 12 | { |
13 | 13 | package App; |
14 | 14 | use Moose; |
15 | ||
15 | ||
16 | 16 | with 'MooseX::Getopt'; |
17 | 17 | |
18 | 18 | has 'data' => ( |
19 | traits => [ 'MooseX::Getopt::Meta::Attribute::Trait' ], | |
19 | traits => [ 'MooseX::Getopt::Meta::Attribute::Trait' ], | |
20 | 20 | is => 'ro', |
21 | 21 | isa => 'Str', |
22 | 22 | default => 'file.dat', |
24 | 24 | ); |
25 | 25 | |
26 | 26 | has 'cow' => ( |
27 | traits => [ 'Getopt' ], | |
27 | traits => [ 'Getopt' ], | |
28 | 28 | is => 'ro', |
29 | 29 | isa => 'Str', |
30 | 30 | default => 'moo', |
32 | 32 | ); |
33 | 33 | |
34 | 34 | has 'horse' => ( |
35 | traits => [ 'Getopt' ], | |
35 | traits => [ 'Getopt' ], | |
36 | 36 | is => 'ro', |
37 | 37 | isa => 'Str', |
38 | 38 | default => 'bray', |
48 | 48 | |
49 | 49 | has 'verbose' => ( |
50 | 50 | is => 'ro', |
51 | isa => 'Bool', | |
52 | ); | |
53 | ||
51 | isa => 'Bool', | |
52 | ); | |
53 | ||
54 | 54 | has 'libs' => ( |
55 | 55 | is => 'ro', |
56 | 56 | isa => 'ArrayRef', |
57 | 57 | default => sub { [] }, |
58 | ); | |
59 | ||
58 | ); | |
59 | ||
60 | 60 | has 'details' => ( |
61 | 61 | is => 'ro', |
62 | 62 | isa => 'HashRef', |
70 | 70 | ); |
71 | 71 | |
72 | 72 | has '_private_stuff_cmdline' => ( |
73 | traits => [ 'Getopt' ], | |
73 | traits => [ 'Getopt' ], | |
74 | 74 | is => 'ro', |
75 | 75 | isa => 'Int', |
76 | 76 | default => 832, |
77 | 77 | cmd_flag => 'p', |
78 | 78 | ); |
79 | ||
79 | ||
80 | 80 | } |
81 | 81 | |
82 | 82 | foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { |
83 | 83 | my $attr = App->meta->get_attribute($attr_name); |
84 | 84 | isa_ok($attr, 'Moose::Meta::Attribute'); |
85 | 85 | does_ok($attr, 'MooseX::Getopt::Meta::Attribute::Trait'); |
86 | ||
86 | ||
87 | 87 | can_ok($attr, 'cmd_flag'); |
88 | can_ok($attr, 'cmd_aliases'); | |
88 | can_ok($attr, 'cmd_aliases'); | |
89 | 89 | } |
90 | 90 | |
91 | 91 | { |
95 | 95 | isa_ok($app, 'App'); |
96 | 96 | |
97 | 97 | ok(!$app->verbose, '... verbosity is off as expected'); |
98 | is($app->length, 24, '... length is 24 as expected'); | |
99 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
100 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
101 | is_deeply($app->details, {}, '... details is {} as expected'); | |
98 | is($app->length, 24, '... length is 24 as expected'); | |
99 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
100 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
101 | is_deeply($app->details, {}, '... details is {} as expected'); | |
102 | 102 | } |
103 | 103 | |
104 | 104 | { |
108 | 108 | isa_ok($app, 'App'); |
109 | 109 | |
110 | 110 | ok($app->verbose, '... verbosity is turned on as expected'); |
111 | is($app->length, 50, '... length is 50 as expected'); | |
112 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
113 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
114 | is_deeply($app->details, {}, '... details is {} as expected'); | |
111 | is($app->length, 50, '... length is 50 as expected'); | |
112 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
113 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
114 | is_deeply($app->details, {}, '... details is {} as expected'); | |
115 | 115 | } |
116 | 116 | |
117 | 117 | { |
121 | 121 | isa_ok($app, 'App'); |
122 | 122 | |
123 | 123 | ok($app->verbose, '... verbosity is turned on as expected'); |
124 | is($app->length, 24, '... length is 24 as expected'); | |
125 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
126 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
127 | is_deeply($app->details, {}, '... details is {} as expected'); | |
124 | is($app->length, 24, '... length is 24 as expected'); | |
125 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
126 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
127 | is_deeply($app->details, {}, '... details is {} as expected'); | |
128 | 128 | } |
129 | 129 | |
130 | 130 | { |
134 | 134 | isa_ok($app, 'App'); |
135 | 135 | |
136 | 136 | ok($app->verbose, '... verbosity is turned on as expected'); |
137 | is($app->length, 24, '... length is 24 as expected'); | |
138 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
139 | is_deeply($app->libs, | |
140 | ['libs/', 'includes/lib'], | |
141 | '... libs is [libs/, includes/lib] as expected'); | |
142 | is_deeply($app->details, {}, '... details is {} as expected'); | |
137 | is($app->length, 24, '... length is 24 as expected'); | |
138 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
139 | is_deeply($app->libs, | |
140 | ['libs/', 'includes/lib'], | |
141 | '... libs is [libs/, includes/lib] as expected'); | |
142 | is_deeply($app->details, {}, '... details is {} as expected'); | |
143 | 143 | } |
144 | 144 | |
145 | 145 | { |
149 | 149 | isa_ok($app, 'App'); |
150 | 150 | |
151 | 151 | ok(!$app->verbose, '... verbosity is turned on as expected'); |
152 | is($app->length, 24, '... length is 24 as expected'); | |
153 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
154 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
155 | is_deeply($app->details, | |
156 | { os => 'mac', name => 'foo' }, | |
157 | '... details is { os => mac, name => foo } as expected'); | |
152 | is($app->length, 24, '... length is 24 as expected'); | |
153 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
154 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
155 | is_deeply($app->details, | |
156 | { os => 'mac', name => 'foo' }, | |
157 | '... details is { os => mac, name => foo } as expected'); | |
158 | 158 | } |
159 | 159 | |
160 | 160 | { |
165 | 165 | isa_ok($app, 'App'); |
166 | 166 | |
167 | 167 | ok(!$app->verbose, '... verbosity is turned off as expected'); |
168 | is($app->length, 24, '... length is 24 as expected'); | |
169 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
170 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
171 | is_deeply($app->details, {}, '... details is {} as expected'); | |
168 | is($app->length, 24, '... length is 24 as expected'); | |
169 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
170 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
171 | is_deeply($app->details, {}, '... details is {} as expected'); | |
172 | 172 | } |
173 | 173 | |
174 | 174 | # Test cmd_alias without cmd_flag |
5 | 5 | use Test::More; |
6 | 6 | use Test::Exception; |
7 | 7 | |
8 | BEGIN { | |
8 | BEGIN { | |
9 | 9 | eval 'use Getopt::Long::Descriptive;'; |
10 | 10 | plan skip_all => "Getopt::Long::Descriptive required for this test" if $@; |
11 | 11 | plan tests => 5; |
15 | 15 | { |
16 | 16 | package Testing::Foo; |
17 | 17 | use Moose; |
18 | ||
18 | ||
19 | 19 | with 'MooseX::Getopt'; |
20 | ||
20 | ||
21 | 21 | has 'bar' => ( |
22 | 22 | is => 'ro', |
23 | isa => 'Int', | |
23 | isa => 'Int', | |
24 | 24 | required => 1, |
25 | 25 | ); |
26 | ||
26 | ||
27 | 27 | has 'baz' => ( |
28 | 28 | is => 'ro', |
29 | isa => 'Int', | |
30 | required => 1, | |
31 | ); | |
29 | isa => 'Int', | |
30 | required => 1, | |
31 | ); | |
32 | 32 | } |
33 | 33 | |
34 | 34 | @ARGV = qw(--bar 10); |
8 | 8 | BEGIN { |
9 | 9 | eval 'use Getopt::Long::Descriptive;'; |
10 | 10 | plan skip_all => "Getopt::Long::Descriptive required for this test" if $@; |
11 | plan tests => 5; | |
11 | plan tests => 5; | |
12 | 12 | use_ok('MooseX::Getopt'); |
13 | 13 | } |
14 | 14 | |
15 | 15 | { |
16 | 16 | package Engine::Foo; |
17 | 17 | use Moose; |
18 | ||
18 | ||
19 | 19 | with 'MooseX::Getopt'; |
20 | ||
20 | ||
21 | 21 | has 'nproc' => ( |
22 | 22 | metaclass => 'Getopt', |
23 | 23 | is => 'ro', |
11 | 11 | { |
12 | 12 | package App; |
13 | 13 | use Moose; |
14 | ||
14 | ||
15 | 15 | with 'MooseX::Getopt::Basic'; |
16 | 16 | |
17 | 17 | has 'data' => ( |
18 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
18 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
19 | 19 | is => 'ro', |
20 | 20 | isa => 'Str', |
21 | 21 | default => 'file.dat', |
23 | 23 | ); |
24 | 24 | |
25 | 25 | has 'cow' => ( |
26 | metaclass => 'Getopt', | |
26 | metaclass => 'Getopt', | |
27 | 27 | is => 'ro', |
28 | 28 | isa => 'Str', |
29 | 29 | default => 'moo', |
31 | 31 | ); |
32 | 32 | |
33 | 33 | has 'horse' => ( |
34 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
34 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
35 | 35 | is => 'ro', |
36 | 36 | isa => 'Str', |
37 | 37 | default => 'bray', |
47 | 47 | |
48 | 48 | has 'verbose' => ( |
49 | 49 | is => 'ro', |
50 | isa => 'Bool', | |
51 | ); | |
52 | ||
50 | isa => 'Bool', | |
51 | ); | |
52 | ||
53 | 53 | has 'libs' => ( |
54 | 54 | is => 'ro', |
55 | 55 | isa => 'ArrayRef', |
56 | 56 | default => sub { [] }, |
57 | ); | |
58 | ||
57 | ); | |
58 | ||
59 | 59 | has 'details' => ( |
60 | 60 | is => 'ro', |
61 | 61 | isa => 'HashRef', |
69 | 69 | ); |
70 | 70 | |
71 | 71 | has '_private_stuff_cmdline' => ( |
72 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
72 | metaclass => 'MooseX::Getopt::Meta::Attribute', | |
73 | 73 | is => 'ro', |
74 | 74 | isa => 'Int', |
75 | 75 | default => 832, |
76 | 76 | cmd_flag => 'p', |
77 | 77 | ); |
78 | ||
78 | ||
79 | 79 | } |
80 | 80 | |
81 | 81 | foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) { |
83 | 83 | isa_ok($attr, 'Moose::Meta::Attribute'); |
84 | 84 | isa_ok($attr, 'MooseX::Getopt::Meta::Attribute'); |
85 | 85 | can_ok($attr, 'cmd_flag'); |
86 | can_ok($attr, 'cmd_aliases'); | |
86 | can_ok($attr, 'cmd_aliases'); | |
87 | 87 | } |
88 | 88 | |
89 | 89 | { |
93 | 93 | isa_ok($app, 'App'); |
94 | 94 | |
95 | 95 | ok(!$app->verbose, '... verbosity is off as expected'); |
96 | is($app->length, 24, '... length is 24 as expected'); | |
97 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
98 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
99 | is_deeply($app->details, {}, '... details is {} as expected'); | |
96 | is($app->length, 24, '... length is 24 as expected'); | |
97 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
98 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
99 | is_deeply($app->details, {}, '... details is {} as expected'); | |
100 | 100 | } |
101 | 101 | |
102 | 102 | { |
106 | 106 | isa_ok($app, 'App'); |
107 | 107 | |
108 | 108 | ok($app->verbose, '... verbosity is turned on as expected'); |
109 | is($app->length, 50, '... length is 50 as expected'); | |
110 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
111 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
112 | is_deeply($app->details, {}, '... details is {} as expected'); | |
109 | is($app->length, 50, '... length is 50 as expected'); | |
110 | is($app->data, 'file.dat', '... data is file.dat as expected'); | |
111 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
112 | is_deeply($app->details, {}, '... details is {} as expected'); | |
113 | 113 | } |
114 | 114 | |
115 | 115 | { |
119 | 119 | isa_ok($app, 'App'); |
120 | 120 | |
121 | 121 | ok($app->verbose, '... verbosity is turned on as expected'); |
122 | is($app->length, 24, '... length is 24 as expected'); | |
123 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
124 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
125 | is_deeply($app->details, {}, '... details is {} as expected'); | |
122 | is($app->length, 24, '... length is 24 as expected'); | |
123 | is($app->data, 'foo.txt', '... data is foo.txt as expected'); | |
124 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
125 | is_deeply($app->details, {}, '... details is {} as expected'); | |
126 | 126 | } |
127 | 127 | |
128 | 128 | { |
132 | 132 | isa_ok($app, 'App'); |
133 | 133 | |
134 | 134 | ok($app->verbose, '... verbosity is turned on as expected'); |
135 | is($app->length, 24, '... length is 24 as expected'); | |
136 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
137 | is_deeply($app->libs, | |
138 | ['libs/', 'includes/lib'], | |
139 | '... libs is [libs/, includes/lib] as expected'); | |
140 | is_deeply($app->details, {}, '... details is {} as expected'); | |
135 | is($app->length, 24, '... length is 24 as expected'); | |
136 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
137 | is_deeply($app->libs, | |
138 | ['libs/', 'includes/lib'], | |
139 | '... libs is [libs/, includes/lib] as expected'); | |
140 | is_deeply($app->details, {}, '... details is {} as expected'); | |
141 | 141 | } |
142 | 142 | |
143 | 143 | { |
147 | 147 | isa_ok($app, 'App'); |
148 | 148 | |
149 | 149 | ok(!$app->verbose, '... verbosity is turned on as expected'); |
150 | is($app->length, 24, '... length is 24 as expected'); | |
151 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
152 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
153 | is_deeply($app->details, | |
154 | { os => 'mac', name => 'foo' }, | |
155 | '... details is { os => mac, name => foo } as expected'); | |
150 | is($app->length, 24, '... length is 24 as expected'); | |
151 | is($app->data, 'file.dat', '... data is foo.txt as expected'); | |
152 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
153 | is_deeply($app->details, | |
154 | { os => 'mac', name => 'foo' }, | |
155 | '... details is { os => mac, name => foo } as expected'); | |
156 | 156 | } |
157 | 157 | |
158 | 158 | { |
163 | 163 | isa_ok($app, 'App'); |
164 | 164 | |
165 | 165 | ok(!$app->verbose, '... verbosity is turned off as expected'); |
166 | is($app->length, 24, '... length is 24 as expected'); | |
167 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
168 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
169 | is_deeply($app->details, {}, '... details is {} as expected'); | |
166 | is($app->length, 24, '... length is 24 as expected'); | |
167 | is($app->data, 'file.dat', '... file is file.dat as expected'); | |
168 | is_deeply($app->libs, [], '... libs is [] as expected'); | |
169 | is_deeply($app->details, {}, '... details is {} as expected'); | |
170 | 170 | } |
171 | 171 | |
172 | 172 | # Test cmd_alias without cmd_flag |
16 | 16 | $meta->add_attribute('BigD', traits => ['Getopt'], isa => 'Bool', |
17 | 17 | cmd_aliases => ['D'], is => 'ro'); |
18 | 18 | $meta->add_attribute('SmallD', traits => ['Getopt'], isa => 'Bool', |
19 | cmd_aliases => ['d'], is => 'ro'); | |
19 | cmd_aliases => ['d'], is => 'ro'); | |
20 | 20 | $role->meta->apply($meta); |
21 | 21 | |
22 | 22 | { |