The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Options::Generator - Build options for the command line from a perl data structure

VERSION

Version 0.01

SYNOPSIS

    use Options::Generator;

    my $og = Options::Generator->new;
    print $og->generate($data);
 

    or more detailed...
     
    my $og = Options::Generater->new({
        outer_prefix   => [ '-', '--' ],
        outer_assign   => ' ',  # default
        outer_separate => ' ',  # default
        inner_assign   => '=',  # default
        inner_separate => ',',  # default
        ... 
    });
    my $data = {
        foo => 'bar',
        o =>  undef,
        s =>  'silly',
        options => [ 'one', 'two', { this => that }],
        blah => undef,
    };
    
    prints:

    --foo bar --options one,two,this=that, --blah -o -s silly
    

SUBROUTINES/METHODS

Options:Generator->new($args);

Accepts a hashref of definitions

  • outer_prefix The prefix character to add to the outer options, defaults to a single hyphen if not specified. This is the only option that can accept an array reference for options that are single length. The first element will be assigned to single length options, the second element will be assigned to options greater that a single character. outer_prefx => '--' # --foo outer_prefix => '-' # -foo outer_prefix => [ '-', '--'] # -f --foo --bar -s -c

  • outer_assign The character to assign a value to the option, defaults to space if not specified. --foo bar outer_assign => '=' # --foo=bar

  • outer_separate The character to separate outer most options. Defaults to space if not specified. --foo bar outer_separate => ',' # --foo=bar,--boo=baz

  • inner_prefx The prefix character to add to the inner options (if applicable). No prefix by default --foo bar,baz,this=that inner_prefix => '+' # --foo +bar,+baz,+this=that

  • inner_assign The character to assign values to the inner options. Defaults to equals sign. --foo this=that,boo=baz

  • inner_separate The character to separate inner options. Defaults to comma

    Examples of outputs with defaults

        --foo
        --foo --bar
        --foo -b -z --bar
        --foo bar=baz,this=that -o -s --options -f blah

$og->generate($data)

Returns a string of your options. Supply your perl data structure as a hash ref.

    my $data = {
        foo => 'bar',
        bar => 'baz',
        inner => [ 'this', 'that', { one => 'two'} ],
        a => b
        c => undef,
    };
    print $og->generate($hash);


        

AUTHOR

Michael Kroher, <infrared at cpan.org>

BUGS

Wrote this module for kvm-qemu generation stuff (hence the defaults).

Please report any bugs or feature requests to bug-commandline-generator at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Options-Generator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Options::Generator

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2011 Michael Kroher.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.