{"id":6869,"date":"2022-12-20T19:33:45","date_gmt":"2022-12-20T22:33:45","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/dataoptlist-man3\/"},"modified":"2022-12-20T19:33:45","modified_gmt":"2022-12-20T22:33:45","slug":"dataoptlist-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/dataoptlist-man3\/","title":{"rendered":"Data::OptList (man3)"},"content":{"rendered":"<h1 align=\"center\">Data::OptList<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#VERSION\">VERSION<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#FUNCTIONS\">FUNCTIONS<\/a><br \/> <a href=\"#EXPORTS\">EXPORTS<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#CONTRIBUTORS\">CONTRIBUTORS<\/a><br \/> <a href=\"#COPYRIGHT AND LICENSE\">COPYRIGHT AND LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Data::OptList \u2212 parse and validate simple name\/value option pairs<\/p>\n<h2>VERSION <a name=\"VERSION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">version 0.110<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use Data::OptList; <br \/> my $options = Data::OptList::mkopt([ <br \/> qw(key1 key2 key3 key4), <br \/> key5 => { &#8230; }, <br \/> key6 => [ &#8230; ], <br \/> key7 => sub { &#8230; }, <br \/> key8 => { &#8230; }, <br \/> key8 => [ &#8230; ], <br \/> ]);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8230;is the same thing, more or less, as:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $options = [ <br \/> [ key1 => undef, ], <br \/> [ key2 => undef, ], <br \/> [ key3 => undef, ], <br \/> [ key4 => undef, ], <br \/> [ key5 => { &#8230; }, ], <br \/> [ key6 => [ &#8230; ], ], <br \/> [ key7 => sub { &#8230; }, ], <br \/> [ key8 => { &#8230; }, ], <br \/> [ key8 => [ &#8230; ], ], <br \/> ]);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">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:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$values = [ <br \/> foo => undef, <br \/> bar => undef, <br \/> baz => undef, <br \/> xyz => { &#8230; }, <br \/> ];<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Just look at all those undefs! Don\u2019t worry, we can get rid of those:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$values = [ <br \/> map { $_ => undef } qw(foo bar baz), <br \/> xyz => { &#8230; }, <br \/> ];<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Aaaauuugh! We\u2019ve saved a little typing, but now it requires thought to read, and thinking is even worse than typing&#8230; and it\u2019s got a bug! It looked right, didn\u2019t it? Well, the &#8220;xyz => { &#8230; }&#8221; gets consumed by the map, and we don\u2019t get the data we wanted.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">With Data::OptList, you can do this instead:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$values = Data::OptList::mkopt([ <br \/> qw(foo bar baz), <br \/> xyz => { &#8230; }, <br \/> ]);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This works by assuming that any defined scalar is a name and any reference following a name is its value.<\/p>\n<h2>FUNCTIONS <a name=\"FUNCTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>mkopt<\/b> <br \/> my $opt_list = Data::OptList::mkopt($input, %arg);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Valid arguments are:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">moniker \u2212 a word used in errors to describe the opt list; encouraged <br \/> require_unique \u2212 if true, no name may appear more than once <br \/> must_be \u2212 types to which opt list values are limited (described below) <br \/> name_test \u2212 a coderef used to test whether a value can be a name <br \/> (described below, but you probably don&#8217;t want this)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This produces an array of arrays; the inner arrays are name\/value pairs. Values will be either &#8220;undef&#8221; or a reference.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Positional parameters may be used for compatibility with the old &#8220;mkopt&#8221; interface:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">my $opt_list = Data::OptList::mkopt($input, $moniker, $req_uni, $must_be);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Valid values for $input:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">undef \u2212> [] <br \/> hashref \u2212> [ [ key1 => value1 ] &#8230; ] # non\u2212ref values become undef <br \/> arrayref \u2212> every name followed by a non\u2212name becomes a pair: [ name => ref ] <br \/> every name followed by undef becomes a pair: [ name => undef ] <br \/> otherwise, it becomes [ name => undef ] like so: <br \/> [ &#8220;a&#8221;, &#8220;b&#8221;, [ 1, 2 ] ] \u2212> [ [ a => undef ], [ b => [ 1, 2 ] ] ]<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">By default, a <i>name<\/i> is any defined non-reference. The &#8220;name_test&#8221; 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 &#8220;require_unique&#8221; and &#8220;name_test&#8221; are not yet particularly elegant, as &#8220;require_unique&#8221; just tests string equality. <b>This may change.<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The &#8220;must_be&#8221; 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 &#8220;must_be&#8221; specifies that values must be <small>CODE, HASH, ARRAY,<\/small> or <small>SCALAR,<\/small> 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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In other words:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">[ qw(SCALAR HASH Object::Known) ]<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Means:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">_SCALAR0($value) or _HASH($value) or _INSTANCE($value, &#8216;Object::Known&#8217;)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>mkopt_hash<\/b> <br \/> my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Given valid &#8220;mkopt&#8221; input, this routine returns a reference to a hash. It will throw an exception if any name has more than one value.<\/p>\n<h2>EXPORTS <a name=\"EXPORTS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Both &#8220;mkopt&#8221; and &#8220;mkopt_hash&#8221; may be exported on request.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Ricardo Signes <rjbs@cpan.org><\/p>\n<h2>CONTRIBUTORS <a name=\"CONTRIBUTORS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"55%\">\n<p style=\"margin-top: 1em\">Olivier Mengu\u00c3\u00a9 <dolmen@cpan.org><\/p>\n<\/td>\n<td width=\"28%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"5%\"><\/td>\n<td width=\"55%\">\n<p>Ricardo <small>SIGNES<\/small> <rjbs@codesimply.com><\/p>\n<\/td>\n<td width=\"28%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>COPYRIGHT AND LICENSE <a name=\"COPYRIGHT AND LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This software is copyright (c) 2006 by Ricardo Signes.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This is free software; you can redistribute it and\/or modify it under the same terms as the Perl 5 programming language system itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Data::OptList \u2212 parse and validate simple name\/value option pairs <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3234,3007],"class_list":["post-6869","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-dataoptlist","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6869"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6869\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}