metaperl has asked for the wisdom of the Perl Monks concerning the following question:

Could someone please show me a practical example of how one would use Data::OptList? MST mentioned Moose 'with' syntax and DBIx::Class 'add_columns' as examples, but I think those are too involved to get a basic understanding of this module.

One very confusing thing about this module is the description starts off saying

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
But then the docs show named data where is not more than one entry per name:
$values = [ foo => undef, bar => undef, baz => undef, xyz => { ... }, ];
Assuming that 'entry' is synonomous with 'value' and 'name' is synonomous with 'key'.

Replies are listed 'Best First'.
Re: Data::OptList - I just dont get it
by ikegami (Patriarch) on Jul 21, 2009 at 14:12 UTC
    It's a shortcut to build an AoA of key-ref pairs where a portion of the refs are undef.
Re: Data::OptList - I just dont get it
by metaperl (Curate) on Jul 21, 2009 at 14:10 UTC
    Well, I've made an example of using a 'name' more than once:
    use Data::OptList; my $options = Data::OptList::mkopt([ qw(key1 key2 key3 key4), key5 => { x => 1, y => 2 }, key5 => { a => 2, b => 4 }, ]); use Data::Dumper; warn Dumper($options); sh-3.2$ perl try.pl $VAR1 = [ [ 'key1', undef ], [ 'key2', undef ], [ 'key3', undef ], [ 'key4', undef ], [ 'key5', { 'y' => 2, 'x' => 1 } ], [ 'key5', { 'a' => 2, 'b' => 4 } ] ]; sh-3.2$
    but I dont understand why the two 'key5' entries were not folded under one 'key5' name with the two values under it, like so:
    [ 'key5', [ { 'a' => 2, 'b' => 4 }, { 'y' => 2, 'x' => 1 } ] ]