Codex

Data::OptList

Section: User Contributed Perl Documentation (3pm)

Updated: 2013-12-13

Index?action=index Return to Main Contents


NAME

Data::OptList - parse and validate simple name/value option pairs

VERSION

version 0.109

SYNOPSIS

...is the same thing, more or less, as:

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:

Just look at all those undefs! Don't worry, we can get rid of those:

Aaaauuugh! We've saved a little typing, but now it requires thought to read, and thinking is even worse than typing... and it's got a bug! It looked right, didn't it? Well, the gets consumed by the map, and we don't get the data we wanted.

With Data::OptList, you can do this instead:

This works by assuming that any defined scalar is a name and any reference following a name is its value.

FUNCTIONS

mkopt

Valid arguments are:

This produces an array of arrays; the inner arrays are name/value pairs. Values will be either ``undef'' or a reference.

Positional parameters may be used for compatibility with the old interface:
Valid values for :
By default, a name is any defined non-reference. The parameter can be a code ref that tests whether the argument passed it is a name or not. This should be used rarely. Interactions between and are not yet particularly elegant, as just tests string equality. This may change.
The parameter 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 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:

Means:

mkopt_hash

Given valid input, this routine returns a reference to a hash. It will throw an exception if any name has more than one value.

EXPORTS

Both and may be exported on request.

AUTHOR

Ricardo Signes <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2006 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


Index

NAME

VERSION

SYNOPSIS

DESCRIPTION

FUNCTIONS

mkopt

mkopt_hash

EXPORTS

AUTHOR

COPYRIGHT AND LICENSE