This file is indexed.

/usr/share/perl5/Data/OptList.pm is in libdata-optlist-perl 0.110-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
use strict;
use warnings;
package Data::OptList;
# ABSTRACT: parse and validate simple name/value option pairs
$Data::OptList::VERSION = '0.110';
use List::Util ();
use Params::Util ();
use Sub::Install 0.921 ();

#pod =head1 SYNOPSIS
#pod
#pod   use Data::OptList;
#pod
#pod   my $options = Data::OptList::mkopt([
#pod     qw(key1 key2 key3 key4),
#pod     key5 => { ... },
#pod     key6 => [ ... ],
#pod     key7 => sub { ... },
#pod     key8 => { ... },
#pod     key8 => [ ... ],
#pod   ]);
#pod
#pod ...is the same thing, more or less, as:
#pod
#pod   my $options = [
#pod     [ key1 => undef,        ],
#pod     [ key2 => undef,        ],
#pod     [ key3 => undef,        ],
#pod     [ key4 => undef,        ],
#pod     [ key5 => { ... },      ],
#pod     [ key6 => [ ... ],      ],
#pod     [ key7 => sub { ... },  ],
#pod     [ key8 => { ... },      ],
#pod     [ key8 => [ ... ],      ],
#pod   ]);
#pod
#pod =head1 DESCRIPTION
#pod
#pod Hashes are great for storing named data, but if you want more than one entry
#pod for a name, you have to use a list of pairs.  Even then, this is really boring
#pod to write:
#pod
#pod   $values = [
#pod     foo => undef,
#pod     bar => undef,
#pod     baz => undef,
#pod     xyz => { ... },
#pod   ];
#pod
#pod Just look at all those undefs!  Don't worry, we can get rid of those:
#pod
#pod   $values = [
#pod     map { $_ => undef } qw(foo bar baz),
#pod     xyz => { ... },
#pod   ];
#pod
#pod Aaaauuugh!  We've saved a little typing, but now it requires thought to read,
#pod and thinking is even worse than typing... and it's got a bug!  It looked right,
#pod didn't it?  Well, the C<< xyz => { ... } >> gets consumed by the map, and we
#pod don't get the data we wanted.
#pod
#pod With Data::OptList, you can do this instead:
#pod
#pod   $values = Data::OptList::mkopt([
#pod     qw(foo bar baz),
#pod     xyz => { ... },
#pod   ]);
#pod
#pod This works by assuming that any defined scalar is a name and any reference
#pod following a name is its value.
#pod
#pod =func mkopt
#pod
#pod   my $opt_list = Data::OptList::mkopt($input, \%arg);
#pod
#pod Valid arguments are:
#pod
#pod   moniker        - a word used in errors to describe the opt list; encouraged
#pod   require_unique - if true, no name may appear more than once
#pod   must_be        - types to which opt list values are limited (described below)
#pod   name_test      - a coderef used to test whether a value can be a name
#pod                    (described below, but you probably don't want this)
#pod
#pod This produces an array of arrays; the inner arrays are name/value pairs.
#pod Values will be either "undef" or a reference.
#pod
#pod Positional parameters may be used for compatibility with the old C<mkopt>
#pod interface:
#pod
#pod   my $opt_list = Data::OptList::mkopt($input, $moniker, $req_uni, $must_be);
#pod
#pod Valid values for C<$input>:
#pod
#pod  undef    -> []
#pod  hashref  -> [ [ key1 => value1 ] ... ] # non-ref values become undef
#pod  arrayref -> every name followed by a non-name becomes a pair: [ name => ref ]
#pod              every name followed by undef becomes a pair: [ name => undef ]
#pod              otherwise, it becomes [ name => undef ] like so:
#pod              [ "a", "b", [ 1, 2 ] ] -> [ [ a => undef ], [ b => [ 1, 2 ] ] ]
#pod
#pod By default, a I<name> is any defined non-reference.  The C<name_test> parameter
#pod can be a code ref that tests whether the argument passed it is a name or not.
#pod This should be used rarely.  Interactions between C<require_unique> and
#pod C<name_test> are not yet particularly elegant, as C<require_unique> just tests
#pod string equality.  B<This may change.>
#pod
#pod The C<must_be> parameter is either a scalar or array of scalars; it defines
#pod what kind(s) of refs may be values.  If an invalid value is found, an exception
#pod is thrown.  If no value is passed for this argument, any reference is valid.
#pod If C<must_be> specifies that values must be CODE, HASH, ARRAY, or SCALAR, then
#pod Params::Util is used to check whether the given value can provide that
#pod interface.  Otherwise, it checks that the given value is an object of the kind.
#pod
#pod In other words:
#pod
#pod   [ qw(SCALAR HASH Object::Known) ]
#pod
#pod Means:
#pod
#pod   _SCALAR0($value) or _HASH($value) or _INSTANCE($value, 'Object::Known')
#pod
#pod =cut

my %test_for;
BEGIN {
  %test_for = (
    CODE   => \&Params::Util::_CODELIKE,  ## no critic
    HASH   => \&Params::Util::_HASHLIKE,  ## no critic
    ARRAY  => \&Params::Util::_ARRAYLIKE, ## no critic
    SCALAR => \&Params::Util::_SCALAR0,   ## no critic
  );
}

sub mkopt {
  my ($opt_list) = shift;

  my ($moniker, $require_unique, $must_be); # the old positional args
  my ($name_test, $is_a);

  if (@_) {
    if (@_ == 1 and Params::Util::_HASHLIKE($_[0])) {
      ($moniker, $require_unique, $must_be, $name_test)
        = @{$_[0]}{ qw(moniker require_unique must_be name_test) };
    } else {
      ($moniker, $require_unique, $must_be) = @_;
    }

    # Transform the $must_be specification into a closure $is_a
    # that will check if a value matches the spec

    if (defined $must_be) {
      $must_be = [ $must_be ] unless ref $must_be;
      my @checks = map {
          my $class = $_;
          $test_for{$_}
          || sub { $_[1] = $class; goto \&Params::Util::_INSTANCE }
      } @$must_be;

      $is_a = (@checks == 1)
            ? $checks[0]
            : sub {
                my $value = $_[0];
                List::Util::first { defined($_->($value)) } @checks
              };

      $moniker = 'unnamed' unless defined $moniker;
    }
  }

  return [] unless $opt_list;

  $name_test ||= sub { ! ref $_[0] };

  $opt_list = [
    map { $_ => (ref $opt_list->{$_} ? $opt_list->{$_} : ()) } keys %$opt_list
  ] if ref $opt_list eq 'HASH';

  my @return;
  my %seen;

  for (my $i = 0; $i < @$opt_list; $i++) { ## no critic
    my $name = $opt_list->[$i];

    if ($require_unique) {
      Carp::croak "multiple definitions provided for $name" if $seen{$name}++;
    }

    my $value;

    if ($i < $#$opt_list) {
      if (not defined $opt_list->[$i+1]) {
        $i++
      } elsif (! $name_test->($opt_list->[$i+1])) {
        $value = $opt_list->[++$i];
        if ($is_a && !$is_a->($value)) {
          my $ref = ref $value;
          Carp::croak "$ref-ref values are not valid in $moniker opt list";
        }
      }
    }

    push @return, [ $name => $value ];
  }

  return \@return;
}

#pod =func mkopt_hash
#pod
#pod   my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be);
#pod
#pod Given valid C<L</mkopt>> input, this routine returns a reference to a hash.  It
#pod will throw an exception if any name has more than one value.
#pod
#pod =cut

sub mkopt_hash {
  my ($opt_list, $moniker, $must_be) = @_;
  return {} unless $opt_list;

  $opt_list = mkopt($opt_list, $moniker, 1, $must_be);
  my %hash = map { $_->[0] => $_->[1] } @$opt_list;
  return \%hash;
}

#pod =head1 EXPORTS
#pod
#pod Both C<mkopt> and C<mkopt_hash> may be exported on request.
#pod
#pod =cut

BEGIN {
  *import = Sub::Install::exporter {
    exports => [qw(mkopt mkopt_hash)],
  };
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

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

=head1 VERSION

version 0.110

=head1 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 => [ ... ],      ],
  ]);

=head1 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... and it's got a bug!  It looked right,
didn't it?  Well, the C<< xyz => { ... } >> gets consumed by the map, and we
don't get the data we wanted.

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.

=head1 FUNCTIONS

=head2 mkopt

  my $opt_list = Data::OptList::mkopt($input, \%arg);

Valid arguments are:

  moniker        - a word used in errors to describe the opt list; encouraged
  require_unique - if true, no name may appear more than once
  must_be        - types to which opt list values are limited (described below)
  name_test      - a coderef used to test whether a value can be a name
                   (described below, but you probably don't want this)

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 C<mkopt>
interface:

  my $opt_list = Data::OptList::mkopt($input, $moniker, $req_uni, $must_be);

Valid values for C<$input>:

 undef    -> []
 hashref  -> [ [ key1 => value1 ] ... ] # non-ref values become undef
 arrayref -> every name followed by a non-name becomes a pair: [ name => ref ]
             every name followed by undef becomes a pair: [ name => undef ]
             otherwise, it becomes [ name => undef ] like so:
             [ "a", "b", [ 1, 2 ] ] -> [ [ a => undef ], [ b => [ 1, 2 ] ] ]

By default, a I<name> is any defined non-reference.  The C<name_test> 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 C<require_unique> and
C<name_test> are not yet particularly elegant, as C<require_unique> just tests
string equality.  B<This may change.>

The C<must_be> 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 C<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')

=head2 mkopt_hash

  my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be);

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

=head1 EXPORTS

Both C<mkopt> and C<mkopt_hash> may be exported on request.

=head1 AUTHOR

Ricardo Signes <rjbs@cpan.org>

=head1 CONTRIBUTORS

=for stopwords Olivier Mengué Ricardo SIGNES

=over 4

=item *

Olivier Mengué <dolmen@cpan.org>

=item *

Ricardo SIGNES <rjbs@codesimply.com>

=back

=head1 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.

=cut