Codebase list libmousex-getopt-perl-upstream / 2557b52
Remove some more trailing whitespace Florian Ragwitz 13 years ago
11 changed file(s) with 158 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
205205 opt_string => $opt_string,
206206 required => $attr->is_required && !$attr->has_default && !$attr->has_builder && !exists $config_from_file->{$attr->name},
207207 # 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
211211 # line flag, which would then override the
212212 # one passed into a constructor.
213213 # See 100_gld_default_bug.t for an example
3131 {
3232 ( ( $opt->{required} && !exists($constructor_params->{$opt->{init_arg}}) ) ? (required => $opt->{required}) : () ),
3333 # NOTE:
34 # remove this 'feature' because it didn't work
34 # remove this 'feature' because it didn't work
3535 # 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
3737 # fine anyway.
3838 # - SL
3939 #( exists $opt->{default} ? (default => $opt->{default}) : () ),
194194 C<new_with_options> will throw an exception.
195195
196196 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
198198 information. You can add descriptions for each option by including a
199199 B<documentation> option for each attribute to document.
200200
1111 {
1212 package App;
1313 use Moose;
14
14
1515 with 'MooseX::Getopt';
1616
1717 has 'data' => (
18 metaclass => 'MooseX::Getopt::Meta::Attribute',
18 metaclass => 'MooseX::Getopt::Meta::Attribute',
1919 is => 'ro',
2020 isa => 'Str',
2121 default => 'file.dat',
2323 );
2424
2525 has 'cow' => (
26 metaclass => 'Getopt',
26 metaclass => 'Getopt',
2727 is => 'ro',
2828 isa => 'Str',
2929 default => 'moo',
3131 );
3232
3333 has 'horse' => (
34 metaclass => 'MooseX::Getopt::Meta::Attribute',
34 metaclass => 'MooseX::Getopt::Meta::Attribute',
3535 is => 'ro',
3636 isa => 'Str',
3737 default => 'bray',
4747
4848 has 'verbose' => (
4949 is => 'ro',
50 isa => 'Bool',
51 );
52
50 isa => 'Bool',
51 );
52
5353 has 'libs' => (
5454 is => 'ro',
5555 isa => 'ArrayRef',
5656 default => sub { [] },
57 );
58
57 );
58
5959 has 'details' => (
6060 is => 'ro',
6161 isa => 'HashRef',
6969 );
7070
7171 has '_private_stuff_cmdline' => (
72 metaclass => 'MooseX::Getopt::Meta::Attribute',
72 metaclass => 'MooseX::Getopt::Meta::Attribute',
7373 is => 'ro',
7474 isa => 'Int',
7575 default => 832,
7676 cmd_flag => 'p',
7777 );
78
78
7979 }
8080
8181 foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) {
8383 isa_ok($attr, 'Moose::Meta::Attribute');
8484 isa_ok($attr, 'MooseX::Getopt::Meta::Attribute');
8585 can_ok($attr, 'cmd_flag');
86 can_ok($attr, 'cmd_aliases');
86 can_ok($attr, 'cmd_aliases');
8787 }
8888
8989 {
9393 isa_ok($app, 'App');
9494
9595 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');
100100 }
101101
102102 {
106106 isa_ok($app, 'App');
107107
108108 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');
113113 }
114114
115115 {
119119 isa_ok($app, 'App');
120120
121121 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');
126126 }
127127
128128 {
132132 isa_ok($app, 'App');
133133
134134 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');
141141 }
142142
143143 {
147147 isa_ok($app, 'App');
148148
149149 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');
156156 }
157157
158158 {
163163 isa_ok($app, 'App');
164164
165165 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');
170170 }
171171
172172 # Test cmd_alias without cmd_flag
1212 package App;
1313 use Moose;
1414 use Moose::Util::TypeConstraints;
15
15
1616 use Scalar::Util 'looks_like_number';
17
17
1818 with 'MooseX::Getopt';
1919
2020 subtype 'ArrayOfInts'
2121 => as 'ArrayRef'
2222 => where { scalar (grep { looks_like_number($_) } @$_) };
23
23
2424 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
2525 'ArrayOfInts' => '=i@'
2626 );
27
27
2828 has 'nums' => (
2929 is => 'ro',
3030 isa => 'ArrayOfInts',
3131 default => sub { [0] }
32 );
33
32 );
33
3434 }
3535
3636 {
3838
3939 my $app = App->new_with_options;
4040 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');
4343 }
4444
4545 {
4747
4848 my $app = App->new_with_options;
4949 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');
5252 }
5353
5454 # Make sure it really used our =i@, instead of falling back
1212 package App;
1313 use Moose;
1414 use Moose::Util::TypeConstraints;
15
15
1616 use Scalar::Util 'looks_like_number';
17
17
1818 with 'MooseX::Getopt';
1919
2020 subtype 'ArrayOfInts'
2121 => as 'ArrayRef'
2222 => where { scalar (grep { looks_like_number($_) } @$_) };
23
23
2424 has 'nums' => (
2525 is => 'ro',
2626 isa => 'ArrayOfInts',
2727 default => sub { [0] }
28 );
29
28 );
29
3030 }
3131
3232 {
3434
3535 my $app = App->new_with_options;
3636 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');
3939 }
4040
4141 {
4343
4444 my $app = App->new_with_options;
4545 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');
4848 }
4949
1212 {
1313 package App;
1414 use Moose;
15
15
1616 with 'MooseX::Getopt';
1717
1818 has 'data' => (
19 traits => [ 'MooseX::Getopt::Meta::Attribute::Trait' ],
19 traits => [ 'MooseX::Getopt::Meta::Attribute::Trait' ],
2020 is => 'ro',
2121 isa => 'Str',
2222 default => 'file.dat',
2424 );
2525
2626 has 'cow' => (
27 traits => [ 'Getopt' ],
27 traits => [ 'Getopt' ],
2828 is => 'ro',
2929 isa => 'Str',
3030 default => 'moo',
3232 );
3333
3434 has 'horse' => (
35 traits => [ 'Getopt' ],
35 traits => [ 'Getopt' ],
3636 is => 'ro',
3737 isa => 'Str',
3838 default => 'bray',
4848
4949 has 'verbose' => (
5050 is => 'ro',
51 isa => 'Bool',
52 );
53
51 isa => 'Bool',
52 );
53
5454 has 'libs' => (
5555 is => 'ro',
5656 isa => 'ArrayRef',
5757 default => sub { [] },
58 );
59
58 );
59
6060 has 'details' => (
6161 is => 'ro',
6262 isa => 'HashRef',
7070 );
7171
7272 has '_private_stuff_cmdline' => (
73 traits => [ 'Getopt' ],
73 traits => [ 'Getopt' ],
7474 is => 'ro',
7575 isa => 'Int',
7676 default => 832,
7777 cmd_flag => 'p',
7878 );
79
79
8080 }
8181
8282 foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) {
8383 my $attr = App->meta->get_attribute($attr_name);
8484 isa_ok($attr, 'Moose::Meta::Attribute');
8585 does_ok($attr, 'MooseX::Getopt::Meta::Attribute::Trait');
86
86
8787 can_ok($attr, 'cmd_flag');
88 can_ok($attr, 'cmd_aliases');
88 can_ok($attr, 'cmd_aliases');
8989 }
9090
9191 {
9595 isa_ok($app, 'App');
9696
9797 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');
102102 }
103103
104104 {
108108 isa_ok($app, 'App');
109109
110110 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');
115115 }
116116
117117 {
121121 isa_ok($app, 'App');
122122
123123 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');
128128 }
129129
130130 {
134134 isa_ok($app, 'App');
135135
136136 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');
143143 }
144144
145145 {
149149 isa_ok($app, 'App');
150150
151151 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');
158158 }
159159
160160 {
165165 isa_ok($app, 'App');
166166
167167 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');
172172 }
173173
174174 # Test cmd_alias without cmd_flag
55 use Test::More;
66 use Test::Exception;
77
8 BEGIN {
8 BEGIN {
99 eval 'use Getopt::Long::Descriptive;';
1010 plan skip_all => "Getopt::Long::Descriptive required for this test" if $@;
1111 plan tests => 5;
1515 {
1616 package Testing::Foo;
1717 use Moose;
18
18
1919 with 'MooseX::Getopt';
20
20
2121 has 'bar' => (
2222 is => 'ro',
23 isa => 'Int',
23 isa => 'Int',
2424 required => 1,
2525 );
26
26
2727 has 'baz' => (
2828 is => 'ro',
29 isa => 'Int',
30 required => 1,
31 );
29 isa => 'Int',
30 required => 1,
31 );
3232 }
3333
3434 @ARGV = qw(--bar 10);
88 BEGIN {
99 eval 'use Getopt::Long::Descriptive;';
1010 plan skip_all => "Getopt::Long::Descriptive required for this test" if $@;
11 plan tests => 5;
11 plan tests => 5;
1212 use_ok('MooseX::Getopt');
1313 }
1414
1515 {
1616 package Engine::Foo;
1717 use Moose;
18
18
1919 with 'MooseX::Getopt';
20
20
2121 has 'nproc' => (
2222 metaclass => 'Getopt',
2323 is => 'ro',
1111 {
1212 package App;
1313 use Moose;
14
14
1515 with 'MooseX::Getopt::Basic';
1616
1717 has 'data' => (
18 metaclass => 'MooseX::Getopt::Meta::Attribute',
18 metaclass => 'MooseX::Getopt::Meta::Attribute',
1919 is => 'ro',
2020 isa => 'Str',
2121 default => 'file.dat',
2323 );
2424
2525 has 'cow' => (
26 metaclass => 'Getopt',
26 metaclass => 'Getopt',
2727 is => 'ro',
2828 isa => 'Str',
2929 default => 'moo',
3131 );
3232
3333 has 'horse' => (
34 metaclass => 'MooseX::Getopt::Meta::Attribute',
34 metaclass => 'MooseX::Getopt::Meta::Attribute',
3535 is => 'ro',
3636 isa => 'Str',
3737 default => 'bray',
4747
4848 has 'verbose' => (
4949 is => 'ro',
50 isa => 'Bool',
51 );
52
50 isa => 'Bool',
51 );
52
5353 has 'libs' => (
5454 is => 'ro',
5555 isa => 'ArrayRef',
5656 default => sub { [] },
57 );
58
57 );
58
5959 has 'details' => (
6060 is => 'ro',
6161 isa => 'HashRef',
6969 );
7070
7171 has '_private_stuff_cmdline' => (
72 metaclass => 'MooseX::Getopt::Meta::Attribute',
72 metaclass => 'MooseX::Getopt::Meta::Attribute',
7373 is => 'ro',
7474 isa => 'Int',
7575 default => 832,
7676 cmd_flag => 'p',
7777 );
78
78
7979 }
8080
8181 foreach my $attr_name (qw(data cow horse _private_stuff_cmdline)) {
8383 isa_ok($attr, 'Moose::Meta::Attribute');
8484 isa_ok($attr, 'MooseX::Getopt::Meta::Attribute');
8585 can_ok($attr, 'cmd_flag');
86 can_ok($attr, 'cmd_aliases');
86 can_ok($attr, 'cmd_aliases');
8787 }
8888
8989 {
9393 isa_ok($app, 'App');
9494
9595 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');
100100 }
101101
102102 {
106106 isa_ok($app, 'App');
107107
108108 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');
113113 }
114114
115115 {
119119 isa_ok($app, 'App');
120120
121121 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');
126126 }
127127
128128 {
132132 isa_ok($app, 'App');
133133
134134 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');
141141 }
142142
143143 {
147147 isa_ok($app, 'App');
148148
149149 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');
156156 }
157157
158158 {
163163 isa_ok($app, 'App');
164164
165165 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');
170170 }
171171
172172 # Test cmd_alias without cmd_flag
1616 $meta->add_attribute('BigD', traits => ['Getopt'], isa => 'Bool',
1717 cmd_aliases => ['D'], is => 'ro');
1818 $meta->add_attribute('SmallD', traits => ['Getopt'], isa => 'Bool',
19 cmd_aliases => ['d'], is => 'ro');
19 cmd_aliases => ['d'], is => 'ro');
2020 $role->meta->apply($meta);
2121
2222 {