# info > Data::OptList

---
type: CommandReference
command: Data::OptList
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `mkopt([qw(key1 key2), key3 => { ... }])` — turn a mix of barewords and pairs into an array of `[name, value]` pairs
- `mkopt($hashref)` — convert a hash to a list of pairs
- `mkopt($input, { require_unique => 1 })` — reject duplicate names
- `mkopt($input, { must_be => 'HASH' })` — restrict values to hashrefs
- `mkopt_hash([qw(a b), c => [1,2]])` — return a hashref; one value per name

## Name
`Data::OptList` — parse and validate simple name/value option pairs

## Synopsis
perl
use Data::OptList;

my $opt_list = Data::OptList::mkopt([
  qw(key1 key2 key3 key4),
  key5 => { ... },
  key6 => [ ... ],
  key7 => sub { ... },
]);

my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be);
## Options (Function Arguments)

### `mkopt($input, \%arg)`
- **`moniker`** — label used in error messages
- **`require_unique`** — boolean; if true, names must appear only once
- **`must_be`** — reference type(s) allowed as values (e.g., `'HASH'`, `'ARRAY'`, `'CODE'`, `'SCALAR'`, or a class name)
- **`name_test`** — coderef to test if a value is a name (rarely needed)

Positional signature (backward compatible): `mkopt($input, $moniker, $require_unique, $must_be)`

**`$input` forms:**
- `undef` → `[]`
- hashref → `[ [key, value], ... ]` (non‑ref values become `undef`)
- arrayref → each sequence of name + reference becomes `[name, ref]`; name + `undef` → `[name, undef]`; otherwise singleton name → `[name, undef]`

### `mkopt_hash($input, $moniker, $must_be)`
Returns a hashref. Throws an exception if any name has more than one value.

## Examples
perl
# Simple list of names
my $opts = Data::OptList::mkopt([qw(foo bar baz)]);
# $opts = [ [ foo => undef ], [ bar => undef ], [ baz => undef ] ]

# Mixed names and values (reference values)
my $opts = Data::OptList::mkopt([
  qw(host port),
  headers => { 'Content-Type' => 'text/plain' },
]);

# Ensuring uniqueness
use Data::OptList;
my $opts = Data::OptList::mkopt(\@input, { require_unique => 1 });

# mkopt_hash example
my $hash = Data::OptList::mkopt_hash([qw(a b), c => [1,2]]);
# $hash = { a => undef, b => undef, c => [1,2] }
## See Also
- [Params::Util](http://localhost/phpMan.php/perldoc/Params%3A%3AUtil/markdown) — used by `must_be` for type checks (CODE, HASH, ARRAY, SCALAR)
- [Sub::Exporter](http://localhost/phpMan.php/perldoc/Sub%3A%3AExporter/markdown) — common companion for configuration export

## Exit Codes
Not applicable.