.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooX::Options 3pm" .TH MooX::Options 3pm "2016-12-15" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooX::Options \- Explicit Options eXtension for Object Class .SH "VERSION" .IX Header "VERSION" version 4.023 .SH "DESCRIPTION" .IX Header "DESCRIPTION" Create a command line tool with your Mo, Moo, Moose objects. .PP Everything is explicit. You have an \f(CW\*(C`option\*(C'\fR keyword to replace the usual \f(CW\*(C`has\*(C'\fR to explicitly use your attribute into the command line. .PP The \f(CW\*(C`option\*(C'\fR keyword takes additional parameters and uses Getopt::Long::Descriptive to generate a command line tool. .SH "SYNOPSIS" .IX Header "SYNOPSIS" In myOptions.pm : .PP .Vb 3 \& package myOptions; \& use Moo; \& use MooX::Options; \& \& option \*(Aqshow_this_file\*(Aq => ( \& is => \*(Aqro\*(Aq, \& format => \*(Aqs\*(Aq, \& required => 1, \& doc => \*(Aqthe file to display\*(Aq \& ); \& 1; .Ve .PP In myTool.pl : .PP .Vb 2 \& use myOptions; \& use Path::Class; \& \& my $opt = myOptions\->new_with_options; \& \& print "Content of the file : ", \& file($opt\->show_this_file)\->slurp; .Ve .PP To use it : .PP .Vb 2 \& perl myTool.pl \-\-show_this_file=myFile.txt \& Content of the file: myFile content .Ve .PP The help message : .PP .Vb 2 \& perl myTool.pl \-\-help \& USAGE: myTool.pl [\-h] [long options...] \& \& \-\-show_this_file: String \& the file to display \& \& \-h \-\-help: \& show this help message \& \& \-\-man: \& show the manual .Ve .PP The usage message : .PP .Vb 2 \& perl myTool.pl \-\-usage \& USAGE: myTool.pl [ \-\-show_this_file=String ] [ \-\-usage ] [ \-\-help ] [ \-\-man ] .Ve .PP The manual : .PP .Vb 1 \& perl myTool.pl \-\-man .Ve .SH "METHODS" .IX Header "METHODS" .SS "croak" .IX Subsection "croak" Call Carp::croak dynamically .SH "IMPORTED METHODS" .IX Header "IMPORTED METHODS" The list of the methods automatically imported into your class. .SS "new_with_options" .IX Subsection "new_with_options" It will parse your command line params and your inline params, validate and call the \f(CW\*(C`new\*(C'\fR method. .PP .Vb 1 \& myTool \-\-str=ko \& \& t\->new_with_options()\->str # ko \& t\->new_with_options(str => \*(Aqok\*(Aq)\->str #ok .Ve .SS "option" .IX Subsection "option" The \f(CW\*(C`option\*(C'\fR keyword replaces the \f(CW\*(C`has\*(C'\fR method and adds support for special options for the command line only. .PP See \*(L"\s-1OPTION PARAMETERS\*(R"\s0 for the documentation. .SS "options_usage | \-\-help" .IX Subsection "options_usage | --help" It displays the usage message and returns the exit code. .PP .Vb 4 \& my $t = t\->new_with_options(); \& my $exit_code = 1; \& my $pre_message = "str is not valid"; \& $t\->options_usage($exit_code, $pre_message); .Ve .PP This method is also automatically fired if the command option \*(L"\-\-help\*(R" is passed. .PP .Vb 1 \& myTool \-\-help .Ve .SS "options_man | \-\-man" .IX Subsection "options_man | --man" It displays the manual. .PP .Vb 2 \& my $t = t\->new_with_options(); \& $t\->options_man(); .Ve .PP This is automatically fired if the command option \*(L"\-\-man\*(R" is passed. .PP .Vb 1 \& myTool \-\-man .Ve .SS "options_short_usage | \-\-usage" .IX Subsection "options_short_usage | --usage" It displays a short version of the help message. .PP .Vb 2 \& my $t = t\->new_with_options(); \& $t\->options_short_usage($exit_code); .Ve .PP This is automatically fired if the command option \*(L"\-\-usage\*(R" is passed. .PP .Vb 1 \& myTool \-\-usage .Ve .SH "IMPORT PARAMETERS" .IX Header "IMPORT PARAMETERS" The list of parameters supported by MooX::Options. .SS "flavour" .IX Subsection "flavour" Passes extra arguments for Getopt::Long::Descriptive. It is useful if you want to configure Getopt::Long. .PP .Vb 1 \& use MooX::Options flavour => [qw( pass_through )]; .Ve .PP Any flavour is passed to Getopt::Long as a configuration, check the doc to see what is possible. .SS "protect_argv" .IX Subsection "protect_argv" By default, \f(CW@ARGV\fR is protected. If you want to do something else on it, use this option and it will change the real \f(CW@ARGV\fR. .PP .Vb 1 \& use MooX::Options protect_argv => 0; .Ve .SS "skip_options" .IX Subsection "skip_options" If you have Role with options and you want to deactivate some of them, you can use this parameter. In that case, the \f(CW\*(C`option\*(C'\fR keyword will just work like an \f(CW\*(C`has\*(C'\fR. .PP .Vb 1 \& use MooX::Options skip_options => [qw/multi/]; .Ve .SS "prefer_commandline" .IX Subsection "prefer_commandline" By default, arguments passed to \f(CW\*(C`new_with_options\*(C'\fR have a higher priority than the command line options. .PP This parameter will give the command line an higher priority. .PP .Vb 1 \& use MooX::Options prefer_commandline => 1; .Ve .SS "with_config_from_file" .IX Subsection "with_config_from_file" This parameter will load MooX::ConfigFromFile in your module. The config option will be used between the command line and parameters. .PP myTool : .PP .Vb 1 \& use MooX::Options with_config_from_file => 1; .Ve .PP In /etc/myTool.json .PP .Vb 1 \& {"test" : 1} .Ve .SH "usage_string" .IX Header "usage_string" This parameter is passed to \fIGetopt::Long::Descriptive::describe_options()\fR as the first parameter. .PP It is a \*(L"sprintf\*(R"\-like string that is used in generating the first line of the usage message. It's a one-line summary of how the command is to be invoked. The default value is \*(L"\s-1USAGE:\s0 \f(CW%c\fR \f(CW%o\fR\*(R". .PP \&\f(CW%c\fR will be replaced with what Getopt::Long::Descriptive thinks is the program name (it's computed from \f(CW$0\fR, see \*(L"prog_name\*(R"). .PP \&\f(CW%o\fR will be replaced with a list of the short options, as well as the text \&\*(L"[long options...]\*(R" if any have been defined. .PP The rest of the usage description can be used to summarize what arguments are expected to follow the program's options, and is entirely free-form. .PP Literal \*(L"%\*(R" characters will need to be written as \*(L"%%\*(R", just like with \&\*(L"sprintf\*(R". .SS "spacer" .IX Subsection "spacer" This indicate the char to use for spacer. Please only use 1 char otherwize the text will be too long. .PP The default char is \*(L" \*(R". .PP .Vb 1 \& use MooX::Options space => \*(Aq+\*(Aq .Ve .PP Then the \*(L"spacer_before\*(R" and \*(L"spacer_after\*(R" will use it for \*(L"man\*(R" and \*(L"help\*(R" message. .PP .Vb 1 \& option \*(Aqx\*(Aq => (is => \*(Aqro\*(Aq, spacer_before => 1, spacer_after => 1); .Ve .SH "OPTION PARAMETERS" .IX Header "OPTION PARAMETERS" The keyword \f(CW\*(C`option\*(C'\fR extend the keyword \f(CW\*(C`has\*(C'\fR with specific parameters for the command line. .SS "doc | documentation" .IX Subsection "doc | documentation" Documentation for the command line option. .SS "long_doc" .IX Subsection "long_doc" Documentation for the man page. By default the \f(CW\*(C`doc\*(C'\fR parameter will be used. .PP See also Man parameters to get more examples how to build a nice man page. .SS "required" .IX Subsection "required" This attribute indicates that the parameter is mandatory. This attribute is not really used by MooX::Options but ensures that consistent error message will be displayed. .SS "format" .IX Subsection "format" Format of the params, same as Getopt::Long::Descriptive. .IP "\(bu" 4 i : integer .IP "\(bu" 4 i@: array of integer .IP "\(bu" 4 s : string .IP "\(bu" 4 s@: array of string .IP "\(bu" 4 f : float value .PP By default, it's a boolean value. .PP Take a look of available formats with Getopt::Long::Descriptive. .PP You need to understand that everything is explicit here. If you use Moose and your attribute has \f(CW\*(C`isa => \*(AqArray[Int]\*(Aq\*(C'\fR, that will \fBnot\fR imply the format \f(CW\*(C`i@\*(C'\fR. .SS "format json : special format support" .IX Subsection "format json : special format support" The parameter will be treated like a json string. .PP .Vb 1 \& option \*(Aqhash\*(Aq => (is => \*(Aqro\*(Aq, json => 1); .Ve .PP You can also use the json format .PP .Vb 1 \& option \*(Aqhash\*(Aq => (is => \*(Aqro\*(Aq, format => "json"); \& \& myTool \-\-hash=\*(Aq{"a":1,"b":2}\*(Aq # hash = { a => 1, b => 2 } .Ve .SS "negativable" .IX Subsection "negativable" It adds the negative version for the option. .PP .Vb 1 \& option \*(Aqverbose\*(Aq => (is => \*(Aqro\*(Aq, negativable => 1); \& \& myTool \-\-verbose # verbose = 1 \& myTool \-\-no\-verbose # verbose = 0 .Ve .SS "repeatable" .IX Subsection "repeatable" It appends to the \*(L"format\*(R" the array attribute \f(CW\*(C`@\*(C'\fR. .PP I advise to add a default value to your attribute to always have an array. Otherwise the default value will be an undefined value. .PP .Vb 1 \& option foo => (is => \*(Aqrw\*(Aq, format => \*(Aqs@\*(Aq, default => sub { [] }); \& \& myTool \-\-foo="abc" \-\-foo="def" # foo = ["abc", "def"] .Ve .SS "autosplit" .IX Subsection "autosplit" For repeatable option, you can add the autosplit feature with your specific parameters. .PP .Vb 1 \& option test => (is => \*(Aqro\*(Aq, format => \*(Aqi@\*(Aq, default => sub {[]}, autosplit => \*(Aq,\*(Aq); \& \& myTool \-\-test=1 \-\-test=2 # test = (1, 2) \& myTool \-\-test=1,2,3 # test = (1, 2, 3) .Ve .PP It will also handle quoted params with the autosplit. .PP .Vb 1 \& option testStr => (is => \*(Aqro\*(Aq, format => \*(Aqs@\*(Aq, default => sub {[]}, autosplit => \*(Aq,\*(Aq); \& \& myTool \-\-testStr=\*(Aqa,b,"c,d",e,f\*(Aq # testStr ("a", "b", "c,d", "e", "f") .Ve .SS "autorange" .IX Subsection "autorange" For another repeatable option you can add the autorange feature with your specific parameters. This allows you to pass number ranges instead of passing each individual number. .PP .Vb 1 \& option test => (is => \*(Aqro\*(Aq, format => \*(Aqi@\*(Aq, default => sub {[]}, autorange => 1); \& \& myTool \-\-test=1 \-\-test=2 # test = (1, 2) \& myTool \-\-test=1,2,3 # test = (1, 2, 3) \& myTool \-\-test=1,2,3..6 # test = (1, 2, 3, 4, 5, 6) .Ve .PP It will also handle quoted params like \f(CW\*(C`autosplit\*(C'\fR, and will not rangify them. .PP .Vb 1 \& option testStr => (is => \*(Aqro\*(Aq, format => \*(Aqs@\*(Aq, default => sub {[]}, autorange => 1); \& \& myTool \-\-testStr=\*(Aq1,2,"3,a,4",5\*(Aq # testStr (1, 2, "3,a,4", 5) .Ve .PP \&\f(CW\*(C`autosplit\*(C'\fR will be set to ',' if undefined. You may set \f(CW\*(C`autosplit\*(C'\fR to a different delimiter than ',' for your group separation, but the range operator '..' cannot be changed. .PP .Vb 1 \& option testStr => (is => \*(Aqro\*(Aq, format => \*(Aqs@\*(Aq, default => sub {[]}, autorange => 1, autosplit => \*(Aq\-\*(Aq); \& \& myTool \-\-testStr=\*(Aq1\-2\-3\-5..7\*(Aq # testStr (1, 2, 3, 5, 6, 7) .Ve .SS "short" .IX Subsection "short" Long option can also have short version or aliased. .PP .Vb 1 \& option \*(Aqverbose\*(Aq => (is => \*(Aqro\*(Aq, short => \*(Aqv\*(Aq); \& \& myTool \-\-verbose # verbose = 1 \& myTool \-v # verbose = 1 \& \& option \*(Aqaccount_id\*(Aq => (is => \*(Aqro\*(Aq, format => \*(Aqi\*(Aq, short => \*(Aqa|id\*(Aq); \& \& myTool \-\-account_id=1 \& myTool \-a=1 \& myTool \-\-id=1 .Ve .PP You can also use a shorter option without attribute : .PP .Vb 1 \& option \*(Aqaccount_id\*(Aq => (is => \*(Aqro\*(Aq, format => \*(Aqi\*(Aq); \& \& myTool \-\-acc=1 \& myTool \-\-account=1 .Ve .SS "order" .IX Subsection "order" Specifies the order of the attribute. If you want to push some attributes at the end of the list. By default all options have an order set to \f(CW0\fR, and options are sorted by their names. .PP .Vb 1 \& option \*(Aqat_the_end\*(Aq => (is => \*(Aqro\*(Aq, order => 999); .Ve .SS "hidden" .IX Subsection "hidden" Hide option from doc but still an option you can use on command line. .PP .Vb 1 \& option \*(Aqdebug\*(Aq => (is => \*(Aqro\*(Aq, doc => \*(Aqhidden\*(Aq); .Ve .PP Or .PP .Vb 1 \& option \*(Aqdebug\*(Aq => (is => \*(Aqro\*(Aq, hidden => 1); .Ve .SS "spacer_before, spacer_after" .IX Subsection "spacer_before, spacer_after" Add spacer before or after or both the params .PP .Vb 1 \& option \*(Aqmyoption\*(Aq => (is => \*(Aqro\*(Aq, spacer_before => 1, spacer_after => 1); .Ve .SH "ADDITIONAL MANUALS" .IX Header "ADDITIONAL MANUALS" .IP "\(bu" 4 Man parameters .IP "\(bu" 4 Using namespace::clean .IP "\(bu" 4 Manage your tools with MooX::Cmd .SH "EXTERNAL EXAMPLES" .IX Header "EXTERNAL EXAMPLES" .IP "\(bu" 4 Slide3D about MooX::Options .SH "Translation" .IX Header "Translation" Translation is now supported. .PP Use the dzil command to update the pot and merge into the po files. .IP "\(bu" 4 dzil msg-init .Sp Create a new language po .IP "\(bu" 4 dzil msg-scan .Sp Scan and generate or update the pot file .IP "\(bu" 4 dzil msg-merge .Sp Update all languages using the pot file .SS "\s-1THANKS\s0" .IX Subsection "THANKS" .IP "\(bu" 4 sschober .Sp For implementation and German translation. .SH "THANKS" .IX Header "THANKS" .IP "\(bu" 4 Matt S. Trout (mst) .Sp For his patience and advice. .IP "\(bu" 4 Tomas Doran (t0m) .Sp To help me release the new version, and using it :) .IP "\(bu" 4 Torsten Raudssus (Getty) .Sp to use it a lot in DuckDuckGo (go to see MooX module also) .IP "\(bu" 4 Jens Rehsack (\s-1REHSACK\s0) .Sp Use with PkgSrc , and many really good idea (MooX::Cmd, MooX::ConfigFromFile, and more to come I'm sure) .IP "\(bu" 4 All contributors .Sp For improving and add more feature to MooX::Options .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website https://github.com/celogeek/MooX\-Options/issues .PP 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. .SH "AUTHOR" .IX Header "AUTHOR" celogeek .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2013 by celogeek . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.