Imported Upstream version 1.01
Fabrizio Regalli
12 years ago
0 | 0 | Revision history for Perl module Getopt::Lucid |
1 | ||
2 | 1.01 2012-02-23 18:07:19 EST5EDT | |
3 | ||
4 | - fixed validation() to make hashref argument actually optional like | |
5 | the documentation says it is [rt.cpan.org #74269] | |
6 | - fixed typos in Pod | |
1 | 7 | |
2 | 8 | 1.00 2011-12-10 23:32:42 EST5EDT |
3 | 9 |
0 | This software is Copyright (c) 2011 by David Golden. | |
0 | This software is Copyright (c) 2012 by David Golden. | |
1 | 1 | |
2 | 2 | This is free software, licensed under: |
3 | 3 |
25 | 25 | t/10-default-validation.t |
26 | 26 | t/ErrorMessages.pm |
27 | 27 | xt/author/critic.t |
28 | xt/author/pod-spell.t | |
28 | 29 | xt/release/distmeta.t |
29 | 30 | xt/release/pod-coverage.t |
30 | 31 | xt/release/pod-syntax.t |
3 | 3 | "David Golden <dagolden@cpan.org>" |
4 | 4 | ], |
5 | 5 | "dynamic_config" : 0, |
6 | "generated_by" : "Dist::Zilla version 4.300003, CPAN::Meta::Converter version 2.112580", | |
6 | "generated_by" : "Dist::Zilla version 4.300009, CPAN::Meta::Converter version 2.120351", | |
7 | 7 | "license" : [ |
8 | 8 | "apache_2_0" |
9 | 9 | ], |
31 | 31 | }, |
32 | 32 | "runtime" : { |
33 | 33 | "requires" : { |
34 | "Carp" : 0, | |
34 | "Carp" : "0", | |
35 | 35 | "Exception::Class" : "1.23", |
36 | "Exporter" : 0, | |
36 | "Exporter" : "0", | |
37 | 37 | "Storable" : "2.16", |
38 | 38 | "perl" : "5.006", |
39 | "strict" : 0, | |
40 | "warnings" : 0 | |
39 | "strict" : "0", | |
40 | "warnings" : "0" | |
41 | 41 | } |
42 | 42 | }, |
43 | 43 | "test" : { |
44 | 44 | "requires" : { |
45 | "Data::Dumper" : 0, | |
45 | "Data::Dumper" : "0", | |
46 | 46 | "Exception::Class::TryCatch" : "1.10", |
47 | "File::Find" : 0, | |
48 | "File::Temp" : 0, | |
47 | "File::Find" : "0", | |
48 | "File::Temp" : "0", | |
49 | 49 | "Test::More" : "0.62", |
50 | "vars" : 0 | |
50 | "vars" : "0" | |
51 | 51 | } |
52 | 52 | } |
53 | 53 | }, |
54 | 54 | "provides" : { |
55 | 55 | "Getopt::Lucid" : { |
56 | 56 | "file" : "lib/Getopt/Lucid.pm", |
57 | "version" : "1.00" | |
57 | "version" : "1.01" | |
58 | 58 | }, |
59 | 59 | "Getopt::Lucid::Exception" : { |
60 | 60 | "file" : "lib/Getopt/Lucid/Exception.pm", |
61 | "version" : "1.00" | |
61 | "version" : "1.01" | |
62 | 62 | }, |
63 | 63 | "Getopt::Lucid::Spec" : { |
64 | 64 | "file" : "lib/Getopt/Lucid.pm", |
65 | "version" : "1.00" | |
65 | "version" : "1.01" | |
66 | 66 | } |
67 | 67 | }, |
68 | 68 | "release_status" : "stable", |
78 | 78 | "web" : "https://github.com/dagolden/getopt-lucid" |
79 | 79 | } |
80 | 80 | }, |
81 | "version" : "1.00" | |
81 | "version" : "1.01" | |
82 | 82 | } |
83 | 83 |
11 | 11 | configure_requires: |
12 | 12 | ExtUtils::MakeMaker: 6.30 |
13 | 13 | dynamic_config: 0 |
14 | generated_by: 'Dist::Zilla version 4.300003, CPAN::Meta::Converter version 2.112580' | |
14 | generated_by: 'Dist::Zilla version 4.300009, CPAN::Meta::Converter version 2.120351' | |
15 | 15 | license: apache |
16 | 16 | meta-spec: |
17 | 17 | url: http://module-build.sourceforge.net/META-spec-v1.4.html |
28 | 28 | provides: |
29 | 29 | Getopt::Lucid: |
30 | 30 | file: lib/Getopt/Lucid.pm |
31 | version: 1.00 | |
31 | version: 1.01 | |
32 | 32 | Getopt::Lucid::Exception: |
33 | 33 | file: lib/Getopt/Lucid/Exception.pm |
34 | version: 1.00 | |
34 | version: 1.01 | |
35 | 35 | Getopt::Lucid::Spec: |
36 | 36 | file: lib/Getopt/Lucid.pm |
37 | version: 1.00 | |
37 | version: 1.01 | |
38 | 38 | requires: |
39 | 39 | Carp: 0 |
40 | 40 | Exception::Class: 1.23 |
47 | 47 | bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Lucid |
48 | 48 | homepage: https://github.com/dagolden/getopt-lucid |
49 | 49 | repository: https://github.com/dagolden/getopt-lucid.git |
50 | version: 1.00 | |
50 | version: 1.01 |
33 | 33 | "strict" => 0, |
34 | 34 | "warnings" => 0 |
35 | 35 | }, |
36 | "VERSION" => "1.00", | |
36 | "VERSION" => "1.01", | |
37 | 37 | "test" => { |
38 | 38 | "TESTS" => "t/*.t" |
39 | 39 | } |
1 | 1 | Getopt::Lucid - Clear, readable syntax for command line processing |
2 | 2 | |
3 | 3 | VERSION |
4 | version 1.00 | |
4 | version 1.01 | |
5 | 5 | |
6 | 6 | SYNOPSIS |
7 | 7 | use Getopt::Lucid qw( :all ); |
54 | 54 | plain-English option specification as compared against the more symbolic |
55 | 55 | approach of Getopt::Long. Key features include: |
56 | 56 | |
57 | * Five option types: switches, counters, parameters, lists, and | |
58 | keypairs | |
57 | * Five option types: switches, counters, parameters, lists, and key | |
58 | pairs | |
59 | 59 | |
60 | 60 | * Three option styles: long, short (including bundled), and bare |
61 | 61 | (without dashes) |
233 | 233 | Validation |
234 | 234 | Validation happens in two stages. First, individual parameters may have |
235 | 235 | validation criteria added to them. Second, the parsed options object may |
236 | be validated by checking that all requirements or prerequires are met. | |
236 | be validated by checking that all requirements collectively are met. | |
237 | 237 | |
238 | 238 | Parameter validation |
239 | 239 | The Param, List, and Keypair option types may be provided an optional |
251 | 251 | "merge_defaults", or "replace_defaults". This ensures internal |
252 | 252 | consistency. |
253 | 253 | |
254 | If no default is explictly provided, validation is only applied if the | |
254 | If no default is explicitly provided, validation is only applied if the | |
255 | 255 | option appears on the command line. (In other words, the built-in |
256 | 256 | defaults are always considered valid if the option does not appear.) If |
257 | 257 | this is not desired, the "required" option to the "validate" method |
335 | 335 | As with all options, negation is processed in order, allowing a "reset" |
336 | 336 | in the middle of command line processing. This may be useful for those |
337 | 337 | using command aliases who wish to "switch off" options in the alias. |
338 | E.g, in unix: | |
338 | E.g, in Unix: | |
339 | 339 | |
340 | 340 | $ alias wibble = wibble.pl --verbose |
341 | 341 | $ wibble --no-verbose |
361 | 361 | print $opt->get_test ? "True" : "False"; |
362 | 362 | $opt->set_test(1); |
363 | 363 | |
364 | For option names with dashes, underscores should be substitued in the | |
364 | For option names with dashes, underscores should be substituted in the | |
365 | 365 | accessor calls. E.g. |
366 | 366 | |
367 | 367 | @spec = ( |
467 | 467 | } |
468 | 468 | |
469 | 469 | Ambiguous Cases and Gotchas |
470 | One-character aliases and anycase | |
470 | One-character aliases and "anycase" | |
471 | 471 | @spec = ( |
472 | 472 | Counter("verbose|v")->anycase, |
473 | 473 | Switch("version|V")->anycase, |
537 | 537 | with the revised defaults, and returns a hash with the resulting |
538 | 538 | options. Each key/value pair in the passed hash is added to the stored |
539 | 539 | defaults. For Switch and Param options, the value in the passed hash |
540 | will overwrite any pre-existing value. For Counter options, the value is | |
541 | added to any pre-existing value. For List options, the value (or values, | |
540 | will overwrite any preexisting value. For Counter options, the value is | |
541 | added to any preexisting value. For List options, the value (or values, | |
542 | 542 | if the value is an array reference) will be pushed onto the end of the |
543 | list of existing values. For Keypair options, the keypairs will be added | |
544 | to the existing hash, overwriting existing key/value pairs (just like | |
545 | merging two hashes). Keys which are not valid names from the options | |
546 | specification will be ignored. | |
543 | list of existing values. For Keypair options, the key/value pairs will | |
544 | be added to the existing hash, overwriting existing key/value pairs | |
545 | (just like merging two hashes). Keys which are not valid names from the | |
546 | options specification will be ignored. | |
547 | 547 | |
548 | 548 | defaults() |
549 | 549 | %defaults = $opt->defaults(); |
574 | 574 | stored defaults, recalculates the result of processing the command line |
575 | 575 | with the revised defaults, and returns a hash with the resulting |
576 | 576 | options. Each key/value pair in the passed hash is added to the stored |
577 | defaults, overwriting any pre-existing value. Keys which are not valid | |
577 | defaults, overwriting any preexisting value. Keys which are not valid | |
578 | 578 | names from the options specification will be ignored. |
579 | 579 | |
580 | 580 | names() |
660 | 660 | David Golden <dagolden@cpan.org> |
661 | 661 | |
662 | 662 | COPYRIGHT AND LICENSE |
663 | This software is Copyright (c) 2011 by David Golden. | |
663 | This software is Copyright (c) 2012 by David Golden. | |
664 | 664 | |
665 | 665 | This is free software, licensed under: |
666 | 666 |
3 | 3 | copyright_holder = David Golden |
4 | 4 | |
5 | 5 | [@DAGOLDEN] |
6 | :version = 0.018 | |
6 | :version = 0.022 | |
7 | stopwords = KeyPair | |
8 | stopwords = KeyPairs | |
9 | stopwords = Keypair | |
10 | stopwords = Keypairs | |
11 | stopwords = Multi | |
12 | stopwords = Param | |
7 | 13 | |
8 | [Test::Perl::Critic] | |
9 |
2 | 2 | use warnings; |
3 | 3 | package Getopt::Lucid::Exception; |
4 | 4 | # ABSTRACT: Exception classes for Getopt::Lucid |
5 | our $VERSION = '1.00'; # VERSION | |
5 | our $VERSION = '1.01'; # VERSION | |
6 | 6 | |
7 | 7 | use Exception::Class 1.23 ( |
8 | 8 | "Getopt::Lucid::Exception" => { |
47 | 47 | |
48 | 48 | =head1 VERSION |
49 | 49 | |
50 | version 1.00 | |
50 | version 1.01 | |
51 | 51 | |
52 | 52 | =head1 AUTHOR |
53 | 53 | |
55 | 55 | |
56 | 56 | =head1 COPYRIGHT AND LICENSE |
57 | 57 | |
58 | This software is Copyright (c) 2011 by David Golden. | |
58 | This software is Copyright (c) 2012 by David Golden. | |
59 | 59 | |
60 | 60 | This is free software, licensed under: |
61 | 61 |
2 | 2 | use warnings; |
3 | 3 | package Getopt::Lucid; |
4 | 4 | # ABSTRACT: Clear, readable syntax for command line processing |
5 | our $VERSION = '1.00'; # VERSION | |
5 | our $VERSION = '1.01'; # VERSION | |
6 | 6 | |
7 | 7 | our @EXPORT_OK = qw(Switch Counter Param List Keypair); |
8 | 8 | our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); |
225 | 225 | |
226 | 226 | sub validate { |
227 | 227 | my ($self, $arg) = @_; |
228 | throw_usage("Getopt::Lucid->validate() takes an optional hashref argument") | |
229 | unless $arg && ref($arg) eq 'HASH'; | |
230 | ||
231 | for my $p ( @{$arg->{requires}} ) { | |
232 | throw_argv("Required option '$self->{spec}{$p}{canon}' not found") | |
233 | if ( ! $self->{seen}{$p} ); | |
228 | throw_usage("Getopt::Lucid->validate() takes a hashref argument") | |
229 | if $arg && ref($arg) ne 'HASH'; | |
230 | ||
231 | if ( $arg && exists $arg->{requires} ) { | |
232 | my $requires = $arg->{requires}; | |
233 | throw_usage("'validate' argument 'requires' must be an array reference") | |
234 | if $requires && ref($requires) ne 'ARRAY'; | |
235 | for my $p ( @$requires ) { | |
236 | throw_argv("Required option '$self->{spec}{$p}{canon}' not found") | |
237 | if ( ! $self->{seen}{$p} ); | |
238 | } | |
234 | 239 | } |
240 | ||
235 | 241 | _check_prereqs($self); |
236 | 242 | |
237 | 243 | return $self; |
772 | 778 | |
773 | 779 | =head1 VERSION |
774 | 780 | |
775 | version 1.00 | |
781 | version 1.01 | |
776 | 782 | |
777 | 783 | =head1 SYNOPSIS |
778 | 784 | |
831 | 837 | |
832 | 838 | =item * |
833 | 839 | |
834 | Five option types: switches, counters, parameters, lists, and keypairs | |
840 | Five option types: switches, counters, parameters, lists, and key pairs | |
835 | 841 | |
836 | 842 | =item * |
837 | 843 | |
870 | 876 | Getopt::Lucid support three kinds of option styles: long-style ("--foo"), |
871 | 877 | short-style ("-f") and bareword style ("foo"). Short-style options |
872 | 878 | are automatically unbundled during command line processing if a single dash |
873 | is followed by more than one letter (e.g. "-xzf" becomes "-x -z -f" ). | |
879 | is followed by more than one letter (e.g. C<<< -xzf >>> becomes C<<< -x -z -f >>> ). | |
874 | 880 | |
875 | 881 | Each option is identified in the specification with a string consisting of the |
876 | 882 | option "name" followed by zero or more "aliases", with any alias (and each |
1045 | 1051 | |
1046 | 1052 | Validation happens in two stages. First, individual parameters may have |
1047 | 1053 | validation criteria added to them. Second, the parsed options object may be |
1048 | validated by checking that all requirements or prerequires are met. | |
1054 | validated by checking that all requirements collectively are met. | |
1049 | 1055 | |
1050 | 1056 | =head3 Parameter validation |
1051 | 1057 | |
1063 | 1069 | modifier or later modified with C<<< append_defaults >>>, C<<< merge_defaults >>>, or |
1064 | 1070 | C<<< replace_defaults >>>. This ensures internal consistency. |
1065 | 1071 | |
1066 | If no default is explictly provided, validation is only applied if the option | |
1072 | If no default is explicitly provided, validation is only applied if the option | |
1067 | 1073 | appears on the command line. (In other words, the built-in defaults are always |
1068 | 1074 | considered valid if the option does not appear.) If this is not desired, the |
1069 | 1075 | C<<< required >>> option to the C<<< validate >>> method should be used to force users to |
1146 | 1152 | |
1147 | 1153 | As with all options, negation is processed in order, allowing a "reset" in |
1148 | 1154 | the middle of command line processing. This may be useful for those using |
1149 | command aliases who wish to "switch off" options in the alias. E.g, in unix: | |
1155 | command aliases who wish to "switch off" options in the alias. E.g, in Unix: | |
1150 | 1156 | |
1151 | 1157 | $ alias wibble = wibble.pl --verbose |
1152 | 1158 | $ wibble --no-verbose |
1173 | 1179 | print $opt->get_test ? "True" : "False"; |
1174 | 1180 | $opt->set_test(1); |
1175 | 1181 | |
1176 | For option names with dashes, underscores should be substitued in the accessor | |
1182 | For option names with dashes, underscores should be substituted in the accessor | |
1177 | 1183 | calls. E.g. |
1178 | 1184 | |
1179 | 1185 | @spec = ( |
1315 | 1321 | |
1316 | 1322 | =head2 Ambiguous Cases and Gotchas |
1317 | 1323 | |
1318 | =head3 One-character aliases and anycase | |
1324 | =head3 One-character aliases and C<<< anycase >>> | |
1319 | 1325 | |
1320 | 1326 | @spec = ( |
1321 | 1327 | Counter("verbose|v")->anycase, |
1400 | 1406 | revised defaults, and returns a hash with the resulting options. Each |
1401 | 1407 | keyE<sol>value pair in the passed hash is added to the stored defaults. For Switch |
1402 | 1408 | and Param options, the value in the passed hash will overwrite any |
1403 | pre-existing value. For Counter options, the value is added to any | |
1404 | pre-existing value. For List options, the value (or values, if the value is an | |
1409 | preexisting value. For Counter options, the value is added to any | |
1410 | preexisting value. For List options, the value (or values, if the value is an | |
1405 | 1411 | array reference) will be pushed onto the end of the list of existing values. |
1406 | For Keypair options, the keypairs will be added to the existing hash, | |
1412 | For Keypair options, the keyE<sol>value pairs will be added to the existing hash, | |
1407 | 1413 | overwriting existing keyE<sol>value pairs (just like merging two hashes). Keys |
1408 | 1414 | which are not valid names from the options specification will be ignored. |
1409 | 1415 | |
1437 | 1443 | defaults, recalculates the result of processing the command line with the |
1438 | 1444 | revised defaults, and returns a hash with the resulting options. Each |
1439 | 1445 | keyE<sol>value pair in the passed hash is added to the stored defaults, overwriting |
1440 | any pre-existing value. Keys which are not valid names from the options | |
1446 | any preexisting value. Keys which are not valid names from the options | |
1441 | 1447 | specification will be ignored. |
1442 | 1448 | |
1443 | 1449 | =head2 names() |
1559 | 1565 | |
1560 | 1566 | =head1 COPYRIGHT AND LICENSE |
1561 | 1567 | |
1562 | This software is Copyright (c) 2011 by David Golden. | |
1568 | This software is Copyright (c) 2012 by David Golden. | |
1563 | 1569 | |
1564 | 1570 | This is free software, licensed under: |
1565 | 1571 |
23 | 23 | 'lib', |
24 | 24 | ); |
25 | 25 | |
26 | my @scripts; | |
27 | if ( -d 'bin' ) { | |
26 | sub _find_scripts { | |
27 | my $dir = shift @_; | |
28 | ||
29 | my @found_scripts = (); | |
28 | 30 | find( |
29 | 31 | sub { |
30 | 32 | return unless -f; |
31 | 33 | my $found = $File::Find::name; |
32 | 34 | # nothing to skip |
33 | push @scripts, $found; | |
35 | open my $FH, '<', $_ or do { | |
36 | note( "Unable to open $found in ( $! ), skipping" ); | |
37 | return; | |
38 | }; | |
39 | my $shebang = <$FH>; | |
40 | return unless $shebang =~ /^#!.*?\bperl\b\s*$/; | |
41 | push @found_scripts, $found; | |
34 | 42 | }, |
35 | 'bin', | |
43 | $dir, | |
36 | 44 | ); |
45 | ||
46 | return @found_scripts; | |
37 | 47 | } |
48 | ||
49 | my @scripts; | |
50 | do { push @scripts, _find_scripts($_) if -d $_ } | |
51 | for qw{ bin script scripts }; | |
38 | 52 | |
39 | 53 | my $plan = scalar(@modules) + scalar(@scripts); |
40 | 54 | $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run"); |
0 | #!perl | |
1 | # This test is generated by Dist::Zilla::Plugin::Test::PodSpelling | |
2 | ||
3 | use Test::More; | |
4 | ||
5 | eval "use Pod::Wordlist::hanekomu"; | |
6 | plan skip_all => "Pod::Wordlist::hanekomu required for testing POD spelling" | |
7 | if $@; | |
8 | ||
9 | eval "use Test::Spelling 0.12"; | |
10 | plan skip_all => "Test::Spelling 0.12 required for testing POD spelling" | |
11 | if $@; | |
12 | ||
13 | ||
14 | add_stopwords(<DATA>); | |
15 | all_pod_files_spelling_ok('bin', 'lib'); | |
16 | __DATA__ | |
17 | KeyPair | |
18 | KeyPairs | |
19 | Keypair | |
20 | Keypairs | |
21 | Multi | |
22 | Param | |
23 | David | |
24 | Golden | |
25 |
1 | 1 | |
2 | 2 | use Test::More; |
3 | 3 | |
4 | eval "use Test::Portability::Files"; | |
5 | plan skip_all => "Test::Portability::Files required for testing portability" | |
6 | if $@; | |
4 | eval 'use Test::Portability::Files'; | |
5 | plan skip_all => 'Test::Portability::Files required for testing portability' | |
6 | if $@; | |
7 | 7 | run_tests(); |