Codebase list libgetopt-lucid-perl / 9e01a7d
Imported Upstream version 1.01 Fabrizio Regalli 12 years ago
14 changed file(s) with 130 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
00 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
17
28 1.00 2011-12-10 23:32:42 EST5EDT
39
0 This software is Copyright (c) 2011 by David Golden.
0 This software is Copyright (c) 2012 by David Golden.
11
22 This is free software, licensed under:
33
2525 t/10-default-validation.t
2626 t/ErrorMessages.pm
2727 xt/author/critic.t
28 xt/author/pod-spell.t
2829 xt/release/distmeta.t
2930 xt/release/pod-coverage.t
3031 xt/release/pod-syntax.t
33 "David Golden <dagolden@cpan.org>"
44 ],
55 "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",
77 "license" : [
88 "apache_2_0"
99 ],
3131 },
3232 "runtime" : {
3333 "requires" : {
34 "Carp" : 0,
34 "Carp" : "0",
3535 "Exception::Class" : "1.23",
36 "Exporter" : 0,
36 "Exporter" : "0",
3737 "Storable" : "2.16",
3838 "perl" : "5.006",
39 "strict" : 0,
40 "warnings" : 0
39 "strict" : "0",
40 "warnings" : "0"
4141 }
4242 },
4343 "test" : {
4444 "requires" : {
45 "Data::Dumper" : 0,
45 "Data::Dumper" : "0",
4646 "Exception::Class::TryCatch" : "1.10",
47 "File::Find" : 0,
48 "File::Temp" : 0,
47 "File::Find" : "0",
48 "File::Temp" : "0",
4949 "Test::More" : "0.62",
50 "vars" : 0
50 "vars" : "0"
5151 }
5252 }
5353 },
5454 "provides" : {
5555 "Getopt::Lucid" : {
5656 "file" : "lib/Getopt/Lucid.pm",
57 "version" : "1.00"
57 "version" : "1.01"
5858 },
5959 "Getopt::Lucid::Exception" : {
6060 "file" : "lib/Getopt/Lucid/Exception.pm",
61 "version" : "1.00"
61 "version" : "1.01"
6262 },
6363 "Getopt::Lucid::Spec" : {
6464 "file" : "lib/Getopt/Lucid.pm",
65 "version" : "1.00"
65 "version" : "1.01"
6666 }
6767 },
6868 "release_status" : "stable",
7878 "web" : "https://github.com/dagolden/getopt-lucid"
7979 }
8080 },
81 "version" : "1.00"
81 "version" : "1.01"
8282 }
8383
1111 configure_requires:
1212 ExtUtils::MakeMaker: 6.30
1313 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'
1515 license: apache
1616 meta-spec:
1717 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2828 provides:
2929 Getopt::Lucid:
3030 file: lib/Getopt/Lucid.pm
31 version: 1.00
31 version: 1.01
3232 Getopt::Lucid::Exception:
3333 file: lib/Getopt/Lucid/Exception.pm
34 version: 1.00
34 version: 1.01
3535 Getopt::Lucid::Spec:
3636 file: lib/Getopt/Lucid.pm
37 version: 1.00
37 version: 1.01
3838 requires:
3939 Carp: 0
4040 Exception::Class: 1.23
4747 bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Lucid
4848 homepage: https://github.com/dagolden/getopt-lucid
4949 repository: https://github.com/dagolden/getopt-lucid.git
50 version: 1.00
50 version: 1.01
3333 "strict" => 0,
3434 "warnings" => 0
3535 },
36 "VERSION" => "1.00",
36 "VERSION" => "1.01",
3737 "test" => {
3838 "TESTS" => "t/*.t"
3939 }
11 Getopt::Lucid - Clear, readable syntax for command line processing
22
33 VERSION
4 version 1.00
4 version 1.01
55
66 SYNOPSIS
77 use Getopt::Lucid qw( :all );
5454 plain-English option specification as compared against the more symbolic
5555 approach of Getopt::Long. Key features include:
5656
57 * Five option types: switches, counters, parameters, lists, and
58 keypairs
57 * Five option types: switches, counters, parameters, lists, and key
58 pairs
5959
6060 * Three option styles: long, short (including bundled), and bare
6161 (without dashes)
233233 Validation
234234 Validation happens in two stages. First, individual parameters may have
235235 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.
237237
238238 Parameter validation
239239 The Param, List, and Keypair option types may be provided an optional
251251 "merge_defaults", or "replace_defaults". This ensures internal
252252 consistency.
253253
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
255255 option appears on the command line. (In other words, the built-in
256256 defaults are always considered valid if the option does not appear.) If
257257 this is not desired, the "required" option to the "validate" method
335335 As with all options, negation is processed in order, allowing a "reset"
336336 in the middle of command line processing. This may be useful for those
337337 using command aliases who wish to "switch off" options in the alias.
338 E.g, in unix:
338 E.g, in Unix:
339339
340340 $ alias wibble = wibble.pl --verbose
341341 $ wibble --no-verbose
361361 print $opt->get_test ? "True" : "False";
362362 $opt->set_test(1);
363363
364 For option names with dashes, underscores should be substitued in the
364 For option names with dashes, underscores should be substituted in the
365365 accessor calls. E.g.
366366
367367 @spec = (
467467 }
468468
469469 Ambiguous Cases and Gotchas
470 One-character aliases and anycase
470 One-character aliases and "anycase"
471471 @spec = (
472472 Counter("verbose|v")->anycase,
473473 Switch("version|V")->anycase,
537537 with the revised defaults, and returns a hash with the resulting
538538 options. Each key/value pair in the passed hash is added to the stored
539539 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,
542542 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.
547547
548548 defaults()
549549 %defaults = $opt->defaults();
574574 stored defaults, recalculates the result of processing the command line
575575 with the revised defaults, and returns a hash with the resulting
576576 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
578578 names from the options specification will be ignored.
579579
580580 names()
660660 David Golden <dagolden@cpan.org>
661661
662662 COPYRIGHT AND LICENSE
663 This software is Copyright (c) 2011 by David Golden.
663 This software is Copyright (c) 2012 by David Golden.
664664
665665 This is free software, licensed under:
666666
33 copyright_holder = David Golden
44
55 [@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
713
8 [Test::Perl::Critic]
9
22 use warnings;
33 package Getopt::Lucid::Exception;
44 # ABSTRACT: Exception classes for Getopt::Lucid
5 our $VERSION = '1.00'; # VERSION
5 our $VERSION = '1.01'; # VERSION
66
77 use Exception::Class 1.23 (
88 "Getopt::Lucid::Exception" => {
4747
4848 =head1 VERSION
4949
50 version 1.00
50 version 1.01
5151
5252 =head1 AUTHOR
5353
5555
5656 =head1 COPYRIGHT AND LICENSE
5757
58 This software is Copyright (c) 2011 by David Golden.
58 This software is Copyright (c) 2012 by David Golden.
5959
6060 This is free software, licensed under:
6161
22 use warnings;
33 package Getopt::Lucid;
44 # ABSTRACT: Clear, readable syntax for command line processing
5 our $VERSION = '1.00'; # VERSION
5 our $VERSION = '1.01'; # VERSION
66
77 our @EXPORT_OK = qw(Switch Counter Param List Keypair);
88 our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
225225
226226 sub validate {
227227 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 }
234239 }
240
235241 _check_prereqs($self);
236242
237243 return $self;
772778
773779 =head1 VERSION
774780
775 version 1.00
781 version 1.01
776782
777783 =head1 SYNOPSIS
778784
831837
832838 =item *
833839
834 Five option types: switches, counters, parameters, lists, and keypairs
840 Five option types: switches, counters, parameters, lists, and key pairs
835841
836842 =item *
837843
870876 Getopt::Lucid support three kinds of option styles: long-style ("--foo"),
871877 short-style ("-f") and bareword style ("foo"). Short-style options
872878 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 >>> ).
874880
875881 Each option is identified in the specification with a string consisting of the
876882 option "name" followed by zero or more "aliases", with any alias (and each
10451051
10461052 Validation happens in two stages. First, individual parameters may have
10471053 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.
10491055
10501056 =head3 Parameter validation
10511057
10631069 modifier or later modified with C<<< append_defaults >>>, C<<< merge_defaults >>>, or
10641070 C<<< replace_defaults >>>. This ensures internal consistency.
10651071
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
10671073 appears on the command line. (In other words, the built-in defaults are always
10681074 considered valid if the option does not appear.) If this is not desired, the
10691075 C<<< required >>> option to the C<<< validate >>> method should be used to force users to
11461152
11471153 As with all options, negation is processed in order, allowing a "reset" in
11481154 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:
11501156
11511157 $ alias wibble = wibble.pl --verbose
11521158 $ wibble --no-verbose
11731179 print $opt->get_test ? "True" : "False";
11741180 $opt->set_test(1);
11751181
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
11771183 calls. E.g.
11781184
11791185 @spec = (
13151321
13161322 =head2 Ambiguous Cases and Gotchas
13171323
1318 =head3 One-character aliases and anycase
1324 =head3 One-character aliases and C<<< anycase >>>
13191325
13201326 @spec = (
13211327 Counter("verbose|v")->anycase,
14001406 revised defaults, and returns a hash with the resulting options. Each
14011407 keyE<sol>value pair in the passed hash is added to the stored defaults. For Switch
14021408 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
14051411 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,
14071413 overwriting existing keyE<sol>value pairs (just like merging two hashes). Keys
14081414 which are not valid names from the options specification will be ignored.
14091415
14371443 defaults, recalculates the result of processing the command line with the
14381444 revised defaults, and returns a hash with the resulting options. Each
14391445 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
14411447 specification will be ignored.
14421448
14431449 =head2 names()
15591565
15601566 =head1 COPYRIGHT AND LICENSE
15611567
1562 This software is Copyright (c) 2011 by David Golden.
1568 This software is Copyright (c) 2012 by David Golden.
15631569
15641570 This is free software, licensed under:
15651571
2323 'lib',
2424 );
2525
26 my @scripts;
27 if ( -d 'bin' ) {
26 sub _find_scripts {
27 my $dir = shift @_;
28
29 my @found_scripts = ();
2830 find(
2931 sub {
3032 return unless -f;
3133 my $found = $File::Find::name;
3234 # 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;
3442 },
35 'bin',
43 $dir,
3644 );
45
46 return @found_scripts;
3747 }
48
49 my @scripts;
50 do { push @scripts, _find_scripts($_) if -d $_ }
51 for qw{ bin script scripts };
3852
3953 my $plan = scalar(@modules) + scalar(@scripts);
4054 $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
11
22 use Test::More;
33
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 $@;
77 run_tests();
33 use warnings;
44 use Test::More;
55
6 eval "use Test::Version 0.04";
7 plan skip_all => "Test::Version 0.04 required for testing versions"
8 if $@;
6 use Test::Requires {
7 'Test::Version' => 0.04,
8 };
99
10 version_all_ok();
10 version_all_ok;
1111 done_testing;