-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r31981@knight: rjbs | 2007-07-04 22:19:04 -0400
release
- Loading branch information
0 parents
commit ceaebfa
Showing
11 changed files
with
1,043 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Revision history for Sub-Exporter | ||
|
||
0.102 2006-07-04 | ||
improved documentation | ||
tweaked some Perl::Critic-offending code | ||
|
||
0.100 2006-06-05 | ||
broken out of Sub-Exporter into its own dist | ||
renamed routines to be easier to type | ||
|
||
0.040 2006-05-11 (in Sub-Exporter) | ||
tweaks to Data::OptList, moving toward its own dist: now it exports | ||
expand_opt_list is now opt_list_as_hash | ||
|
||
0.??? 2006-05-10 (in Sub-Exporter) | ||
require Params::Util for craftier opt list validation | ||
|
||
0.??? 2006-04-26 (in Sub-Exporter) | ||
broken out of Sub::Exporter module | ||
remove an "optimization" that broke expand_opt_list |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
inc/Module/Install.pm | ||
inc/Module/Install/Base.pm | ||
inc/Module/Install/Can.pm | ||
inc/Module/Install/Fetch.pm | ||
inc/Module/Install/Makefile.pm | ||
inc/Module/Install/Metadata.pm | ||
inc/Module/Install/Win32.pm | ||
inc/Module/Install/WriteAll.pm | ||
lib/Data/OptList.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
META.yml | ||
t/mkopt.t | ||
t/hash.t | ||
t/pod.t | ||
t/pod-coverage.t | ||
README | ||
Changes | ||
t/perl-critic.t | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use inc::Module::Install; | ||
|
||
name ('Data-OptList'); | ||
author ('Ricardo SIGNES <rjbs@cpan.org>'); | ||
license ('perl'); | ||
version_from ('lib/Data/OptList.pm'); | ||
|
||
requires('Sub::Install' => 0.92); # exporter, needed by Data::OptList | ||
requires('List::Util' => 0.00); # unknown minimum; used for "first" | ||
requires('Params::Util' => 0.14); # _HASHLIKE, _ARRAYLIKE, _CODELIKE | ||
|
||
WriteAll(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
NAME | ||
Data::OptList - parse and validate simple name/value option pairs | ||
|
||
VERSION | ||
version 0.102 | ||
|
||
$Id: /my/cs/projects/Data-OptList/trunk/lib/Data/OptList.pm 31979 2007-07-05T02:17:36.805594Z rjbs $ | ||
|
||
SYNOPSIS | ||
use Data::OptList; | ||
|
||
my $options = Data::Optlist::mkopt([ | ||
qw(key1 key2 key3 key4), | ||
key5 => { ... }, | ||
key6 => [ ... ], | ||
key7 => sub { ... }, | ||
key8 => { ... }, | ||
key8 => [ ... ], | ||
]); | ||
|
||
...is the same thing, more or less, as: | ||
|
||
my $options = [ | ||
[ key1 => undef, ], | ||
[ key2 => undef, ], | ||
[ key3 => undef, ], | ||
[ key4 => undef, ], | ||
[ key5 => { ... }, ], | ||
[ key6 => [ ... ], ], | ||
[ key7 => sub { ... }, ], | ||
[ key8 => { ... }, ], | ||
[ key8 => [ ... ], ], | ||
]); | ||
|
||
DESCRIPTION | ||
Hashes are great for storing named data, but if you want more than one | ||
entry for a name, you have to use a list of pairs. Even then, this is | ||
really boring to write: | ||
|
||
$values = [ | ||
foo => undef, | ||
bar => undef, | ||
baz => undef, | ||
xyz => { ... }, | ||
]; | ||
|
||
Just look at all those undefs! Don't worry, we can get rid of those: | ||
|
||
$values = [ | ||
map { $_ => undef } qw(foo bar baz), | ||
xyz => { ... }, | ||
]; | ||
|
||
Aaaauuugh! We've saved a little typing, but now it requires thought to | ||
read, and thinking is even worse than typing. | ||
|
||
With Data::OptList, you can do this instead: | ||
|
||
$values = Data::OptList::mkopt([ | ||
qw(foo bar baz), | ||
xyz => { ... }, | ||
]); | ||
|
||
This works by assuming that any defined scalar is a name and any | ||
reference following a name is its value. | ||
|
||
FUNCTIONS | ||
mkopt | ||
my $opt_list = Data::OptList::mkopt( | ||
$input, | ||
$moniker, | ||
$require_unique, | ||
$must_be, | ||
); | ||
|
||
This produces an array of arrays; the inner arrays are name/value pairs. | ||
Values will be either "undef" or a reference. | ||
|
||
Valid values for $input: | ||
|
||
undef -> [] | ||
hashref -> [ [ key1 => value1 ] ... ] # non-ref values become undef | ||
arrayref -> every value followed by a ref becomes a pair: [ value => ref ] | ||
every value followed by undef becomes a pair: [ value => undef ] | ||
otherwise, it becomes [ value => undef ] like so: | ||
[ "a", "b", [ 1, 2 ] ] -> [ [ a => undef ], [ b => [ 1, 2 ] ] ] | ||
|
||
$moniker is a name describing the data, which will be used in error | ||
messages. | ||
|
||
If $require_unique is true, an error will be thrown if any name is given | ||
more than once. | ||
|
||
$must_be is either a scalar or array of scalars; it defines what kind(s) | ||
of refs may be values. If an invalid value is found, an exception is | ||
thrown. If no value is passed for this argument, any reference is valid. | ||
If $must_be specifies that values must be CODE, HASH, ARRAY, or SCALAR, | ||
then Params::Util is used to check whether the given value can provide | ||
that interface. Otherwise, it checks that the given value is an object | ||
of the kind. | ||
|
||
In other words: | ||
|
||
[ qw(SCALAR HASH Object::Known) ] | ||
|
||
Means: | ||
|
||
_SCALAR0($value) or _HASH($value) or _INSTANCE($value, 'Object::Known') | ||
|
||
mkopt_hash | ||
my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be); | ||
|
||
Given valid "mkopt" input, this routine returns a reference to a hash. | ||
It will throw an exception if any name has more than one value. | ||
|
||
EXPORTS | ||
Both "mkopt" and "mkopt_hash" may be exported on request. | ||
|
||
AUTHOR | ||
Ricardo SIGNES, "<rjbs@cpan.org>" | ||
|
||
BUGS | ||
Please report any bugs or feature requests at <http://rt.cpan.org>. I | ||
will be notified, and then you'll automatically be notified of progress | ||
on your bug as I make changes. | ||
|
||
COPYRIGHT | ||
Copyright 2006-2007, Ricardo SIGNES. This program is free software; you | ||
can redistribute it and/or modify it under the same terms as Perl | ||
itself. | ||
|
Oops, something went wrong.