github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

rjbs / data-optlist

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (5)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (5)
    • 0.105
    • 0.104
    • 0.103
    • 0.102
    • 0.100
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

parse and validate simple name/value option pairs — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

changelog for update 
rjbs (author)
Thu Jan 14 04:46:26 -0800 2010
commit  9a8f0e991cd5dcfe31f520d1b0d5567460bce5bf
tree    c4da15ff328ac27d8c9ec55e175ef9540c956529
parent  716e4cbef87971c924e707905a42b8fd9f52fe7d
data-optlist /
name age
history
message
file Changes Thu Jan 14 04:46:26 -0800 2010 changelog for update [rjbs]
file LICENSE Loading commit data...
file MANIFEST.SKIP Fri Jan 16 07:27:56 -0800 2009 prep new release [rjbs]
file Makefile.PL
file README Fri Jan 16 07:27:56 -0800 2009 prep new release [rjbs]
directory lib/ Thu Jan 14 04:44:35 -0800 2010 fix typo in synopsis [rjbs]
directory t/
README
NAME
    Data::OptList - parse and validate simple name/value option pairs

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.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server