NAME

MooX::Options::Docs::QuickStart - Fast and simple examples

VERSION

version 4.000

DESCRIPTION

This is quick examples to start creating your tools on command line.

QUICK START

DISPLAY A FILE

You can quickly create a basic command line tools, using inline package to capture the option you need.

In this example (cf SYNOPSIS), we get want to get the name of the file from command line.

  • The script

    package myOptions;
    use Moo;
    use MooX::Options;
    
    option 'show_this_file' => (
        is => 'ro',
        format => 's',
        required => 1,
        doc => 'the file to display',
        short => 'f'
    );
    1;
    
    package main;
    use Path::Class;
    
    my $opt = myOptions->new_with_options;
    
    print "Content of the file : ",
         file($opt->show_this_file)->slurp;
  • Run it

    myTools.pl --show_this_file=myDoc
    myTools.pl --show-this-file=myDoc
    myTools.pl --show=myDoc
    myTools.pl -f=myDoc
    myTools.pl -f myDoc
  • Automatic help when a required param is missing

    If you miss the required params, MooX::Options explain the error, and show you the help message :

    myTools.pl
    
    show_this_file is missing
    USAGE: myTools.pl [-fh] [long options...]
    
        --show_this_file: String
            the file to display
        
        -h --help:
            show this help message
        
        --man:
            show the manual
  • Help wanted

    myTools.pl --help
    myTools.pl --man

DISPLAY SEVERAL FILES

MooX::Options handle different formats of parameters almost like Getopt::Long::Descriptive. You can create an array for files to display. A cool feature is the "autosplit" parameters.

  • The script

    package myOptions;
    use Moo;
    use MooX::Options;
    
    option 'show_this_files' => (
        is => 'ro',
        format => 's@',
        required => 1,
        doc => 'the file to display',
        short => 'f',
        autosplit => ',',
    );
    1;
    
    package main;
    use Path::Class;
    
    my $opt = myOptions->new_with_options;
    
    for my $f (@{$opt->show_this_files}) {
      print "File content of <$f> : \n\n", file($f)->slurp, "\n\n";
    }
  • Run it

    To display myDoc1 and myDoc2 :

    myTools.pl --show_this_files=myDoc1 --show_this_files=myDoc2
    myTools.pl --show_this_files=myDoc1,myDoc2

SEE ALSO

MooX::Options

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/celogeek/MooX-Options/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

celogeek <me@celogeek.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by celogeek <me@celogeek.com>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.