MooX-Options-4.103/000755 000765 000024 00000000000 13147041352 013776 5ustar00snostaff000000 000000 MooX-Options-4.103/Changes000644 000765 000024 00000026217 13147036663 015312 0ustar00snostaff000000 000000 Revision history for MooX-Options 4.103 2017-08-22 * fix broken shortname split (Thanks to Burak Gürsoy for reporting the issue) * fix copy/paste issue in tests of shortname * fix some typo's in tests * declare honestly the state of Mo support 4.102 2017-08-21 * fix out-of-order abbrev (analyzed and reported by Jean-Damien Durand ) 4.101 2017-07-24 * remove fatalized warnings for all categories and rely on wise strictures maintainer instead * remove dynamic_config from META files (fix RT#122349) 4.100 2017-06-27 * release 4.099_003 as 4.100 Please read carefully the Changes before updating blindly! 4.099_003 2017-06-12 * use MRO::Compat instead of mro for Perls bevor v5.9.5 4.099_002 2017-06-06 * fix some broken documentation due move from Dist::Zilla to ExtUtils::MakeMaker * improve additional documentation regarding MooX::Cmd, MooX::ConfigFromFile and namespace::clean * add localization (test) using MooX::Locale::TextDomain::OO * remove unused modules being loaded from tests 4.099_001 2017-06-02 * Move from Dist::Zilla to ExtUtils::MakeMaker * allow enhancing attributes to option * improve Kwalitee * rename negativable into negatable * replace Locale::TextDomain by MooX::Locale::Passthrough * make lazy loaded features optional * decouple autorange and autosplit * relax related current directory in INC 4.023 2016-07-12 22:19:00 GMT * Bug Github #55 : Fix error reporting on missing required arguments with Moo 2.002002. (intrigeri) * Bug #513 : remove perl 5.10 deps (Celogeek San) 4.022 2015-11-30 11:56:47 GMT * Bug #501 : Remove useless space (Celogeek San) 4.021 2015-11-11 16:42:01 GMT * Feature #487 : Translate using Locale::TextDomain (sschober) add setlocale for linux system 4.020 2015-11-08 17:33:34 GMT * Feature #487 : Translate using Locale::TextDomain (sschober) fix LC_ALL in tests 4.019 2015-10-31 16:01:55 GMT * Bug #496 : Handle multiple autosplit options correctly (Celogeek San) * Feature #489 : add compact help (Celogeek San) * Feature #487 : Translate using Locale::TextDomain (sschober) * Feature #486 : Reduce runtime dependency footprint (arc) * Feature #481 : add spacer option (Celogeek San) * Feature #373 : use "format" => "json" instead of json => 1 (Celogeek San) 4.018 2015-03-05 07:07:03 GMT * Feature #475 : Add usage_string parameters (kablamo) 4.017 2015-02-13 07:13:03 GMT * Bug #472 : Upgrade deps on Module::Build and Getopt::Long (Celogeek San) 4.016 2015-01-24 12:30:10 GMT * Feature #470 : Add "hidden" attribute, and doc (Celogeek San) * Feature #471 : Added a better error message for isa check failures (Celogeek San) 4.015 2015-01-13 16:06:52 GMT * Bug #466 : Term::Any::Size should be recommanded but optional (Celogeek San) fix eval 4.014 2015-01-13 15:51:32 GMT * Bug #464 : warning generated when missing required params (Celogeek San) * Bug #466 : Term::Any::Size should be recommanded but optional (Celogeek San) 4.013 2014-11-22 07:43:13 GMT * Feature #462 : Autorange (Celogeek San) 4.012 2014-10-07 09:42:27 GMT * Bug #455 : Option of options should not be change for trait (Celogeek San) handle shorter name 4.011 2014-10-07 08:51:50 GMT * Bug #455 : Option of options should not be change for trait (Celogeek San) 4.010 2014-09-05 16:49:56 GMT * Feature #453 : Use Text::LineFold instead of Text::WrapI18N (Celogeek San) * Feature #452 : Support UTF8 source for pod and man (Celogeek San) 4.009 2014-07-08 10:15:09 GMT * Bug #450 : options with format "s" do not accept "0" as value (Celogeek San) 4.008 2014-02-01 09:49:36 GMT * Bug #405 : fix typo in pod (Celogeek San) 4.007 2014-01-17 15:57:22 GMT * Bug #403 : fix pod (Grzegorz Rożniecki) 4.006 2013-12-18 14:31:42 GMT * Bug #388 : Short option not properly fixed (fix_argv) (Celogeek San) 4.005 2013-12-16 12:44:02 GMT * Bug #383: autosplit should handle all variance of "-" and "_" Fix tests (reused vars) 4.004 2013-12-14 13:00:38 GMT * Bug #383: autosplit should handle all variance of "-" and "_" implement a proper fix_argv method 4.003 2013-12-01 00:40:22 GMT * Feature #370 : Add usage, only the usage row with all the long options (Celogeek San) 4.002 2013-11-29 19:07:32 GMT * Feature #380 : global improvement doc (Celogeek San) * Bug #378 : fix pod typo (Celogeek San) * Feature #379 : improve synopsis (Celogeek San) 4.001 2013-11-26 09:15:14 GMT * Bug #377 : older version of perl has different init methods (Celogeek San) 4.000 2013-11-25 19:01:24 GMT * Feature #328 : Rewrite pod (Celogeek San) Fix: Path::Class 0.32 needed for tempfile Fix: import only moox options role methods, not the one need by this module Fix: JSON help format Feature: improve handling of errors (catch everything and display the proper usage methods) Feature: full rewrite pod documentation 3.99 2013-11-13 09:36:51 GMT * Feature #195 : Use pod2usage for help (Celogeek San) 3.98 2013-11-10 13:03:41 GMT * Feature #369 : Add support of List of all subcommand from MooX::Cmd (Celogeek San) 3.97 2013-11-09 13:31:26 GMT * Feature #368 : Improve support of MooX::Cmd (Celogeek San) 3.96 2013-11-06 20:22:43 GMT * Feature #367 : use the command name of the MooX::Cmd if available (Celogeek San) 3.95 2013-11-06 20:06:26 GMT * Feature #366 : Support MooX::Cmd (Celogeek San) 3.94 2013-10-27 17:33:35 GMT * Feature #352 : Rewrite the option text message (Celogeek San) 3.93 2013-10-24 20:15:53 GMT * Feature #350 : Push back Mo support with proper deps (Celogeek San) 3.92 2013-10-24 16:27:01 GMT * Bug #349 : drop Mo support, it use Mouse ! (Celogeek San) 3.91 2013-10-24 16:04:05 GMT * Bug #348 : die if the caller is not able to run "around" or "with" (Celogeek San) 3.90 2013-10-14 20:30:53 GMT * Feature #338 : Add test module in test build required (Celogeek San) 3.89 2013-10-14 18:31:12 GMT * Feature #335 : Fix changes based on kwaleeti (Celogeek San) 3.88 2013-10-12 17:39:25 GMT * Feature #332 : Create real usage_option method, and use it for help message (Celogeek San) 3.87 2013-10-12 14:04:11 GMT * Bug #331 : Fix tests with Mo (Celogeek San) 3.86 2013-09-28 12:38:55 GMT * Feature #329 : Add support config file to get option (Celogeek San) 3.85 2013-09-22 16:06:32 GMT * Feature #309 : Indicate what is expected in the help message (Celogeek San) 3.84 2013-09-12 22:36:54 GMT * Bug #157 : repeatable work only with the original name (Celogeek San) 3.83 2013-05-13 12:35:06 GMT * Bug #211 : Fix README.mkdn (Celogeek San) 3.82 2013-05-13 08:40:27 GMT * Feature #158 : use GRS for release (Celogeek San) 3.81 2013-05-13 * dummy 3.80 2013-04-28 23:46:23 Europe/Paris * Bug #198 : Fix pod, issue with metacpan (Celogeek San) 3.79 2013-04-25 00:12:25 Europe/Paris * Feature #192 : support json mode (Celogeek San) 3.78 2013-04-12 01:16:12 Europe/Paris * Support for prefered commandline (Tom Lanyon) 3.77 2013-01-05 18:23:49 Europe/Paris * Support for dash in option 3.76 2012-12-24 12:47:40 Europe/Paris * Reupload due to pause failure 3.75 2012-12-24 12:46:12 Europe/Paris * Update changes 3.74 2012-12-24 12:36:12 Europe/Paris * [Keedi Kim] : Allow ordering of params (by name by default, can be selected order) 3.73 2012-12-08 20:07:07 Europe/Paris * Add deps 3.72 2012-11-26 00:47:35 Europe/Paris * Change bugtracker and git repository 3.71 2012-09-03 02:18:06 Europe/Paris 3.7 2012-09-03 02:12:10 Europe/Paris 3.6 2012-08-20 00:28:50 Europe/Paris * Fix: autosplit with space * Add: greeding and slides 3.5 2012-08-13 23:34:33 Europe/Paris * working role ! * fix namespace clean * add doc to use it 3.4 2012-08-13 20:34:17 Europe/Paris * disabling failing test * moo is now a necessary deps 3.3 2012-08-13 10:38:16 Europe/Paris * support for namespace::clean * fix issue with default value * move ski_options to the role * move options_meta and options_params to the main package * fix role issues * TODO: make role fully work 3.2 2012-08-12 14:41:26 Europe/Paris * add option skip_options to remove option to the terminal 3.1 2012-08-12 02:45:07 Europe/Paris * Fix is missing 3.0 2012-08-12 02:06:35 Europe/Paris * Full rewrite of MooX::Options * Add easy support to use it in a Role. * Break support of Mouse. 2.4 2012-07-27 02:06:03 Europe/Paris * Fix: Role, wasn't working very well 2.3 2012-07-25 18:48:47 Europe/Paris * Add MooX::Options::Role - You can create role in your module that automatically call MooX::Option 'option' method when the role is imported. 2.2 2012-07-19 12:52:59 Europe/Paris * Fix test for Moo 1.0 2.1 2012-07-17 18:11:38 Europe/Paris * Fix pod 2.0 2012-07-17 18:04:48 Europe/Paris * Add 'documentation', an alternative 'doc' option attribute 1.9 2012-07-17 15:02:42 Europe/Paris * Remove bugs section (duplicate) 1.8 2012-07-16 16:51:44 Europe/Paris * use Dist::Zilla::PluginBundle::Author::Celogeek v0.7 1.7 2012-07-16 14:55:02 Europe/Paris * use Dist::Zilla::PluginBundle::Author::Celogeek 1.6 2012-06-08 11:20 * Change author name 1.5 2012-06-01 01:10 * fix mouse test * add doc, markdown, cleanup 1.4 2012-05-16 23:30 * remove goto method, compat with older perl 1.3 2012-05-12 00:30 * fix minimum version to 5.8.9 * fix test unit 1.2 2012-05-02 02:20 * add advice on repeatable option (Alex Howarth) * full test and 100% coverage * fix import_options and add protection. 1.1 2012-03-13 23:20 * remove min version for testing Moo * remove deps on Mo/Moo/Mouse/Moose from test (if present do the test, else skip) 1.0 2012-03-10 16:00 * use perl 5.006 syntax compatible, allow use MooX::Options with older version 0.9 2012-02-14 21:40 * Add flavour to pass options to GetOpt::Long (zengargoyle) 0.8 2011-12-25 14:30 * use Moo 0.009013 to pass cpantester tests 0.7 2011-12-09 00:10 * change name to MooX::Options * fix Global name (UPPERCASE) * fix Global name (Camel_Case) * fix private name (no more "_") 0.6 2011-12-04 13:00 * add option_usage * add test for it 0.5 2011-12-04 12:20 * fix doc 0.4 2011-12-04 12:00 * fix call chain method (don't call properly because new method was not already generated at the call) * add test for chain_method (should_die_ok) 0.3 2011-12-03 13:00 * fix test unit 0.2 2011-12-02 01:30 * improve help test * fix possible miss reading * Factorize test import_options rename options for import_options (better reading) remove synopsis filter is on by default, can be cancel with \"nofilter\" import doc at the end * add TODO * fix tests for autosplit, add complex autosplit for str with quote * add some better handle of repeatable and negativable, use Data::Record to resplit the args 0.1 2011-11-30 18:30 * First release of MooX::Getopt * Fully compatible with Mo/Moo/Mouse/Moose and more MooX-Options-4.103/coverage.txt000644 000765 000024 00000001276 13146536263 016351 0ustar00snostaff000000 000000 ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ blib/lib/MooX/Options.pm 100.0 100.0 100.0 100.0 n/a 55.1 100.0 ...oX/Options/Descriptive.pm 100.0 n/a n/a 100.0 100.0 6.1 100.0 ...ions/Descriptive/Usage.pm 97.4 80.6 72.7 89.4 100.0 12.7 90.3 .../lib/MooX/Options/Role.pm 98.4 94.1 90.2 100.0 100.0 25.9 96.2 Total 98.6 90.4 90.3 97.8 100.0 100.0 95.6 ---------------------------- ------ ------ ------ ------ ------ ------ ------ MooX-Options-4.103/etc/000755 000765 000024 00000000000 13147041352 014551 5ustar00snostaff000000 000000 MooX-Options-4.103/lib/000755 000765 000024 00000000000 13147041352 014544 5ustar00snostaff000000 000000 MooX-Options-4.103/LICENSE000644 000765 000024 00000043733 13115545420 015015 0ustar00snostaff000000 000000 This software is copyright (c) 2013-2016 by celogeek . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by celogeek . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by celogeek . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MooX-Options-4.103/Makefile.PL000644 000765 000024 00000013205 13135324110 015742 0ustar00snostaff000000 000000 use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker; my %RUN_DEPS = ( "Getopt::Long" => "2.43", "Getopt::Long::Descriptive" => "0.099", "MRO::Compat" => 0, "Module::Runtime" => 0, "Moo" => "1.003", "strictures" => 2, "MooX::Locale::Passthrough" => 0, "Path::Class" => "0.32", "Pod::Usage" => 0, "Text::LineFold" => 0, ); my %CONFIGURE_DEPS = ( 'ExtUtils::MakeMaker' => 0, ); my %BUILD_DEPS = (); my %TEST_DEPS = ( "Test::More" => 0.90, "Test::Trap" => 0, ); WriteMakefile1( MIN_PERL_VERSION => "5.008001", META_ADD => { "meta-spec" => { version => 2 }, dynamic_config => 0, resources => { homepage => "https://metacpan.org/celogeek/MooX-Options", repository => { url => "https://github.com/celogeek/MooX-Options.git", web => "https://github.com/celogeek/MooX-Options", type => "git", }, bugtracker => { web => "http://rt.cpan.org/Public/Dist/Display.html?Name=MooX-Options", mailto => 'bug-MooX-Options@rt.cpan.org', }, license => "http://dev.perl.org/licenses/", }, prereqs => { develop => { requires => { "Test::CPAN::Changes" => 0, "Test::CheckManifest" => 0, "Module::CPANTS::Analyse" => "0.96", "Test::Kwalitee" => 0, "Test::Perl::Critic" => 0, "Test::PerlTidy" => 0, "Test::Pod" => 0, "Test::Pod::Coverage" => 0, "Test::Pod::Spelling::CommonMistakes" => 0, "Test::Spelling" => 0, }, }, configure => { requires => {%CONFIGURE_DEPS}, }, build => { requires => {%BUILD_DEPS} }, test => { requires => {%TEST_DEPS}, recommends => { "Data::Record" => 0, "JSON::MaybeXS" => 0, "Regexp::Common" => 0, }, suggests => { "Mo" => "0.36", "MooX::Cmd" => "0.012", "MooX::ConfigFromFile" => 0, "Moose" => 0, "MooX::Locale::TextDomain::OO" => 0, } }, runtime => { requires => { %RUN_DEPS, perl => "5.8.1", }, recommends => { "Data::Record" => 0, "JSON::MaybeXS" => 0, "Regexp::Common" => 0, }, }, }, }, NAME => "MooX::Options", VERSION_FROM => "lib/MooX/Options.pm", ABSTRACT_FROM => "lib/MooX/Options.pm", LICENSE => "perl", AUTHOR => [ q{celogeek }, q{Jens Rehsack } ], PREREQ_PM => \%RUN_DEPS, CONFIGURE_REQUIRES => \%CONFIGURE_DEPS, BUILD_REQUIRES => \%BUILD_DEPS, TEST_REQUIRES => \%TEST_DEPS, test => { TESTS => "t/*.t xt/*.t" }, ); sub WriteMakefile1 { # originally written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. my %params = @_; my $eumm_version = $ExtUtils::MakeMaker::VERSION; $eumm_version = eval $eumm_version; die "EXTRA_META is deprecated" if ( exists( $params{EXTRA_META} ) ); die "License not specified" if ( !exists( $params{LICENSE} ) ); $params{TEST_REQUIRES} and $eumm_version < 6.6303 and $params{BUILD_REQUIRES} = { %{ $params{BUILD_REQUIRES} || {} }, %{ delete $params{TEST_REQUIRES} } }; #EUMM 6.5502 has problems with BUILD_REQUIRES $params{BUILD_REQUIRES} and $eumm_version < 6.5503 and $params{PREREQ_PM} = { %{ $params{PREREQ_PM} || {} }, %{ delete $params{BUILD_REQUIRES} } }; ref $params{AUTHOR} and "ARRAY" eq ref $params{AUTHOR} and $eumm_version < 6.5702 and $params{AUTHOR} = join( ", ", @{ $params{AUTHOR} } ); delete $params{CONFIGURE_REQUIRES} if ( $eumm_version < 6.52 ); delete $params{MIN_PERL_VERSION} if ( $eumm_version < 6.48 ); delete $params{META_MERGE} if ( $eumm_version < 6.46 ); delete $params{META_ADD}{prereqs} if ( $eumm_version < 6.58 ); delete $params{META_ADD}{"meta-spec"} if ( $eumm_version < 6.58 ); delete $params{META_ADD} if ( $eumm_version < 6.46 ); delete $params{LICENSE} if ( $eumm_version < 6.31 ); delete $params{AUTHOR} if ( $] < 5.005 ); delete $params{ABSTRACT_FROM} if ( $] < 5.005 ); delete $params{BINARY_LOCATION} if ( $] < 5.005 ); # more or less taken from Moose' Makefile.PL if ( $params{CONFLICTS} ) { my $ok = CheckConflicts(%params); exit(0) if ( $params{PREREQ_FATAL} and not $ok ); my $cpan_smoker = grep { $_ =~ m/(?:CR_SMOKER|CPAN_REPORTER|AUTOMATED_TESTING)/ } keys %ENV; unless ( $cpan_smoker || $ENV{PERL_MM_USE_DEFAULT} ) { sleep 4 unless ($ok); } delete $params{CONFLICTS}; } WriteMakefile(%params); } MooX-Options-4.103/MANIFEST000644 000765 000024 00000002341 13147041352 015127 0ustar00snostaff000000 000000 Changes coverage.txt etc/25-with_config.t.json etc/25-with_config_2.t.json lib/MooX/Options.pm lib/MooX/Options/Descriptive.pm lib/MooX/Options/Descriptive/Usage.pm lib/MooX/Options/Manual/Man.pod lib/MooX/Options/Manual/MooXCmd.pod lib/MooX/Options/Manual/NamespaceClean.pod lib/MooX/Options/Role.pm LICENSE Makefile.PL MANIFEST MANIFEST.SKIP po/de.po po/de_DE.po po/MooX-Options.pot README.md t/00-load.t t/01-around_options_usage.t t/02-autosplit_warning_on_required_param.t t/03-check_target_methods.t t/04-doc-utf8.t t/05-doc.t t/06-failure.t t/07-flavour.t t/08-hidden.t t/09-isa_check.t t/10-mo.t t/11-moo.t t/12-moose.t t/13-moox-cmd.t t/14-multi_role.t t/15-multiple-split-options.t t/16-namespace_clean.t t/17-no_option.t t/18-option-of-attr.t t/19-option-of-option.t t/20-order.t t/21-role.t t/22-spacer.t t/23-string_with_zero_value.t t/24-usage_string.t t/25-with_config.t t/26-localization.t t/27-short.t t/base.st t/lib/MooXCmdTest.pm t/lib/MooXCmdTest/Cmd/test1.pm t/lib/MooXCmdTest/Cmd/test1/Cmd/test2.pm t/lib/MooXCmdTest/Cmd/test3.pm t/lib/TestNamespaceClean.pm META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) MooX-Options-4.103/MANIFEST.SKIP000644 000765 000024 00000000477 13115545420 015704 0ustar00snostaff000000 000000 \B\.svn\b \B\.git\b \.gitignore$ \.[Bb][Aa][Kk]$ \.orig$ \.old$ \.tdy$ \.tmp$ \..*swp ^Makefile$ ^Build$ ^Build\.bat$ \.Inline/.* _Inline/.* \.bak$ \.tar$ \.tgz$ \.tar\.gz$ ^mess/ ^tmp/ ^testdata/ ^blib/ ^sandbox/ ^pm_to_blib$ ^cover_db/ ^_build/.* ~$ .*\.planner ^\..* MooX-Options-.* \bxt ^MYMETA\.json$ ^MYMETA\..*$ MooX-Options-4.103/META.json000644 000765 000024 00000005526 13147041352 015427 0ustar00snostaff000000 000000 { "abstract" : "Explicit Options eXtension for Object Class", "author" : [ "celogeek ", "Jens Rehsack " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "MooX-Options", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Module::CPANTS::Analyse" : "0.96", "Test::CPAN::Changes" : "0", "Test::CheckManifest" : "0", "Test::Kwalitee" : "0", "Test::Perl::Critic" : "0", "Test::PerlTidy" : "0", "Test::Pod" : "0", "Test::Pod::Coverage" : "0", "Test::Pod::Spelling::CommonMistakes" : "0", "Test::Spelling" : "0" } }, "runtime" : { "recommends" : { "Data::Record" : "0", "JSON::MaybeXS" : "0", "Regexp::Common" : "0" }, "requires" : { "Getopt::Long" : "2.43", "Getopt::Long::Descriptive" : "0.099", "MRO::Compat" : "0", "Module::Runtime" : "0", "Moo" : "1.003", "MooX::Locale::Passthrough" : "0", "Path::Class" : "0.32", "Pod::Usage" : "0", "Text::LineFold" : "0", "perl" : "v5.8.1", "strictures" : "2" } }, "test" : { "recommends" : { "Data::Record" : "0", "JSON::MaybeXS" : "0", "Regexp::Common" : "0" }, "requires" : { "Test::More" : "0.9", "Test::Trap" : "0" }, "suggests" : { "Mo" : "0.36", "MooX::Cmd" : "0.012", "MooX::ConfigFromFile" : "0", "MooX::Locale::TextDomain::OO" : "0", "Moose" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-MooX-Options@rt.cpan.org", "web" : "http://rt.cpan.org/Public/Dist/Display.html?Name=MooX-Options" }, "homepage" : "https://metacpan.org/celogeek/MooX-Options", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "https://github.com/celogeek/MooX-Options.git", "web" : "https://github.com/celogeek/MooX-Options" } }, "version" : "4.103", "x_serialization_backend" : "JSON::PP version 2.94" } MooX-Options-4.103/META.yml000644 000765 000024 00000002207 13147041352 015250 0ustar00snostaff000000 000000 --- abstract: 'Explicit Options eXtension for Object Class' author: - 'celogeek ' - 'Jens Rehsack ' build_requires: Test::More: '0.9' Test::Trap: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: MooX-Options no_index: directory: - t - inc recommends: Data::Record: '0' JSON::MaybeXS: '0' Regexp::Common: '0' requires: Getopt::Long: '2.43' Getopt::Long::Descriptive: '0.099' MRO::Compat: '0' Module::Runtime: '0' Moo: '1.003' MooX::Locale::Passthrough: '0' Path::Class: '0.32' Pod::Usage: '0' Text::LineFold: '0' perl: v5.8.1 strictures: '2' resources: bugtracker: http://rt.cpan.org/Public/Dist/Display.html?Name=MooX-Options homepage: https://metacpan.org/celogeek/MooX-Options license: http://dev.perl.org/licenses/ repository: https://github.com/celogeek/MooX-Options.git version: '4.103' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' MooX-Options-4.103/po/000755 000765 000024 00000000000 13147041352 014414 5ustar00snostaff000000 000000 MooX-Options-4.103/README.md000644 000765 000024 00000037674 13124420301 015264 0ustar00snostaff000000 000000 # NAME MooX::Options - Explicit Options eXtension for Object Class # SYNOPSIS In myOptions.pm : package myOptions; use Moo; use MooX::Options; option 'show_this_file' => ( is => 'ro', format => 's', required => 1, doc => 'the file to display' ); 1; In myTool.pl : use myOptions; use Path::Class; my $opt = myOptions->new_with_options; print "Content of the file : ", file($opt->show_this_file)->slurp; To use it : perl myTool.pl --show_this_file=myFile.txt Content of the file: myFile content The help message : 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 The usage message : perl myTool.pl --usage USAGE: myTool.pl [ --show_this_file=String ] [ --usage ] [ --help ] [ --man ] The manual : perl myTool.pl --man # DESCRIPTION Create a command line tool with your [Mo](https://metacpan.org/pod/Mo), [Moo](https://metacpan.org/pod/Moo), [Moose](https://metacpan.org/pod/Moose) objects. Everything is explicit. You have an `option` keyword to replace the usual `has` to explicitly use your attribute into the command line. The `option` keyword takes additional parameters and uses [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive) to generate a command line tool. # IMPORTANT CHANGES IN 4.100 ## Enhancing existing attributes One can now convert an existing attribute into an option for obvious reasons. package CommonRole; use Moo::Role; has attr => (is => "ro", ...); sub common_logic { ... } 1; package Suitable::Cmd::CLI; use Moo; use MooX::Cmd; use MooX::Options; with "CommonRole"; option '+attr' => (format => 's', repeatable => 1); sub execute { shift->common_logic } 1; package Suitable::Web::Request::Handler; use Moo; with "CommonRole"; sub all_suits { shift->common_logic } 1; package Suitable::Web; use Dancer2; use Suitable::Web::Request::Handler; set serializer => "JSON"; get '/suits' => sub { $my $reqh = Suitable::Web::Request::Handler->new( attr => config->{suit_attr} ); $reqh->all_suits; }; dance; 1; Of course there more ways to to it, [Jedi](https://metacpan.org/pod/Jedi) or [Catalyst](https://metacpan.org/pod/Catalyst) shall be fine, either. ## Rename negativable into negatable Since users stated that `negativable` is not a reasonable word, the flag is renamed into negatable. Those who will 2020 continue use negativable might or might not be warned about soon depreciation. ## Replace Locale::TextDomain by MooX::Locale::Passthrough [Locale::TextDomain](https://metacpan.org/pod/Locale::TextDomain) is broken (technically and functionally) and causes a lot of people to avoid `MooX::Options` or hack around. Both is unintened. So introduce [MooX::Locale::Passthrough](https://metacpan.org/pod/MooX::Locale::Passthrough) to allow any vendor to add reasonable localization, eg. by composing [MooX::Locale::TextDomain::OO](https://metacpan.org/pod/MooX::Locale::TextDomain::OO) into it's solution and initialize the localization in a reasonable way. ## Make lazy loaded features optional Since some features aren't used on a regular basis, their dependencies have been downgraded to `recommended` or `suggested`. The optional features are: - autosplit This feature allowes one to split option arguments at a defined character and always return an array (implicit flag `repeatable`). option "search_path" => ( is => "ro", required => 1, autosplit => ":", format => "s" ); However, this feature requires following modules are provided: - [Data::Record](https://metacpan.org/pod/Data::Record) - [Regexp::Common](https://metacpan.org/pod/Regexp::Common) - json format This feature allowes one to invoke a script like $ my-tool --json-attr '{ "gem": "sapphire", "color": "blue" }' It might be a reasonable enhancement to _handles_. Handling JSON formatted arguments requires any of those modules are loded: - [JSON::MaybeXS](https://metacpan.org/pod/JSON::MaybeXS) - [JSON::PP](https://metacpan.org/pod/JSON::PP) (in Core since 5.14). ## Decouple autorange and autosplit Until 4.023, any option which had autorange enabled got autosplit enabled, too. Since autosplit might not work correctly and for a reasonable amount of users the fact of $ my-tool --range 1..5 is all they desire, autosplit will enabled only when the dependencies of autosplit are fulfilled. # IMPORTED METHODS The list of the methods automatically imported into your class. ## new\_with\_options It will parse your command line params and your inline params, validate and call the `new` method. myTool --str=ko t->new_with_options()->str # ko t->new_with_options(str => 'ok')->str #ok ## option The `option` keyword replaces the `has` method and adds support for special options for the command line only. See ["OPTION PARAMETERS"](#option-parameters) for the documentation. ## options\_usage | --help It displays the usage message and returns the exit code. my $t = t->new_with_options(); my $exit_code = 1; my $pre_message = "str is not valid"; $t->options_usage($exit_code, $pre_message); This method is also automatically fired if the command option "--help" is passed. myTool --help ## options\_man | --man It displays the manual. my $t = t->new_with_options(); $t->options_man(); This is automatically fired if the command option "--man" is passed. myTool --man ## options\_short\_usage | --usage It displays a short version of the help message. my $t = t->new_with_options(); $t->options_short_usage($exit_code); This is automatically fired if the command option "--usage" is passed. myTool --usage # IMPORT PARAMETERS The list of parameters supported by [MooX::Options](https://metacpan.org/pod/MooX::Options). ## flavour Passes extra arguments for [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive). It is useful if you want to configure [Getopt::Long](https://metacpan.org/pod/Getopt::Long). use MooX::Options flavour => [qw( pass_through )]; Any flavour is passed to [Getopt::Long](https://metacpan.org/pod/Getopt::Long) as a configuration, check the doc to see what is possible. ## protect\_argv By default, `@ARGV` is protected. If you want to do something else on it, use this option and it will change the real `@ARGV`. use MooX::Options protect_argv => 0; ## 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 `option` keyword will just work like an `has`. use MooX::Options skip_options => [qw/multi/]; ## prefer\_commandline By default, arguments passed to `new_with_options` have a higher priority than the command line options. This parameter will give the command line an higher priority. use MooX::Options prefer_commandline => 1; ## with\_config\_from\_file This parameter will load [MooX::Options](https://metacpan.org/pod/MooX::Options) in your module. The config option will be used between the command line and parameters. myTool : use MooX::Options with_config_from_file => 1; In /etc/myTool.json {"test" : 1} ## with\_locale\_textdomain\_oo This Parameter will load [MooX::Locale::TextDomain::OO](https://metacpan.org/pod/MooX::Locale::TextDomain::OO) into your module as well as into [MooX::Options::Descriptive::Usage](https://metacpan.org/pod/MooX::Options::Descriptive::Usage). No further action is taken, no language is chosen - everything keep in control. Please read [Locale::TextDomain::OO](https://metacpan.org/pod/Locale::TextDomain::OO) carefully how to enable the desired translation setup accordingly. # usage\_string This parameter is passed to Getopt::Long::Descriptive::describe\_options() as the first parameter. It is a "sprintf"-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 "USAGE: %c %o". %c will be replaced with what Getopt::Long::Descriptive thinks is the program name (it's computed from $0, see "prog\_name"). %o will be replaced with a list of the short options, as well as the text "\[long options...\]" if any have been defined. 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. Literal "%" characters will need to be written as "%%", just like with "sprintf". ## spacer This indicate the char to use for spacer. Please only use 1 char otherwize the text will be too long. The default char is " ". use MooX::Options space => '+' Then the "spacer\_before" and "spacer\_after" will use it for "man" and "help" message. option 'x' => (is => 'ro', spacer_before => 1, spacer_after => 1); # OPTION PARAMETERS The keyword `option` extend the keyword `has` with specific parameters for the command line. ## doc | documentation Documentation for the command line option. ## long\_doc Documentation for the man page. By default the `doc` parameter will be used. See also [Man parameters](https://metacpan.org/pod/MooX::Options::Manual::Man) to get more examples how to build a nice man page. ## required This attribute indicates that the parameter is mandatory. This attribute is not really used by [MooX::Options](https://metacpan.org/pod/MooX::Options) but ensures that consistent error message will be displayed. ## format Format of the params, same as [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive). - i : integer - i@: array of integer - s : string - s@: array of string - f : float value By default, it's a boolean value. Take a look of available formats with [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive). You need to understand that everything is explicit here. If you use [Moose](https://metacpan.org/pod/Moose) and your attribute has `isa => 'Array[Int]'`, that will **not** imply the format `i@`. ## format json : special format support The parameter will be treated like a json string. option 'hash' => (is => 'ro', json => 1); You can also use the json format option 'hash' => (is => 'ro', format => "json"); myTool --hash='{"a":1,"b":2}' # hash = { a => 1, b => 2 } ## negatable It adds the negative version for the option. option 'verbose' => (is => 'ro', negatable => 1); myTool --verbose # verbose = 1 myTool --no-verbose # verbose = 0 The former name of this flag, negativable, is discouraged - since it's not a word. ## repeatable It appends to the ["format"](#format) the array attribute `@`. I advise to add a default value to your attribute to always have an array. Otherwise the default value will be an undefined value. option foo => (is => 'rw', format => 's@', default => sub { [] }); myTool --foo="abc" --foo="def" # foo = ["abc", "def"] ## autosplit For repeatable option, you can add the autosplit feature with your specific parameters. option test => (is => 'ro', format => 'i@', default => sub {[]}, autosplit => ','); myTool --test=1 --test=2 # test = (1, 2) myTool --test=1,2,3 # test = (1, 2, 3) It will also handle quoted params with the autosplit. option testStr => (is => 'ro', format => 's@', default => sub {[]}, autosplit => ','); myTool --testStr='a,b,"c,d",e,f' # testStr ("a", "b", "c,d", "e", "f") ## 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. option test => (is => 'ro', format => 'i@', 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) It will also handle quoted params like `autosplit`, and will not rangify them. option testStr => (is => 'ro', format => 's@', default => sub {[]}, autorange => 1); myTool --testStr='1,2,"3,a,4",5' # testStr (1, 2, "3,a,4", 5) `autosplit` will be set to ',' if undefined. You may set `autosplit` to a different delimiter than ',' for your group separation, but the range operator '..' cannot be changed. option testStr => (is => 'ro', format => 's@', default => sub {[]}, autorange => 1, autosplit => '-'); myTool --testStr='1-2-3-5..7' # testStr (1, 2, 3, 5, 6, 7) ## short Long option can also have short version or aliased. option 'verbose' => (is => 'ro', short => 'v'); myTool --verbose # verbose = 1 myTool -v # verbose = 1 option 'account_id' => (is => 'ro', format => 'i', short => 'a|id'); myTool --account_id=1 myTool -a=1 myTool --id=1 You can also use a shorter option without attribute : option 'account_id' => (is => 'ro', format => 'i'); myTool --acc=1 myTool --account=1 ## 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 `0`, and options are sorted by their names. option 'at_the_end' => (is => 'ro', order => 999); ## hidden Hide option from doc but still an option you can use on command line. option 'debug' => (is => 'ro', doc => 'hidden'); Or option 'debug' => (is => 'ro', hidden => 1); ## spacer\_before, spacer\_after Add spacer before or after or both the params option 'myoption' => (is => 'ro', spacer_before => 1, spacer_after => 1); # ADDITIONAL MANUALS - [Man parameters](https://metacpan.org/pod/MooX::Options::Manual::Man) - [Using namespace::clean](https://metacpan.org/pod/MooX::Options::Manual::NamespaceClean) - [Manage your tools with MooX::Cmd](https://metacpan.org/pod/MooX::Options::Manual::MooXCmd) # EXTERNAL EXAMPLES - [Slide3D about MooX::Options](http://perltalks.celogeek.com/slides/2012/08/moox-options-slide3d.html) # Translation Translation is now supported. Use the dzil command to update the pot and merge into the po files. - dzil msg-init Create a new language po - dzil msg-scan Scan and generate or update the pot file - dzil msg-merge Update all languages using the pot file ## THANKS - sschober For implementation and German translation. # THANKS - Matt S. Trout (mst) <mst@shadowcat.co.uk> For his patience and advice. - Tomas Doran (t0m) <bobtfish@bobtfish.net> To help me release the new version, and using it :) - Torsten Raudssus (Getty) to use it a lot in [DuckDuckGo](http://duckduckgo.com) (go to see [MooX](https://metacpan.org/pod/MooX) module also) - Jens Rehsack (REHSACK) Use with [PkgSrc](http://www.pkgsrc.org/), and many really good idea ([MooX::Cmd](https://metacpan.org/pod/MooX::Cmd), [MooX::Options](https://metacpan.org/pod/MooX::Options), and more to come I'm sure) - All contributors For improving and add more feature to MooX::Options # SUPPORT You can find documentation for this module with the perldoc command. perldoc MooX::Options You can also look for information at: - RT: CPAN's request tracker (report bugs here) [http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-Options](http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-Options) - AnnoCPAN: Annotated CPAN documentation [http://annocpan.org/dist/MooX-Options](http://annocpan.org/dist/MooX-Options) - CPAN Ratings [http://cpanratings.perl.org/d/MooX-Options](http://cpanratings.perl.org/d/MooX-Options) - Search CPAN [http://search.cpan.org/dist/MooX-Options/](http://search.cpan.org/dist/MooX-Options/) # AUTHOR celogeek <me@celogeek.com> # COPYRIGHT AND LICENSE This software is copyright (c) 2013 by celogeek <me@celogeek.com>. This software is copyright (c) 2017 by Jens Rehsack. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. MooX-Options-4.103/t/000755 000765 000024 00000000000 13147041352 014241 5ustar00snostaff000000 000000 MooX-Options-4.103/t/00-load.t000644 000765 000024 00000001034 13145023421 015553 0ustar00snostaff000000 000000 #!perl use 5.008001; use strict; use warnings FATAL => 'all'; use Test::More; use Moo; use_ok('MooX::Options') or BAIL_OUT("Couldn't load MooX::Options"); use_ok('MooX::Options::Role') or BAIL_OUT("Couldn't load MooX::Options::Role"); use_ok('MooX::Options::Descriptive') or BAIL_OUT("Couldn't load MooX::Options::Descriptive"); use_ok('MooX::Options::Descriptive::Usage') or BAIL_OUT("Couldn't load MooX::Options::Descriptive::Usage"); diag("Testing MooX::Options $MooX::Options::VERSION, Perl $], $^X"); done_testing(); MooX-Options-4.103/t/01-around_options_usage.t000644 000765 000024 00000002232 13145023421 021065 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t; use Moo; use MooX::Options; option 't' => ( is => 'ro', documentation => 'this is a test', ); around [ 'options_usage', 'options_help' ] => sub { my ( $orig, $self, $code, @message ) = @_; $code = 0 if !defined $code; print "This is a pre message\n"; $self->$orig( -1, @message ); print "\nThis is a post message\n"; exit($code) if $code >= 0; }; 1; } my @messages; trap { t->new_with_options( h => 1 ) }; @messages = split( /\n/, $trap->stdout ); is $messages[0], 'This is a pre message', 'Pre message ok' or diag( explain($trap) ); like $messages[1], qr{^USAGE}, 'Usage ok'; is $messages[-1], 'This is a post message', 'Post message ok'; trap { t->new_with_options( help => 1 ) }; @messages = split( /\n/, $trap->stdout ); is $messages[0], 'This is a pre message', 'Pre message ok'; like $messages[1], qr{^USAGE}, 'Usage ok'; is $messages[-1], 'This is a post message', 'Post message ok'; done_testing; MooX-Options-4.103/t/02-autosplit_warning_on_required_param.t000644 000765 000024 00000001475 13145023422 024175 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; BEGIN { use Module::Runtime qw(use_module); eval { use_module("Data::Record"); use_module("Regexp::Common"); } or plan skip_all => "This test needs Data::Record and Regexp::Common"; } { package t; use strict; use warnings; use Moo; use MooX::Options; option 'treq' => ( is => 'ro', documentation => 'this is mandatory', format => 's@', required => 1, autosplit => ",", ); 1; } { local @ARGV = ('--treq'); trap { my $opt = t->new_with_options(); }; like $trap->stderr, qr/Option treq requires an argument/, 'stdout ok'; unlike $trap->stderr, qr/Use of uninitialized/, 'stderr ok'; } done_testing; MooX-Options-4.103/t/03-check_target_methods.t000644 000765 000024 00000002244 13145023422 021012 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; { package t; use Moo; use MooX::Options; option 't' => ( is => 'ro' ); 1; } my $test = t->new_with_options; my %ignore_methods; @ignore_methods{ qw/ TEST:: AUTOLOAD BEGIN BUILD BUILDARGS DEMOLISH DOES AFTER BEFORE EXTENDS HAS ISA CAN __ANON__ DESTROY WITH AROUND / } = (); my @methods; { no strict 'refs'; @methods = sort { $a cmp $b } grep { !exists $ignore_methods{ uc($_) } } keys %{ ref($test) . "::" }; } is_deeply( \@methods, [ qw/ __ __n __p _options_config _options_data _options_prog_name _options_sub_commands new new_with_options option options_help options_man options_short_usage options_usage parse_options t / ], 'methods ok' ) or diag "Found : ", join( ', ', @methods ); done_testing; MooX-Options-4.103/t/04-doc-utf8.t000644 000765 000024 00000001316 13145023422 016275 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t; use Moo; use MooX::Options; option 't' => ( is => 'ro', documentation => 'this is a test with utf8 : ça marche héhé !', ); 1; } { my $opt = t->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/\s+\-t\s+this\sis\sa\stest\swith\sutf8\s:\sça\smarche\shéhé\s\!/x, 'documentation work'; trap { $opt->options_help }; like $trap->stdout, qr/\s+\-t:\n\s+this\sis\sa\stest\swith\sutf8\s:\sça\smarche\shéhé\s\!/x, 'documentation work'; } done_testing; MooX-Options-4.103/t/05-doc.t000644 000765 000024 00000003514 13145023422 015414 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t; use Moo; use MooX::Options; option 't' => ( is => 'ro', documentation => 'this is a test', ); 1; } { package t1; use Moo; use MooX::Options; option 't' => ( is => 'ro', doc => 'this pass first', documentation => 'this is a test', ); 1; } { package t2; use Moo; use strict; use warnings all => 'FATAL'; use Test::More; sub filter_opt { my ( $attr, %opt ) = @_; ok !defined $opt{doc}, 'doc has been filtered'; ok defined $opt{documentation}, 'documentation has been keeped'; return has( $attr, %opt ); } use MooX::Options option_chain_method => 'filter_opt'; option 't' => ( is => 'ro', doc => 'this pass first', documentation => 'this is a test', ); 1; } { my $opt = t->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/\s+\-t\s+this\sis\sa\stest/x, 'documentation work'; trap { $opt->options_help }; like $trap->stdout, qr/\s+\-t:\n\s+this\sis\sa\stest/x, 'documentation work'; } { my $opt = t1->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/\s+\-t\s+this\spass\sfirst/x, 'doc pass first'; trap { $opt->options_help }; like $trap->stdout, qr/\s+\-t:\n\s+this\spass\sfirst/x, 'doc pass first'; } { my $opt = t2->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/\s+\-t\s+this\spass\sfirst/x, 'doc pass first'; trap { $opt->options_help }; like $trap->stdout, qr/\s+\-t:\n\s+this\spass\sfirst/x, 'doc pass first'; } done_testing; MooX-Options-4.103/t/06-failure.t000644 000765 000024 00000011423 13145053402 016276 0ustar00snostaff000000 000000 #!/usr/bin/env perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; use Carp; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ package FailureNegatableWithFormat; use Moo; use MooX::Options; option fail => ( is => 'rw', negatable => 1, format => 'i', ); 1; __EOF__ ; like $@, qr/^Negatable\sparams\sis\snot\susable\swith\snon\sboolean\svalue,\sdon't\spass\sformat\sto\suse\sit\s\!/x, "negatable and format are incompatible"; eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ package FailureNegativableWithFormat; use Moo; use MooX::Options; option fail => ( is => 'rw', negativable => 1, format => 'i', ); 1; __EOF__ ; like $@, qr/^Negatable\sparams\sis\snot\susable\swith\snon\sboolean\svalue,\sdon't\spass\sformat\sto\suse\sit\s\!/x, "negatable and format are incompatible"; for my $ban ( qw/help man usage option new_with_options parse_options options_usage _options_data _options_config/ ) { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ package FailureHelp$ban; use Moo; use MooX::Options; option $ban => ( is => 'rw', ); __EOF__ ; like $@, qr/^You\scannot\suse\san\soption\swith\sthe\sname\s'$ban',\sit\sis\simplied\sby\sMooX::Options/x, "$ban method can't be defined"; } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package FailureRoleMyRole; use Moo::Role; use MooX::Options; option 't' => (is => 'rw'); 1; } { package FailureRole; use Moo; with 'FailureRoleMyRole'; 1; } __EOF__ ; like $@, qr/^Can't\sapply\sFailureRoleMyRole\sto\sFailureRole\s-\smissing\s_options_data,\s_options_config/x, "role could only be apply with a MooX::Options ready package" } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package FailureRedefined; use Moo; sub _options_data {}; sub _options_config {}; use MooX::Options; 1; } __EOF__ ; like $@, qr/^Subroutine\s_options_data\sredefined/x, 'redefined methods'; ok( !FailureRedefined->can('new_with_options'), 'FailureRedefined has crash' ); } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package MissingWith; use MooX::Options; 1; } __EOF__ ; like $@, qr/^\QCan't find the method in ! Ensure to load a Role::Tiny compatible module like Moo or Moose before using MooX::Options.\E/, 'missing with'; } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package MissingAround; sub with {}; use MooX::Options; 1; } __EOF__ ; like $@, qr/^\QCan't find the method in ! Ensure to load a Role::Tiny compatible module like Moo or Moose before using MooX::Options.\E/, 'missing with'; } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package MissingHas; sub with {}; sub around {}; use MooX::Options; 1; } __EOF__ ; like $@, qr/^\QCan't find the method in ! Ensure to load a Role::Tiny compatible module like Moo or Moose before using MooX::Options.\E/, 'missing with'; } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package IllegalShortEnding; use Moo; use MooX::Options; option 'legal' => (is => 'rw', short => 'l!'); 1; } IllegalShortEnding->new_with_options; __EOF__ ; like $@, qr/^cmdline\sargument\s'legal|l!'\sshould\send\swith\sa\sword\scharacter/x, 'illegal short trailing char causes reasonable failure'; } { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package ShortOptionConflict; use Moo; use MooX::Options; option 'l' => (is => 'rw'); option 'legal' => (is => 'rw', short => 'l'); 1; } ShortOptionConflict->new_with_options; __EOF__ ; like $@, qr/^There\sis\salready\san\soption\s'l'\s\-\scan't\suse\sit\sto\sshorten\s'legal'/x, 'short conflict with existing option'; } trap { eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . <<__EOF__ { package NonNegatableNegated; use Moo; use MooX::Options; option 'legal' => (is => 'rw'); 1; } local \@ARGV = ('--no-legal'); NonNegatableNegated->new_with_options; __EOF__ ; }; like $trap->stderr, qr/^Unknown\soption:\sno_legal/x, 'Unexisting negation'; done_testing; MooX-Options-4.103/t/07-flavour.t000644 000765 000024 00000004455 13145023423 016335 0ustar00snostaff000000 000000 #!/usr/bin/env perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package plain; use Moo; use MooX::Options protect_argv => 0; option 'bool' => ( is => 'ro' ); 1; } { package plain2; use Moo; use MooX::Options protect_argv => 0, flavour => undef; option 'bool' => ( is => 'ro' ); 1; } { package FlavourTest; use Moo; use MooX::Options flavour => [qw(pass_through)], protect_argv => 0; option 'bool' => ( is => 'ro' ); 1; } for my $noflavour (qw/plain plain2/) { subtest "unknown option $noflavour" => sub { note "Without flavour $noflavour"; { local @ARGV = ('anarg'); my $plain = $noflavour->new_with_options(); is_deeply( [@ARGV], ['anarg'], "anarg is left" ); } { local @ARGV = ( '--bool', 'anarg' ); my $plain = $noflavour->new_with_options(); is( $plain->bool, 1, "bool was set" ); is_deeply( [@ARGV], ['anarg'], "anarg is left" ); } { local @ARGV = ( '--bool', 'anarg', '--unknown_option' ); my @r = trap { $noflavour->new_with_options() }; is( $trap->exit, 1, "exit code ok" ); like( $trap->stderr, qr/Unknown option: unknown_option/, "and a warning from GLD" ); like( $trap->stderr, qr/USAGE:/, "died with usage message" ); } }; } subtest "flavour" => sub { note "With flavour"; { local @ARGV = ('anarg'); my $flavour_test = FlavourTest->new_with_options(); is_deeply( [@ARGV], ['anarg'], "anarg is left" ); } { local @ARGV = ( '--bool', 'anarg' ); my $flavour_test = FlavourTest->new_with_options(); is( $flavour_test->bool, 1, "bool was set" ); is_deeply( [@ARGV], ['anarg'], "anarg is left" ); } { local @ARGV = ( '--bool', 'anarg', '--unknown_option' ); my $flavour_test = FlavourTest->new_with_options(); is( $flavour_test->bool, 1, "bool was set" ); is_deeply( [@ARGV], [ 'anarg', '--unknown_option' ], "anarg and unknown_option are left" ); } }; done_testing; MooX-Options-4.103/t/08-hidden.t000644 000765 000024 00000001642 13145023423 016106 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; { package t; use Moo; use MooX::Options; option 'visible_option' => ( is => 'ro', doc => 'visible' ); option 'hidden_option_by_doc' => ( is => 'ro', format => 's', doc => 'hidden' ); option 'hidden_option' => ( is => 'ro', format => 's', hidden => 1, doc => 'not visible' ); 1; } trap { local @ARGV = qw(--help); t->new_with_options }; unlike $trap->stdout, qr/hidden_option_by_doc:/, 'hidden by doc'; unlike $trap->stdout, qr/hidden_option:/, 'hidden by option'; like $trap->stdout, qr/visible_option:/, 'visible option'; { local @ARGV = qw(--hidden_option_by_doc=test1 --hidden_option=test2); my $o = t->new_with_options; is $o->hidden_option_by_doc, 'test1', 'hidden by doc exists'; is $o->hidden_option, 'test2', 'hidden by option exists'; } done_testing; MooX-Options-4.103/t/09-isa_check.t000644 000765 000024 00000001034 13145023423 016560 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; { package t; use strict; use warnings; use Moo; use MooX::Options; option 'hero' => ( is => 'ro', doc => 'this is mandatory', format => 's@', isa => sub { die "boop\n" }, ); 1; } { local @ARGV = (qw/--hero batman/); trap { my $opt = t->new_with_options(); }; like $trap->stderr, qr/^boop/, 'stdout ok'; like $trap->stderr, qr/USAGE/, 'stderr ok'; } done_testing; MooX-Options-4.103/t/10-mo.t000644 000765 000024 00000013540 13147002060 015253 0ustar00snostaff000000 000000 #!/usr/bin/env perl use strict; use warnings all => 'FATAL'; use Test::More skip_all => "Mo isn't supported in a reasonable way since method modifiers are requires as well as adding private accessors."; use Test::Trap; use FindBin '$RealBin'; my @autosplit; BEGIN { use Module::Runtime qw(use_module); eval { use_module( "Mo", "0.36" ) } or plan skip_all => "Need Mo (0.36) for this test"; eval { use_module("Data::Record"); use_module("Regexp::Common"); } and @autosplit = ( autosplit => ',' ); } { package tRole; use Moo::Role; use Mo 'default'; use MooX::Options; option 'bool' => ( is => 'ro' ); option 'counter' => ( is => 'ro', repeatable => 1 ); option 'empty' => ( is => 'ro', negatable => 1 ); option 'verbose' => ( is => 'ro', negativable => 1 ); option 'used' => ( is => 'ro' ); option 'unused' => ( is => 'ro', short => 'no_used' ); option 'split' => ( is => 'ro', format => 'i@', @autosplit ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); option 'range' => ( is => 'ro', format => 'i@', autorange => 1 ); 1; } { package t; use Mo; use Role::Tiny::With; with 'tRole'; 1; } { package rRole; use Moo::Role; use Mo 'required'; use MooX::Options; option 'str_req' => ( is => 'ro', format => 's', required => 1 ); 1; } { package r; use Mo; use Role::Tiny::With; with 'rRole'; 1; } { package sp_strRole; use Moo::Role; use Mo; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str1' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str2' => ( is => 'ro', format => 's', @autosplit ); 1; } { package sp_str; use Mo; use Role::Tiny::With; with 'sp_strRole'; 1; } { package sp_str_shortRole; use Moo::Role; use Mo; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit, short => 'z' ); 1; } { package sp_str_short; use Mo; use Role::Tiny::With; with 'sp_str_shortRole'; 1; } { package dRole; use Moo::Role; use Mo 'coerce'; use MooX::Options; option 'should_die_ok' => ( is => 'ro', coerce => sub { die "this will die ok" } ); 1; } { package d; use Mo 'coerce'; use Role::Tiny::With; with 'dRole'; 1; } { package multi_reqRole; use Moo::Role; use Mo 'required'; use MooX::Options; option 'multi_1' => ( is => 'ro', required => 1 ); option 'multi_2' => ( is => 'ro', required => 1 ); option 'multi_3' => ( is => 'ro', required => 1 ); 1; } { package multi_req; use Mo; use Role::Tiny::With; with 'multi_reqRole'; 1; } { package t_docRole; use Moo::Role; use Mo; use MooX::Options; option 't' => ( is => 'ro', doc => 'this is a test' ); 1; } { package t_doc; use Mo; use Role::Tiny::With; with 't_docRole'; 1; } { package t_shortRole; use Moo::Role; use Mo; use MooX::Options; option 'verbose' => ( is => 'ro', short => 'v' ); 1; } { package t_short; use Mo; use Role::Tiny::With; with 't_shortRole'; 1; } { package t_skipoptRole; use Moo::Role; use Mo; use MooX::Options skip_options => [qw/multi/]; option 'multi' => ( is => 'ro' ); 1; } { package t_skipopt; use Mo; use Role::Tiny::With; with 't_skipoptRole'; 1; } { package t_prefer_cliRole; use Moo::Role; use Mo; use MooX::Options prefer_commandline => 1; option 't' => ( is => 'ro', format => 's' ); 1; } { package t_prefer_cli; use Mo; use Role::Tiny::With; with 't_prefer_cliRole'; 1; } { package t_dashRole; use Moo::Role; use Mo; use MooX::Options; option 'start_date' => ( is => 'ro', format => 's', short => 's' ); 1; } { package t_dash; use Mo; use Role::Tiny::With; with 't_dashRole'; 1; } { package t_jsonRole; use Moo::Role; use Mo; use MooX::Options; option 't' => ( is => 'ro', json => 1 ); 1; } { package t_json; use Mo; use Role::Tiny::With; with 't_jsonRole'; 1; } { package t_jsonOptRole; use Moo::Role; use Mo; use MooX::Options; option 't' => ( is => 'ro', format => 'json' ); 1; } { package t_json_opt; use Mo; use Role::Tiny::With; with 't_jsonOptRole'; 1; } { package rg_strRole; use Moo::Role; use Mo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'rs', @autosplit ); option 'range_conflict_str1' => ( is => 'ro', format => 's', autorange => 1 ); option 'range_conflict_str2' => ( is => 'ro', format => 's', autorange => 1 ); 1; } { package rg_str; use Mo; use Role::Tiny::With; with 'rg_strRole'; 1; } { package rg_str_shortRole; use Moo::Role; use Mo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); 1; } { package rg_str_short; use Mo; use Role::Tiny::With; with 'rg_str_shortRole'; 1; } { package rg_str_short_commonRole; use Moo::Role; use Mo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); option 'range_json' => ( is => 'ro', format => 'json', short => 'j' ); 1; } { package rg_str_short_common; use Role::Tiny::With; use Mo; with 'rg_str_short_commonRole'; 1; } subtest "Mo" => sub { note "Test Mo"; do $RealBin . '/base.st'; $@ and diag $@; }; done_testing; MooX-Options-4.103/t/11-moo.t000644 000765 000024 00000007326 13146767135 015464 0ustar00snostaff000000 000000 #!/usr/bin/env perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; use FindBin '$RealBin'; my @autosplit; BEGIN { use Module::Runtime qw(use_module); eval { use_module("Data::Record"); use_module("Regexp::Common"); } and @autosplit = ( autosplit => ',' ); } { package t; use Moo; use MooX::Options; option 'bool' => ( is => 'ro' ); option 'counter' => ( is => 'ro', repeatable => 1 ); option 'empty' => ( is => 'ro', negatable => 1 ); option 'verbose' => ( is => 'ro', negativable => 1 ); option 'used' => ( is => 'ro' ); option 'unused' => ( is => 'ro', short => 'no_used' ); option 'split' => ( is => 'ro', format => 'i@', @autosplit ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); option 'range' => ( is => 'ro', format => 'i@', autorange => 1 ); 1; } { package r; use Moo; use MooX::Options; option 'str_req' => ( is => 'ro', format => 's', required => 1 ); 1; } { package sp_str; use Moo; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str1' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str2' => ( is => 'ro', format => 's', @autosplit ); 1; } { package sp_str_short; use Moo; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit, short => 'z' ); 1; } { package d; use Moo; use MooX::Options; option 'should_die_ok' => ( is => 'ro', isa => sub { die "this will die ok" } ); 1; } { package multi_req; use Moo; use MooX::Options; option 'multi_1' => ( is => 'ro', required => 1 ); option 'multi_2' => ( is => 'ro', required => 1 ); option 'multi_3' => ( is => 'ro', required => 1 ); 1; } { package t_doc; use Moo; use MooX::Options; option 't' => ( is => 'ro', doc => 'this is a test' ); 1; } { package t_short; use Moo; use MooX::Options; option 'verbose' => ( is => 'ro', short => 'v' ); 1; } { package t_skipopt; use Moo; use MooX::Options skip_options => [qw/multi/]; option 'multi' => ( is => 'ro' ); 1; } { package t_prefer_cli; use Moo; use MooX::Options prefer_commandline => 1; option 't' => ( is => 'ro', format => 's' ); 1; } { package t_dash; use Moo; use MooX::Options; option 'start_date' => ( is => 'ro', format => 's', short => 's' ); 1; } { package t_json; use Moo; use MooX::Options; option 't' => ( is => 'ro', json => 1 ); 1; } { package t_json_opt; use Moo; use MooX::Options; option 't' => ( is => 'ro', format => 'json' ); 1; } { package rg_str; use Moo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'rs', @autosplit ); option 'range_conflict_str1' => ( is => 'ro', format => 's', autorange => 1 ); option 'range_conflict_str2' => ( is => 'ro', format => 's', autorange => 1 ); 1; } { package rg_str_short; use Moo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); 1; } { package rg_str_short_common; use Moo; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); option 'range_json' => ( is => 'ro', format => 'json', short => 'j' ); 1; } subtest "Moo" => sub { note "Test Moo"; do $RealBin . '/base.st'; $@ and diag $@; }; done_testing; MooX-Options-4.103/t/12-moose.t000644 000765 000024 00000007530 13145053175 016001 0ustar00snostaff000000 000000 #!/usr/bin/env perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; use FindBin '$RealBin'; my @autosplit; BEGIN { use Module::Runtime qw(use_module); eval { use_module("Moose") } or plan skip_all => 'Need Moose for this test'; eval { use_module("Data::Record"); use_module("Regexp::Common"); } and @autosplit = ( autosplit => ',' ); } { package t; use Moose; use MooX::Options; option 'bool' => ( is => 'ro' ); option 'counter' => ( is => 'ro', repeatable => 1 ); option 'empty' => ( is => 'ro', negatable => 1 ); option 'verbose' => ( is => 'ro', negativable => 1 ); option 'used' => ( is => 'ro' ); option 'unused' => ( is => 'ro', short => 'no_used' ); option 'split' => ( is => 'ro', format => 'i@', @autosplit ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); option 'range' => ( is => 'ro', format => 'i@', autorange => 1 ); 1; } { package r; use Moose; use MooX::Options; option 'str_req' => ( is => 'ro', format => 's', required => 1 ); 1; } { package sp_str; use Moose; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str1' => ( is => 'ro', format => 's', @autosplit ); option 'split_conflict_str2' => ( is => 'ro', format => 's', @autosplit ); 1; } { package sp_str_short; use Moose; use MooX::Options; option 'split_str' => ( is => 'ro', format => 's', @autosplit, short => 'z' ); 1; } { package d; use Moose; use MooX::Options; option 'should_die_ok' => ( is => 'ro', trigger => sub { die "this will die ok" } ); 1; } { package multi_req; use Moose; use MooX::Options; option 'multi_1' => ( is => 'ro', required => 1 ); option 'multi_2' => ( is => 'ro', required => 1 ); option 'multi_3' => ( is => 'ro', required => 1 ); 1; } { package t_doc; use Moose; use MooX::Options; option 't' => ( is => 'ro', doc => 'this is a test' ); 1; } { package t_short; use Moose; use MooX::Options; option 'verbose' => ( is => 'ro', short => 'v' ); 1; } { package t_skipopt; use Moose; use MooX::Options skip_options => [qw/multi/]; option 'multi' => ( is => 'ro' ); 1; } { package t_prefer_cli; use Moose; use MooX::Options prefer_commandline => 1; option 't' => ( is => 'ro', format => 's' ); 1; } { package t_dash; use Moose; use MooX::Options; option 'start_date' => ( is => 'ro', format => 's', short => 's' ); 1; } { package t_json; use Moose; use MooX::Options; option 't' => ( is => 'ro', json => 1 ); 1; } { package t_json_opt; use Moose; use MooX::Options; option 't' => ( is => 'ro', format => 'json' ); 1; } { package rg_str; use Moose; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'rs', @autosplit ); option 'range_conflict_str1' => ( is => 'ro', format => 's', autorange => 1 ); option 'range_conflict_str2' => ( is => 'ro', format => 's', autorange => 1 ); 1; } { package rg_str_short; use Moose; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); 1; } { package rg_str_short_common; use Moose; use MooX::Options; option 'range_str' => ( is => 'ro', format => 's', autorange => 1, short => 'r' ); option 'range_json' => ( is => 'ro', format => 'json', short => 'j' ); 1; } subtest "Moose" => sub { note "Test Moose"; do $RealBin . '/base.st'; $@ and diag $@; }; done_testing; MooX-Options-4.103/t/13-moox-cmd.t000644 000765 000024 00000005671 13145023424 016401 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; use Carp; use File::Spec; use FindBin qw/$RealBin/; BEGIN { eval 'use MooX::Cmd 0.007'; if ($@) { plan skip_all => 'Need MooX::Cmd (0.007) for this test'; exit 0; } } use lib File::Spec->catdir( $RealBin, qw(lib) ); use MooXCmdTest; trap { local @ARGV = ('-h'); MooXCmdTest->new_with_cmd; }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'base command help ok' or diag( explain($trap) ); like $trap->stdout, qr{\QSUB COMMANDS AVAILABLE: test1, test3\E}, 'sub base command help ok'; trap { MooXCmdTest->new->options_man( undef, *STDOUT ); }; like $trap->stdout, qr{NAME\s+\d{2}\-\Qmoox-cmd.t\E}, 'pod name ok'; like $trap->stdout, qr{DESCRIPTION\s+\QThis is a test sub command\E}, 'pod description ok'; like $trap->stdout, qr{SYNOPSIS\s+\d{2}\Q-moox-cmd.t [-h] [long options ...]\E\s+\QThis is a test synopsis\E}, 'pod synopsis ok'; like $trap->stdout, qr{AUTHORS\s+\QCelogeek \E}, 'pod author ok'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_cmd(); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t test1 [-h]\E}, 'subcommand 1 help ok' or diag( explain($trap) ); like $trap->stdout, qr{\QSUB COMMANDS AVAILABLE: test2\E}, 'sub subcommand 1 help ok'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [] ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'no subcommand pass'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [123] ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'no ref params'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [ {} ] ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'bad ref'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [ bless {}, 'MooX::Cmd' ] ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'bad ref'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [ MooXCmdTest->new ] ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t [-h]\E}, 'no command_name filled'; trap { local @ARGV = ( 'test1', '-h' ); MooXCmdTest->new_with_options( command_chain => [ MooXCmdTest->new( command_name => 'mySub' ) ], command_commands => { a => 1, b => 2 } ); }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t mySub [-h]\E}, 'subcommand with mySub name'; like $trap->stdout, qr{\QSUB COMMANDS AVAILABLE: a, b\E}, 'sub subcommand with mySub name'; trap { local @ARGV = ( 'test1', 'test2', '-h' ); MooXCmdTest->new_with_cmd; }; like $trap->stdout, qr{USAGE:\s\d{2}\Q-moox-cmd.t test1 test2 [-h]\E}, 'subcommand 2 ok' or diag( explain($trap) ); done_testing; MooX-Options-4.103/t/14-multi_role.t000644 000765 000024 00000001475 13145023424 017030 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package r1Role; use Moo::Role; use MooX::Options; option 'r1' => ( is => 'ro' ); 1; } { package r2Role; use Moo::Role; use MooX::Options; option 'r2' => ( is => 'ro' ); 1; } { package t; use Moo; use MooX::Options; with 'r1Role', 'r2Role'; option 'r3' => ( is => 'ro' ); 1 } local @ARGV = ( '--r1', '--r2', '--r3' ); my $r; $r = t->new_with_options; ok( $r, 'r is defined' ); if ( defined $r ) { ok( $r->can('r1'), 'r1 exists' ); ok( $r->can('r2'), 'r2 exists' ); ok( $r->can('r3'), 'r3 exists' ); ok( $r->r1(), 'r1 set' ); ok( $r->r2(), 'r2 set' ); ok( $r->r3(), 'r3 set' ); } done_testing; MooX-Options-4.103/t/15-multiple-split-options.t000644 000765 000024 00000001340 13145023425 021323 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; BEGIN { use Module::Runtime qw(use_module); eval { use_module("Data::Record"); use_module("Regexp::Common"); } or plan skip_all => "This test needs Data::Record and Regexp::Common"; } { package TestMultipleSplitOptions; use Moo; use MooX::Options; option 'opt' => ( is => 'ro', format => 'i@', autosplit => ',' ); option 'opt2' => ( is => 'ro', format => 'i@', autosplit => ',' ); 1; } local @ARGV = ( '--opt', '1,2', '--opt2', '3,4' ); my $opt = TestMultipleSplitOptions->new_with_options; is_deeply $opt->opt, [ 1, 2 ], 'opt got split correctly'; is_deeply $opt->opt2, [ 3, 4 ], 'opt2 got split correctly'; done_testing; MooX-Options-4.103/t/16-namespace_clean.t000644 000765 000024 00000001041 13145023425 017743 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::More; use FindBin qw/ $Bin /; use lib "$Bin/lib"; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; BEGIN { use Module::Runtime qw(use_module); eval { use_module("TestNamespaceClean") } or plan skip_all => "This test needs namespace::clean"; } ok( TestNamespaceClean->new, 'TestNamespaceClean is a package' ); { local @ARGV = ( '--foo', '12' ); my $i = TestNamespaceClean->new_with_options; is $i->foo, 12, 'value save properly'; } done_testing; MooX-Options-4.103/t/17-no_option.t000644 000765 000024 00000000363 13145023425 016660 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t; use Moo; use MooX::Options; 1; } my $p = t->new_with_options; ok( $p, 't has options' ); done_testing; MooX-Options-4.103/t/18-option-of-attr.t000644 000765 000024 00000001172 13145023425 017536 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; { package RoleOptOfAttr; use Moo::Role; use MooX::Options; has 'opt' => ( is => 'ro' ); 1; } { package TestOptOfAttr; use Moo; use MooX::Options; with "RoleOptOfAttr"; option '+opt' => ( format => 's' ); } local @ARGV = ( '--opt', 'foo' ); my $opt = TestOptOfAttr->new_with_options; is $opt->opt, 'foo', 'option of option is not changed for separated args'; local @ARGV = ('--opt=bar'); my $opt2 = TestOptOfAttr->new_with_options; is $opt2->opt, 'bar', 'option of option is not changed for glued args'; done_testing; MooX-Options-4.103/t/19-option-of-option.t000644 000765 000024 00000001400 13145023425 020067 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; { package TestOptOfOpt; use Moo; use MooX::Options; option 'opt' => ( is => 'ro', format => 's' ); 1; } local @ARGV = ( '--opt', '--opt -y -my-options' ); my $opt = TestOptOfOpt->new_with_options; is $opt->opt, '--opt -y -my-options', 'option of option is not changed for separated args'; local @ARGV = ('--opt=--opt -y -my-options'); my $opt2 = TestOptOfOpt->new_with_options; is $opt2->opt, '--opt -y -my-options', 'option of option is not changed for glued args'; local @ARGV = ('--op=--opt -y -my-options'); my $opt3 = TestOptOfOpt->new_with_options; is $opt3->opt, '--opt -y -my-options', 'option of option is not changed for shortened args'; done_testing; MooX-Options-4.103/t/20-order.t000644 000765 000024 00000004357 13145023426 015771 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t1; use Moo; use MooX::Options; option 'first' => ( is => 'ro', documentation => 'first option', order => 1, ); option 'second' => ( is => 'ro', documentation => 'second option', order => 2, ); option 'third' => ( is => 'ro', documentation => 'third option', order => 3, ); option 'fourth' => ( is => 'ro', documentation => 'fourth option', order => 4, ); 1; } { package t2; use Moo; use MooX::Options; option 'first' => ( is => 'ro', documentation => 'first option', ); option 'second' => ( is => 'ro', documentation => 'second option', ); option 'third' => ( is => 'ro', documentation => 'third option', ); option 'fourth' => ( is => 'ro', documentation => 'fourth option', ); 1; } { package t3; use Moo; use MooX::Options; option 'first' => ( is => 'ro', documentation => 'first option', order => 1, ); option 'second' => ( is => 'ro', documentation => 'second option', order => 2, ); option 'third' => ( is => 'ro', documentation => 'third option', ); option 'fourth' => ( is => 'ro', documentation => 'fourth option', ); 1; } { my $opt = t1->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/first.+second.+third.+fourth/ms, 'order work w/ order attribute'; } { my $opt = t2->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/first.+fourth.+second.+third/ms, 'order work w/o order attribute'; } { my $opt = t3->new_with_options; trap { $opt->options_usage }; like $trap->stdout, qr/fourth.+third.+first.+second/ms, 'order work w/ mixed mode'; } done_testing; MooX-Options-4.103/t/21-role.t000644 000765 000024 00000003437 13145023426 015616 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package myRole; use strict; use warnings; use Moo::Role; use MooX::Options; option 'multi' => ( is => 'rw', doc => 'multi threading mode' ); 1; } { package testRole; use Moo; use MooX::Options; with 'myRole'; 1; } { package testRole2; use Moo; use MooX::Options skip_options => undef; with 'myRole'; 1; } { package testSkipOpt; use Moo; use MooX::Options skip_options => [qw/multi/], flavour => [qw( pass_through )]; with 'myRole'; 1; } { local @ARGV; @ARGV = (); my $opt = testRole->new_with_options; ok( !$opt->multi, 'multi not set' ); } { local @ARGV; @ARGV = ('--multi'); my $opt = testRole->new_with_options; ok( $opt->multi, 'multi set' ); trap { $opt->options_usage; }; like( $trap->stdout, qr/\-\-multi\s+multi\sthreading\smode/x, "usage method is properly set" ); } { local @ARGV; @ARGV = (); my $opt = testRole2->new_with_options; ok( !$opt->multi, 'multi not set' ); } { local @ARGV; @ARGV = ('--multi'); my $opt = testRole2->new_with_options; ok( $opt->multi, 'multi set' ); trap { $opt->options_usage; }; like( $trap->stdout, qr/\-\-multi\s+multi\sthreading\smode/x, "usage method is properly set" ); } { local @ARGV; @ARGV = ('--multi'); my $opt = testSkipOpt->new_with_options; ok( !$opt->multi, 'multi not set' ); trap { $opt->options_usage; }; ok( $trap->stdout !~ /\-\-multi\s+multi\sthreading\smode/x, "usage method is properly set" ); } done_testing; 1; MooX-Options-4.103/t/22-spacer.t000644 000765 000024 00000001751 13145023426 016130 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; { package t; use Moo; use MooX::Options spacer => '+'; option 'a' => ( is => 'ro' ); option 'b' => ( is => 'ro', spacer_before => 1, spacer_after => 1 ); option 'c' => ( is => 'ro' ); 1; } my $opt = t->new_with_options; my @usages; trap { $opt->options_usage }; @usages = grep {/\-[abc]\s+|\+/} split( /\n/, $trap->stdout ); like $usages[0], qr/a/, 'a is first'; like $usages[1], qr/\++/, 'then the spacer'; like $usages[2], qr/b/, 'b is next'; like $usages[3], qr/\++/, 'then the spacer'; like $usages[4], qr/c/, 'c is last'; trap { $opt->options_help }; @usages = grep {/[abc]:|\+/} split( /\n/, $trap->stdout ); like $usages[0], qr/a:/, 'a is first'; like $usages[1], qr/\++/, 'then the spacer'; like $usages[2], qr/b:/, 'b is next'; like $usages[3], qr/\++/, 'then the spacer'; like $usages[4], qr/c:/, 'c is last'; done_testing; MooX-Options-4.103/t/23-string_with_zero_value.t000644 000765 000024 00000000544 13145023426 021447 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; package Foo; use Moo; use MooX::Options; option start_from => ( is => "ro", format => "s" ); package main; local @ARGV = qw/--start_from 0/; my $f = Foo->new_with_options; my $n = $f->start_from; is $n, 0, 'option with value 0 works'; $n++; is $n, 1, 'and can be increment'; done_testing; MooX-Options-4.103/t/24-usage_string.t000644 000765 000024 00000001063 13145023427 017344 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; { package t; use strict; use warnings; use Moo; use MooX::Options usage_string => 'usage: myprogram %o'; option 'hero' => ( is => 'ro', doc => 'this is mandatory', format => 's@', ); 1; } { local @ARGV = (qw/--bad-option/); trap { my $opt = t->new_with_options(); }; like $trap->stderr, qr/usage: myprogram \[-h\] \[long options/, 'stderr has correct usage'; } done_testing; MooX-Options-4.103/t/25-with_config.t000644 000765 000024 00000006140 13145023427 017154 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; BEGIN { use Module::Runtime qw(use_module); eval { use_module("MooX::ConfigFromFile::Role") } or plan skip_all => "This test needs MooX::ConfigFromFile"; } { package MyTestWithConfig; use Moo; use MooX::Options with_config_from_file => 1; option 'p1' => ( is => 'ro', format => 'i', required => 1 ); option 'p2' => ( is => 'ro', format => 'i@', required => 1 ); 1; } SKIP: { my $t = trap { MyTestWithConfig->new_with_options() }; isa_ok( $t, "MyTestWithConfig" ) or skip "MyTestWithConfig Instantiation failure", 4; is $t->p1, 1, 'p1 fetch from config'; is_deeply $t->p2, [ 1, 2, 3 ], '... and also p2'; ok $t->can('config_prefix'), '... config prefix defined'; ok $t->can('config_dirs'), '... config dirs defined'; ok $t->can('config_files'), '... config files defined'; } SKIP: { local @ARGV = ( '--config_prefix', '25-with_config_2.t' ); my $t = trap { MyTestWithConfig->new_with_options() }; isa_ok( $t, "MyTestWithConfig" ) or skip "MyTestWithConfig Instantiation failure", 2; is $t->p1, 2, 'p1 fetch from config'; is_deeply $t->p2, [ 3, 4, 5 ], '... and also p2'; } SKIP: { local @ARGV = ( '--p1', '2' ); my $t = trap { MyTestWithConfig->new_with_options() }; isa_ok( $t, "MyTestWithConfig" ) or skip "MyTestWithConfig Instantiation failure", 2; is $t->p1, 2, 'p1 fetch from cmdline'; is_deeply $t->p2, [ 1, 2, 3 ], '... and p2 from config'; } SKIP: { local @ARGV = ( '--p1', '2' ); my $t = trap { MyTestWithConfig->new_with_options( p1 => 3 ) }; isa_ok( $t, "MyTestWithConfig" ) or skip "MyTestWithConfig Instantiation failure", 2; is $t->p1, 3, 'p1 fetch from params'; is_deeply $t->p2, [ 1, 2, 3 ], '... and p2 from config'; } eval < 1; option 'p1' => (is => 'ro', format => 'i', required => 1); option 'p2' => (is => 'ro', format => 'i\@', required => 1); 1; EOF ; like $@, qr/\QPlease, don't use the option into a role.\E/x, 'error when try to include with_config_from_file into a role'; eval < 1; option 'p1' => (is => 'ro', format => 'i', required => 1); option 'p2' => (is => 'ro', format => 'i\@', required => 1); option 'config_files' => (is => 'ro'); 1; EOF ; like $@, qr/\QYou cannot use an option with the name 'config_files', it is implied by MooX::Options\E/x, 'keywords when we use config is bannish'; eval < 0; option 'p1' => (is => 'ro', format => 'i', required => 1); option 'p2' => (is => 'ro', format => 'i\@', required => 1); option 'config_files' => (is => 'ro'); 1; EOF ; ok !$@, '... and not without the config option'; done_testing; MooX-Options-4.103/t/26-localization.t000644 000765 000024 00000013216 13145023427 017347 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use FindBin '$Script'; use Test::More; use Test::Trap; BEGIN { use Module::Runtime qw(use_module); eval { use_module("MooX::Locale::TextDomain::OO"); } or plan skip_all => "This test needs MooX::Locale::TextDomain::OO"; } { package t; use strict; use warnings; use Moo; use MooX::Options with_locale_textdomain_oo => 1; option req => ( is => 'ro', documentation => 'this is mandatory', format => 's', required => 1, ); option neg => ( is => 'ro', negatable => 1, documentation => 'this is negatable', ); option paths => ( is => 'ro', repeatable => 1, format => 's', documentation => 'list of some paths', ); 1; } { use Locale::TextDomain::OO::Lexicon::Hash; Locale::TextDomain::OO::Lexicon::Hash->new()->lexicon_ref( { 'de:LC_MESSAGES:example' => [ { msgid => "", msgstr => "Language-Team: none\n" . "Language: de\n" . "MIME-Version: 1.0\n" . "Content-Type: text/plain; charset=ISO-8859-15\n" . "Content-Transfer-Encoding: 8bit\n" . "Plural-Forms: nplurals=2; plural=(n != 1);\n" }, { msgid => "this is mandatory", msgstr => "dies ist erforderlich" }, { msgid => "this is negatable", msgstr => "dieser ist negierbar" }, { msgid => "show a short help message", msgstr => "Zeigt eine kurze Hilfe" }, { msgid => "show a compact help message", msgstr => "Zeigt eine kompakte Hilfe" }, { msgid => "show a long help message", msgstr => "Zeigt eine ausführliche Hilfe" }, { msgid => "show the manual", msgstr => "Zeigt die Anleitung" }, { msgid => "USAGE: %s %s", msgstr => "AUFRUF: %s %s" }, { msgid => "String", msgstr => "Zeichenkette" }, { msgid => "Int", msgstr => "Ganzzahl" }, { msgid => "Ext. Int", msgstr => "erw. Ganzzahl" }, { msgid => "Real", msgstr => "reelle Zahl" }, { msgid => "[Strings]", msgstr => "[Zeichenketten]" }, { msgid => "[Ints]", msgstr => "[Ganzzahlen]" }, { msgid => "[Ext. Ints]", msgstr => "[erw. Ganzzahlen]" }, { msgid => "[Reals]", msgstr => "[reelle Zahlen]" }, { msgid => "Array of Strings", msgstr => "Menge von Zeichenketten" }, { msgid => "Array of Integers", msgstr => "Menge von ganzen Zahlen" }, { msgid => "Extended Integer", msgstr => "erweiterte ganze Zahl" }, { msgid => "Array of extended integers", msgstr => "Menge von erweiterten ganzen Zahlen" }, { msgid => "Real number", msgstr => "reelle Zahl" }, { msgid => "Array of real numbers", msgstr => "Menge von reellen Zahlen" }, { msgid => "SUB COMMANDS AVAILABLE: ", msgstr => "Verfügbare Unterkommandos: " }, { msgid => "long options ...", msgstr => "ausgedehnte Parameter ..." }, ] } ); } { local @ARGV = ('--help'); my $opt = trap { t->new_with_options(); }; like( $trap->stdout, qr{USAGE:\s\Q$Script\E\s\[\-h\]\s\[long\soptions\s\.\.\.\]}x, "Usage itself" ); like( $trap->stdout, qr{this\sis\snegatable}x, "--neg usage" ); like( $trap->stdout, qr{this\sis\smandatory}x, "--req usage" ); like( $trap->stdout, qr{show\sa\sshort\shelp\smessage}x, "--usage usage" ); like( $trap->stdout, qr{show\sa\scompact\shelp\smessage}x, "-h usage" ); like( $trap->stdout, qr{show\sa\slong\shelp\smessage}x, "--help usage" ); like( $trap->stdout, qr{show\sthe\smanual}x, "--man usage" ); } Locale::TextDomain::OO->instance()->language("de"); Locale::TextDomain::OO->instance()->category("LC_MESSAGES"); Locale::TextDomain::OO->instance()->domain("example"); { local @ARGV = ('--help'); my $opt = trap { t->new_with_options(); }; like( $trap->stdout, qr{AUFRUF:\s\Q$Script\E\s\[\-h\]\s\Q[ausgedehnte Parameter ...]\E}x, "Usage itself" ); like( $trap->stdout, qr{dieser\sist\snegierbar}x, "--neg aufruf" ); like( $trap->stdout, qr{dies\sist\serforderlich}x, "--req aufruf" ); like( $trap->stdout, qr{Zeigt\seine\skurze\sHilfe}x, "--usage aufruf" ); like( $trap->stdout, qr{Zeigt\seine\skompakte\sHilfe}x, "-h aufruf" ); like( $trap->stdout, qr{Zeigt\seine\sausführliche\sHilfe}x, "--help aufruf" ); like( $trap->stdout, qr{Zeigt\sdie\sAnleitung}x, "--man aufruf" ); } done_testing; MooX-Options-4.103/t/27-short.t000644 000765 000024 00000002313 13147002060 016003 0ustar00snostaff000000 000000 #!perl use strict; use warnings all => 'FATAL'; use Test::More; use Test::Trap; { package TestSeveralMultipleShort; use Moo; use MooX::Options; option 'lololo' => ( is => 'ro', format => 'i', short => 'l|lolo' ); option 'rororo' => ( is => 'ro', format => 'i', short => 'r|roro' ); option 'lorimi' => ( is => 'ro', format => 'i', short => 'm|lori' ); 1; } SCOPE: { local @ARGV = ( '--r', '1', '--l', '2', '--m', 4 ); my $opt = TestSeveralMultipleShort->new_with_options; is $opt->rororo, 1, 'rororo got shortened correctly'; is $opt->lololo, 2, 'lololo got shortened correctly'; is $opt->lorimi, 4, 'lorimi got shortened correctly'; } SCOPE: { local @ARGV = ( '--lolo', '2', '--roro', '3', '--lori', '5' ); my $opt = TestSeveralMultipleShort->new_with_options; is $opt->lololo, 2, 'lololo got shortened correctly'; is $opt->rororo, 3, 'rororo got shortened correctly'; is $opt->lorimi, 5, 'lorimi got shortened correctly'; } trap { local @ARGV = ( '--ro', '1', '--lo', '1', '--lo', 2 ); TestSeveralMultipleShort->new_with_options; }; like $trap->stderr, qr/Option lo is ambiguous/, "Unable to abbreviate and not argv fix"; done_testing; MooX-Options-4.103/t/base.st000644 000765 000024 00000053362 13147002061 015526 0ustar00snostaff000000 000000 use Module::Runtime qw(use_module); local $ENV{TEST_FORCE_COLUMN_SIZE} = 78; my @params = qw/bool counter empty verbose/; subtest "no args" => sub { note "no args"; local @ARGV = (); my $t = t->new_with_options(); ok( $t->can($_), "$_ defined" ) for @params; is( $t->$_, undef, "$_ values is undef" ) for @params; is( $t->has_default, 'foo', 'Default works correctly' ); done_testing(); }; subtest "args value" => sub { note "args value with repeatable"; local @ARGV = ( ( map {"--$_"} @params ), '--counter', '--counter' ); my $t = t->new_with_options(); note "bool ", $t->bool; note "counter ", $t->counter; note "empty ", $t->empty; ok( $t->$_, "$_ values is defined" ) for @params; is( $t->bool, 1, "bool is well defined" ); is( $t->counter, 3, "counter is well defined" ); is( $t->empty, 1, "empty is well defined" ); is( $t->verbose, 1, "verbose is well defined" ); done_testing(); }; subtest "negatable" => sub { note "negatable"; { local @ARGV = ( '--empty', '--no-empty' ); my $t = t->new_with_options(); is( $t->empty, 0, "empty is well defined" ); } { local @ARGV = ( '--em', '--no-em' ); my $t = t->new_with_options(); is( $t->empty, 0, "empty is well defined" ); } done_testing(); }; subtest "negativable" => sub { note "negativable"; local @ARGV = ( '--verbose', '--no-verbose' ); my $t = t->new_with_options(); is( $t->verbose, 0, "verbose is well defined" ); done_testing(); }; subtest "passthrough" => sub { note "passthrough"; local @ARGV = ( '--split', '1', '--split=2', '--', '3' ); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2 ], "split separated correctly" ); done_testing(); }; subtest "negate_other" => sub { note "negate other"; local @ARGV = ('--no-used'); my $t = t->new_with_options(); is( $t->unused, 1, "unused is well defined" ); done_testing(); }; subtest "split" => sub { note "split"; { local @ARGV = ('--split=1'); my $t = t->new_with_options(); is_deeply( $t->split, [1], "split one arg" ); } { local @ARGV = ( '--split=1', '--split=2' ); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2 ], "split two arg" ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ('--split=1,2'); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2 ], "split one arg autosplit" ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ( '--split=1', '--split=2', '--split=3,4' ); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2, 3, 4 ], "split three arg with autosplit" ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ( '--split', '1', '--split', '2', '--split', '3,4' ); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2, 3, 4 ], "split three arg with autosplit and space" ); } done_testing(); }; subtest "test required" => sub { note "test required"; { local @ARGV = (); my @r = trap { r->new_with_options }; is( $trap->exit, 1, "missing args, exit 1" ); like( $trap->stderr, qr/^str_req is missing/, "str_reg is missing" ); } { local @ARGV = ('--str_req=ok'); my $t = r->new_with_options; is( $t->str_req, 'ok', 'str req is ok' ); } { local @ARGV = (); my @r = trap { multi_req->new_with_options }; is( $trap->exit, 1, "missing args exit 1" ); my @missing = $trap->stderr =~ /(multi_\d is missing)\n/g; my @target_isa; { no strict 'refs'; @target_isa = @{"multi_req::ISA"} }; if ( multi_req->isa('Moose::Object') || multi_req->isa('Mo::Object') ) { is( scalar @missing, 1, "only one missing for moose" ); } else { is( scalar @missing, 3, "multi is missing" ); } } done_testing(); }; subtest "test help" => sub { note "test help"; { local @ARGV = ('--help'); my @r = trap { r->new_with_options }; is( $trap->exit, 0, "help, exit 0" ); ok( $trap->stdout !~ /^str_req is missing/, "str_reg is missing" ); } done_testing(); }; subtest "test short help" => sub { note "test short help"; { local @ARGV = ('--usage'); my @r = trap { r->new_with_options }; is( $trap->exit, 0, "help, exit 0" ); ok( $trap->stdout !~ /^str_req is missing/, "str_reg is missing" ); like $trap->stdout, qr{USAGE:\s\d{2}\-m\w+\Q.t [ --str_req=String ] | [ --usage ] [ -h ] [ --help ] [ --man ]\E}, 'usage message ok'; } done_testing(); }; subtest "test man" => sub { note "test man"; { local @ARGV = ('--man'); my @r = trap { r->new_with_options }; is( $trap->exit, 0, "man, exit 0" ); ok( $trap->stdout !~ /^str_req is missing/, "str_reg is missing" ); } done_testing(); }; subtest "value override" => sub { note "value override"; { local @ARGV = (); my $t = r->new_with_options( str_req => "ok" ); is( $t->str_req, 'ok', 'str req is ok' ); } { local @ARGV = ('--str_req=ko'); my $t = r->new_with_options( str_req => "ok" ); is( $t->str_req, 'ok', 'str req is override with ok' ); } done_testing(); }; subtest "split_complexe_str" => sub { note "split on complexe str"; eval { use_module("Data::Record"); use_module("Regexp::Common"); } or plan skip_all => "This test needs Data::Record and Regexp::Common"; { local @ARGV = ("--split_str=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split-str=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split_conflict_str1=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split_conflict-str1=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split-conflict_str1=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split-conflict-str1=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ('--split_str=a,"b,c",d'); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' ); } { local @ARGV = ('--split-str=a,"b,c",d'); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' ); } done_testing(); }; subtest "split_complexe_str_short" => sub { note "split on complexe str short"; eval { use_module("Data::Record"); use_module("Regexp::Common"); } or plan skip_all => "This test needs Data::Record and Regexp::Common"; { local @ARGV = ("-z=a"); my $t = sp_str_short->new_with_options(); is_deeply( $t->split_str, [qw/a/], 'str req is ok' ); } { local @ARGV = ("-z=a,b,c"); my $t = sp_str_short->new_with_options(); is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ('-z=a,"b,c",d'); my $t = sp_str_short->new_with_options(); is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' ); } { local @ARGV = ( '-z', 'a,"b,c",d' ); my $t = sp_str_short->new_with_options(); is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' ); } done_testing(); }; subtest "split_str_shorter_name" => sub { note "shorter long split"; eval { use_module("Data::Record"); use_module("Regexp::Common"); } or plan skip_all => "This test needs Data::Record and Regexp::Common"; { local @ARGV = ("--split_st=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' ); } { local @ARGV = ("--split-st=a,b,c"); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' ); } note "shorter long split with conflict"; { local @ARGV = ("--split_co=a,b,c"); trap { sp_str->new_with_options(); }; like $trap->stderr, qr/Option\ssplit_co\sis\sambiguous/, 'conflict detected'; local @ARGV = ("--split-co=a,b,c"); trap { sp_str->new_with_options(); }; like $trap->stderr, qr/Option\ssplit_co\sis\sambiguous/, 'conflict detected'; } done_testing(); }; subtest "should_die_ok" => sub { note "Test chain method"; trap { d->new_with_options( should_die_ok => 1 ) }; like( $trap->stderr, qr/this\s\will\sdie\sok/, 'should die ok' ); }; subtest "test usage" => sub { note "test usage method"; my $s = sp_str->new_with_options(); my @r = trap { $s->options_usage( 127, 'usage work', 'usage really work' ) }; is( $trap->exit, 127, 'exit code is correct' ); like( $trap->stderr, qr/usage work/, 'custom message is present' ); like( $trap->stderr, qr/usage really work/, 'custom message is really present' ); like( $trap->stderr, qr/help\s+show a long help message/, 'help is present' ); SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; like( $trap->stderr, qr/split_str=\[Strings\]\s+no doc for split_str/, 'attr no doc is present' ); } }; subtest "test short usage" => sub { note "test usage method"; my $s = sp_str->new_with_options(); my @r = trap { $s->options_short_usage(127) }; is( $trap->exit, 127, 'exit code is correct' ); SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; like $trap->stderr, qr{USAGE:\s\d{2}\-m\w+\Q.t [ --split_conflict_str1=[Strings] ] [ --split_conflict_str2=[Strings] ] [ --split_str=[Strings] ] | [ --usage ] [ -h ] [ --help ] [ --man ]\E}, 'short message ok'; } }; subtest "doc usage" => sub { note "doc usage"; my $s = t_doc->new_with_options(); my @r = trap { $s->options_usage(127) }; is( $trap->exit, 127, 'exit code is correct' ); like( $trap->stderr, qr/t\s+this is a test/, 'doc on attribute' ); }; subtest "test short" => sub { note "test short"; my $s = t_short->new_with_options(); trap { $s->options_usage }; like( $trap->stdout, qr/\-v \-\-verbose/, 'short doc ok' ); }; subtest "test skip_options" => sub { note "test skip_options"; my $s = t_skipopt->new_with_options(); trap { $s->options_usage() }; ok( $trap->stdout !~ /\-\-multi/, 'multi is no more an option' ); }; subtest "test prefer_commandline" => sub { note "test prefer_commandline"; { local @ARGV = ('--t=override'); my $t = t_prefer_cli->new_with_options( t => 'default value' ); is( $t->t, 'override', 'prefer_commandline ok' ); } }; subtest "test dash" => sub { note "test dash"; { local @ARGV = ('--start_date=2012-12-12'); my $t = t_dash->new_with_options(); is( $t->start_date, '2012-12-12', '--start_date ok' ); } { local @ARGV = ('--start-date=2012-12-12'); my $t = t_dash->new_with_options(); is( $t->start_date, '2012-12-12', '--start-date ok' ); } { local @ARGV = ('-s2012-12-12'); my $t = t_dash->new_with_options(); is( $t->start_date, '2012-12-12', '-s ok' ); } }; subtest "json" => sub { note "json"; { local @ARGV = ( "--t", "{\"a\":1,\"b\":2}" ); my $t = t_json->new_with_options(); is_deeply( $t->t, { a => 1, b => 2 }, 'json properly set' ); } { local @ARGV = ( "--t", "bad json" ); my $t = trap { t_json->new_with_options }; like( $trap->stderr, qr/malformed JSON string/, "decode json failed" ); like( $trap->stderr, qr/\-t=JSON/, "json help message properly set" ); } { local @ARGV = ('--help'); my $t = trap { t_json->new_with_options }; note $trap->stdout; like( $trap->stdout, qr/\-t:\sJSON/, "json help message properly set" ); } { trap { t_json->new->options_man( undef, *STDOUT ); }; like( $trap->stdout, qr/\-t: JSON/, "json man message properly set" ) or diag $trap->stdout; } }; subtest "json format" => sub { note "json format"; { local @ARGV = ( "--t", "{\"a\":1,\"b\":2}" ); my $t = t_json_opt->new_with_options(); is_deeply( $t->t, { a => 1, b => 2 }, 'json properly set' ); } { local @ARGV = ( "--t", "bad json" ); my $t = trap { t_json_opt->new_with_options }; ok( $trap->stderr =~ /malformed JSON string/, "decode json failed" ); ok( $trap->stderr =~ /\-t=JSON/, "json help message properly set" ); } { local @ARGV = ('--help'); my $t = trap { t_json_opt->new_with_options }; ok( $trap->stdout =~ /\-t: JSON/, "json help message properly set" ); } { trap { t_json_opt->new->options_man( undef, *STDOUT ); }; ok( $trap->stdout =~ /\-t: JSON/, "json help message properly set" ) or diag $trap->stdout; } }; subtest "range_complexe_str" => sub { note "range on complexe str"; { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=4' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4/], 'str1 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=4' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4/], 'str2 req is ok' ); } { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=4..6' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6/], 'str3 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=4..6' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6/], 'str4 req is ok' ); } { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=..6' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 6/], 'str4 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=..6' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 6/], 'str5 req is ok' ); } { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=4..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4/], 'str6 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=4..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4/], 'str7 req is ok' ); } { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 ../], 'str8 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 ../], 'str9 req is ok' ); } { local @ARGV = ( '--range_str=1', '--range_str=2', '--range_str=4..7', '--range_str=10' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6 7 10/], 'str10 req is ok' ); } { local @ARGV = ( '--range-str=1', '--range-str=2', '--range-str=4..7', '--range-str=10' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6 7 10/], 'str11 req is ok' ); } { local @ARGV = ( '--range_str=1..3', '--range_str=10..12', '--range_str=20..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 10 11 12 20/], 'str12 req is ok' ); } { local @ARGV = ( '--range_str=1..3', '--range_str=10..12', '--range_str=20..' ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 10 11 12 20/], 'str13 req is ok' ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ('--range_str=1..3,10..12,20..'); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 10 11 12 20/], 'str14 req is ok' ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ('--range-str=1..3,10..12,20..'); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 10 11 12 20/], 'str15 req is ok' ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ('--range_str=1,"2,3",4,"foo bar"'); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [ 1, "2,3", 4, "foo bar" ], 'str16 req is ok' ); } SKIP: { eval { use_module("Data::Record"); use_module("Regexp::Common"); } or skip "This test needs Data::Record and Regexp::Common", 1; local @ARGV = ('--range-str=1,"2,3",4,"a,2,c"'); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [ 1, "2,3", 4, "a,2,c" ], 'str17 req is ok' ); } done_testing(); }; subtest "range_complexe_str_short" => sub { note "range on complexe str short"; { local @ARGV = ("-r=1"); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1/], 'str1 req is ok' ); } { local @ARGV = ( "-r=1", "-r=2", "-r=4" ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4/], 'str2 req is ok' ); } { local @ARGV = ("-r=1..4"); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 4/], 'str3 req is ok' ); } { local @ARGV = ( '-r', "1..4" ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 4/], 'str4 req is ok' ); } { local @ARGV = ( "-r=1", "-r=2", "-r=4..7", "-r=10" ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6 7 10/], 'str5 req is ok' ); } { local @ARGV = ( '-r', '1..3', '-r=10..12', '-r=20..' ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 10 11 12 20/], 'str6 req is ok' ); } { local @ARGV = ( '-r=1', '-r="2,3"', '-r=4' ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [ '1', "2,3", '4' ], 'str7 req is ok' ); } { local @ARGV = ( '-r', '1', '-r', '"2,3"', '-r', '4..7' ); my $t = rg_str_short->new_with_options(); is_deeply( $t->range_str, [ 1, "2,3", 4, 5, 6, 7 ], 'str8 req is ok' ); } done_testing(); }; subtest "range_str_shorter_name" => sub { note "shorter long range"; { local @ARGV = ( "--range_st=1", "--rs", "2", "--range_s=4..6" ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6/], 'str1 req is ok' ); } { local @ARGV = ( "--range-st=1", "--rs=2", "--range_s", "4..6", "--rs", "7" ); my $t = rg_str->new_with_options(); is_deeply( $t->range_str, [qw/1 2 4 5 6 7/], 'str2 req is ok' ); } note "shorter long range with conflict"; { local @ARGV = ("--range_co=1,2,3"); trap { rg_str->new_with_options(); }; like $trap->stderr, qr/Option\srange_co\sis\sambiguous/, 'conflict detected'; local @ARGV = ("--range-co=1,2,3"); trap { rg_str->new_with_options(); }; like $trap->stderr, qr/Option\srange_co\sis\sambiguous/, 'conflict detected'; } done_testing(); }; subtest "range_str_short_with_overlapping_abbrev" => sub { note "shorter but common abbreviation"; { local @ARGV = ( "-r", "1..4", "-j", "[ 1, 2, 3, 4 ]" ); my $t = rg_str_short_common->new_with_options(); is_deeply( $t->range_str, [qw/1 2 3 4/], 'str1 req is ok' ); is_deeply( $t->range_json, [qw/1 2 3 4/], 'str1 json is ok' ); } }; 1; MooX-Options-4.103/t/lib/000755 000765 000024 00000000000 13147041352 015007 5ustar00snostaff000000 000000 MooX-Options-4.103/t/lib/MooXCmdTest/000755 000765 000024 00000000000 13147041352 017155 5ustar00snostaff000000 000000 MooX-Options-4.103/t/lib/MooXCmdTest.pm000644 000765 000024 00000000457 13145023430 017514 0ustar00snostaff000000 000000 package MooXCmdTest; use strict; use warnings all => 'FATAL'; use Moo; use MooX::Cmd; use MooX::Options authors => 'Celogeek ', description => 'This is a test sub command', synopsis => 'This is a test synopsis'; sub execute { die "need a sub command !"; } 1; MooX-Options-4.103/t/lib/TestNamespaceClean.pm000644 000765 000024 00000000257 13145023431 021044 0ustar00snostaff000000 000000 package TestNamespaceClean; use Moo; use MooX::Options; use namespace::clean -except => [qw/_options_data _options_config/]; option foo => ( is => 'ro', format => 's' ); 1; MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/000755 000765 000024 00000000000 13147041352 017660 5ustar00snostaff000000 000000 MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/test1/000755 000765 000024 00000000000 13147041352 020720 5ustar00snostaff000000 000000 MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/test1.pm000644 000765 000024 00000000234 13145023430 021250 0ustar00snostaff000000 000000 package MooXCmdTest::Cmd::test1; use strict; use warnings all => 'FATAL'; use Moo; use MooX::Cmd; use MooX::Options; sub execute { die "test1"; } 1; MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/test3.pm000644 000765 000024 00000000234 13145023430 021252 0ustar00snostaff000000 000000 package MooXCmdTest::Cmd::test3; use strict; use warnings all => 'FATAL'; use Moo; use MooX::Cmd; use MooX::Options; sub execute { die "test3"; } 1; MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/test1/Cmd/000755 000765 000024 00000000000 13147041352 021423 5ustar00snostaff000000 000000 MooX-Options-4.103/t/lib/MooXCmdTest/Cmd/test1/Cmd/test2.pm000644 000765 000024 00000000251 13145023430 023013 0ustar00snostaff000000 000000 package MooXCmdTest::Cmd::test1::Cmd::test2; use strict; use warnings all => 'FATAL'; use Moo; use MooX::Cmd; use MooX::Options; sub execute { die "test2"; } 1; MooX-Options-4.103/po/de.po000644 000765 000024 00000007312 13105326762 015354 0ustar00snostaff000000 000000 # German translations for MooX-Options package. # Copyright (C) 2015 celogeek # This file is distributed under the same license as the MooX-Options package. # Automatically generated, 2015. # msgid "" msgstr "" "Project-Id-Version: MooX-Options 4.009\n" "Report-Msgid-Bugs-To: me@celogeek.com\n" "POT-Creation-Date: 2015-05-01 13:45+0400\n" "PO-Revision-Date: 2015-05-01 13:46+0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ASCII\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.7.4\n" #: lib/MooX/Options.pm:102 #, perl-brace-format msgid "" "Can't find the method <{needed_methods}> in <{target}> ! Ensure to load a " "Role::Tiny compatible module like Moo or Moose before using MooX::Options." msgstr "" "Kann die Methode <{needed_methods}> nicht in <{target}> finden! Stellen Sie " "sicher, dass ein Role::Tiny kompatibles Modul, wie Moo oder Moose geladen " "ist, bevor Sie MooX::Options benutzen." #: lib/MooX/Options.pm:147 msgid "Please, don't use the option into a role." msgstr "" "Bitte, komponieren Sie die Option nicht in eine " "Rolle." #: lib/MooX/Options.pm:191 #, perl-brace-format msgid "" "You cannot use an option with the name '{ban}', it is implied by MooX::" "Options" msgstr "" "Sie koennen eine Option mit Namen '{ban}' nicht einsetzen, da diese bereits " "von MooX::Options impliziert wird." #: lib/MooX/Options.pm:250 msgid "" "Negativable params is not usable with non boolean value, don't pass format " "to use it !" msgstr "" "Ungueltige Formatspezifikation. Negierbare Parameter sind mit Bool'schen " "Werten nicht einsetzbar." #: lib/MooX/Options/Descriptive/Usage.pm:38 #: lib/MooX/Options/Descriptive/Usage.pm:51 msgid "String" msgstr "Zeichenkette" #: lib/MooX/Options/Descriptive/Usage.pm:39 msgid "[Strings]" msgstr "[Zeichenketten]" #: lib/MooX/Options/Descriptive/Usage.pm:40 msgid "Int" msgstr "Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:41 msgid "[Ints]" msgstr "[Ganzzahlen]" #: lib/MooX/Options/Descriptive/Usage.pm:42 msgid "Ext. Int" msgstr "Erw. Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:43 msgid "[Ext. Ints]" msgstr "[Erw. Ganzzahl]" #: lib/MooX/Options/Descriptive/Usage.pm:44 msgid "Real" msgstr "Reelle Zahl" #: lib/MooX/Options/Descriptive/Usage.pm:45 msgid "[Reals]" msgstr "[Reelle Zahlen]" #: lib/MooX/Options/Descriptive/Usage.pm:52 msgid "Array of Strings" msgstr "Array von Zeichenketten" #: lib/MooX/Options/Descriptive/Usage.pm:53 msgid "Integer" msgstr "Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:54 msgid "Array of Integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:55 msgid "Extended Integer" msgstr "Erweiterte Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:56 msgid "Array of extended integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:57 msgid "Real number" msgstr "Reelle Zahl" #: lib/MooX/Options/Descriptive/Usage.pm:58 msgid "Array of real numbers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:113 msgid "SUB COMMANDS AVAILABLE: " msgstr "Unterkommandos verfuegbar" #: lib/MooX/Options/Descriptive/Usage.pm:211 #: lib/MooX/Options/Descriptive/Usage.pm:250 msgid "long options ..." msgstr "Langoptionen ..." #: lib/MooX/Options/Role.pm:314 #, perl-format, perl-brace-format msgid "USAGE: {prog_name} %o" msgstr "Aufruf: {prog_name} %o" #: lib/MooX/Options/Role.pm:320 msgid "show a short help message" msgstr "Ein kurzer Hilfetext" #: lib/MooX/Options/Role.pm:321 msgid "show a help message" msgstr "Zeige einen Hilfetext" #: lib/MooX/Options/Role.pm:322 msgid "show the manual" msgstr "Zeige das Handbuch" MooX-Options-4.103/po/de_DE.po000644 000765 000024 00000007373 13105326762 015733 0ustar00snostaff000000 000000 # German translations for MooX-Options package # German translation for MooX-Options. # Copyright (C) 2015 celogeek # This file is distributed under the same license as the MooX-Options package. # Automatically generated, 2015. # msgid "" msgstr "" "Project-Id-Version: MooX-Options 4.019\n" "Report-Msgid-Bugs-To: me@celogeek.com\n" "POT-Creation-Date: 2015-05-01 13:45+0400\n" "PO-Revision-Date: 2015-05-01 13:46+0400\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 1.7.4\n" #: lib/MooX/Options.pm:102 #, perl-brace-format msgid "" "Can't find the method <{needed_methods}> in <{target}> ! Ensure to load a " "Role::Tiny compatible module like Moo or Moose before using MooX::Options." msgstr "" "Kann die Methode <{needed_methods}> nicht in <{target}> finden! Stellen Sie " "sicher, dass ein Role::Tiny kompatibles Modul, wie Moo oder Moose geladen " "ist, bevor Sie MooX::Options benutzen." #: lib/MooX/Options.pm:147 msgid "Please, don't use the option into a role." msgstr "" "Bitte, komponieren Sie die Option nicht in eine " "Rolle." #: lib/MooX/Options.pm:191 #, perl-brace-format msgid "" "You cannot use an option with the name '{ban}', it is implied by MooX::" "Options" msgstr "" "Sie können eine Option mit Namen '{ban}' nicht einsetzen, da diese bereits " "von MooX::Options impliziert wird." #: lib/MooX/Options.pm:250 msgid "" "Negativable params is not usable with non boolean value, don't pass format " "to use it !" msgstr "" "Ungültige Formatspezifikation. Negierbare Parameter sind mit Bool'schen " "Werten nicht einsetzbar." #: lib/MooX/Options/Descriptive/Usage.pm:38 #: lib/MooX/Options/Descriptive/Usage.pm:51 msgid "String" msgstr "Zeichenkette" #: lib/MooX/Options/Descriptive/Usage.pm:39 msgid "[Strings]" msgstr "[Zeichenketten]" #: lib/MooX/Options/Descriptive/Usage.pm:40 msgid "Int" msgstr "Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:41 msgid "[Ints]" msgstr "[Ganzzahlen]" #: lib/MooX/Options/Descriptive/Usage.pm:42 msgid "Ext. Int" msgstr "Erw. Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:43 msgid "[Ext. Ints]" msgstr "[Erw. Ganzzahl]" #: lib/MooX/Options/Descriptive/Usage.pm:44 msgid "Real" msgstr "Reelle Zahl" #: lib/MooX/Options/Descriptive/Usage.pm:45 msgid "[Reals]" msgstr "[Reelle Zahlen]" #: lib/MooX/Options/Descriptive/Usage.pm:52 msgid "Array of Strings" msgstr "Array von Zeichenketten" #: lib/MooX/Options/Descriptive/Usage.pm:53 msgid "Integer" msgstr "Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:54 msgid "Array of Integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:55 msgid "Extended Integer" msgstr "Erweiterte Ganzzahl" #: lib/MooX/Options/Descriptive/Usage.pm:56 msgid "Array of extended integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:57 msgid "Real number" msgstr "Reelle Zahl" #: lib/MooX/Options/Descriptive/Usage.pm:58 msgid "Array of real numbers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:113 msgid "SUB COMMANDS AVAILABLE: " msgstr "Verfügbare Unterkommandos: " #: lib/MooX/Options/Descriptive/Usage.pm:211 #: lib/MooX/Options/Descriptive/Usage.pm:250 msgid "long options ..." msgstr "Langoptionen ..." #: lib/MooX/Options/Role.pm:314 #, perl-format, perl-brace-format msgid "USAGE: {prog_name} %o" msgstr "Aufruf: {prog_name} %o" #: lib/MooX/Options/Role.pm:320 msgid "show a short help message" msgstr "Zeige einen kurzen Hilfetext" #: lib/MooX/Options/Role.pm:321 msgid "show a help message" msgstr "Zeige einen Hilfetext" #: lib/MooX/Options/Role.pm:322 msgid "show the manual" msgstr "Zeige das Handbuch" MooX-Options-4.103/po/MooX-Options.pot000644 000765 000024 00000005562 13105326762 017470 0ustar00snostaff000000 000000 # SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR celogeek # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: MooX-Options 4.018\n" "Report-Msgid-Bugs-To: me@celogeek.com\n" "POT-Creation-Date: 2015-05-01 13:45+0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: lib/MooX/Options.pm:102 #, perl-brace-format msgid "" "Can't find the method <{needed_methods}> in <{target}> ! Ensure to load a " "Role::Tiny compatible module like Moo or Moose before using MooX::Options." msgstr "" #: lib/MooX/Options.pm:147 msgid "Please, don't use the option into a role." msgstr "" #: lib/MooX/Options.pm:191 #, perl-brace-format msgid "" "You cannot use an option with the name '{ban}', it is implied by MooX::" "Options" msgstr "" #: lib/MooX/Options.pm:250 msgid "" "Negativable params is not usable with non boolean value, don't pass format " "to use it !" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:38 #: lib/MooX/Options/Descriptive/Usage.pm:51 msgid "String" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:39 msgid "[Strings]" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:40 msgid "Int" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:41 msgid "[Ints]" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:42 msgid "Ext. Int" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:43 msgid "[Ext. Ints]" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:44 msgid "Real" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:45 msgid "[Reals]" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:52 msgid "Array of Strings" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:53 msgid "Integer" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:54 msgid "Array of Integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:55 msgid "Extended Integer" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:56 msgid "Array of extended integers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:57 msgid "Real number" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:58 msgid "Array of real numbers" msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:113 msgid "SUB COMMANDS AVAILABLE: " msgstr "" #: lib/MooX/Options/Descriptive/Usage.pm:211 #: lib/MooX/Options/Descriptive/Usage.pm:250 msgid "long options ..." msgstr "" #: lib/MooX/Options/Role.pm:314 #, perl-format, perl-brace-format msgid "USAGE: {prog_name} %o" msgstr "" #: lib/MooX/Options/Role.pm:320 msgid "show a short help message" msgstr "" #: lib/MooX/Options/Role.pm:321 msgid "show a help message" msgstr "" #: lib/MooX/Options/Role.pm:322 msgid "show the manual" msgstr "" MooX-Options-4.103/lib/MooX/000755 000765 000024 00000000000 13147041352 015426 5ustar00snostaff000000 000000 MooX-Options-4.103/lib/MooX/Options/000755 000765 000024 00000000000 13147041352 017061 5ustar00snostaff000000 000000 MooX-Options-4.103/lib/MooX/Options.pm000755 000765 000024 00000054004 13147036675 017441 0ustar00snostaff000000 000000 package MooX::Options; use strictures 2; our $VERSION = "4.103"; use Carp ('croak'); use Module::Runtime qw(use_module); my @OPTIONS_ATTRIBUTES = qw/format short repeatable negatable autosplit autorange doc long_doc order json hidden spacer_before spacer_after/; sub import { my ( undef, @import ) = @_; my $options_config = { protect_argv => 1, flavour => [], skip_options => [], prefer_commandline => 0, with_config_from_file => 0, with_locale_textdomain_oo => 0, usage_string => undef, #long description (manual) description => undef, authors => [], synopsis => undef, spacer => " ", @import }; my $target = caller; for my $needed_methods (qw/with around has/) { next if $target->can($needed_methods); croak( "Can't find the method <$needed_methods> in <$target>!\n" . "Ensure to load a Role::Tiny compatible module like Moo or Moose before using MooX::Options." ); } my $with = $target->can('with'); my $around = $target->can('around'); my $has = $target->can('has'); my @target_isa; { no strict 'refs'; @target_isa = @{"${target}::ISA"} }; if (@target_isa) { #only in the main class, not a role ## no critic (ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval, ValuesAndExpressions::ProhibitImplicitNewlines) eval "#line ${\(__LINE__+1 . ' ' . __FILE__)}\n" . '{ package ' . $target . '; use MRO::Compat (); sub _options_data { my ( $class, @meta ) = @_; return $class->maybe::next::method(@meta); } sub _options_config { my ( $class, @params ) = @_; return $class->maybe::next::method(@params); } 1; }'; croak($@) if $@; $around->( _options_config => sub { my ( $orig, $self ) = ( shift, shift ); return $self->$orig(@_), %$options_config; } ); ## use critic } else { if ( $options_config->{with_config_from_file} ) { croak( "Please, don't use the option into a role." ); } } my $options_data = {}; if ( $options_config->{with_config_from_file} ) { $options_data->{config_prefix} = { format => 's', doc => 'config prefix', order => 0, }; $options_data->{config_files} = { format => 's@', doc => 'config files', order => 0, }; } my $apply_modifiers = sub { return if $target->can('new_with_options'); $with->('MooX::Options::Role'); if ( $options_config->{with_config_from_file} ) { $with->('MooX::ConfigFromFile::Role'); } if ( $options_config->{with_locale_textdomain_oo} ) { $with->('MooX::Locale::TextDomain::OO'); use_module("MooX::Options::Descriptive::Usage"); MooX::Options::Descriptive::Usage->can("localizer") or MooX::Options::Descriptive::Usage->can("with") ->("MooX::Locale::TextDomain::OO"); } $around->( _options_data => sub { my ( $orig, $self ) = ( shift, shift ); return ( $self->$orig(@_), %$options_data ); } ); }; my @banish_keywords = qw/h help man usage option new_with_options parse_options options_usage _options_data _options_config/; if ( $options_config->{with_config_from_file} ) { push @banish_keywords, qw/config_files config_prefix config_dirs/; } my $option = sub { my ( $name, %attributes ) = @_; for my $ban (@banish_keywords) { croak( "You cannot use an option with the name '$ban', it is implied by MooX::Options" ) if $name eq $ban; } my %_moo_attrs = _filter_attributes(%attributes); $has->( $name => %_moo_attrs ) if %_moo_attrs; ## no critic (RegularExpressions::RequireExtendedFormatting) $name =~ s/^\+//; # one enhances an attribute being an option $options_data->{$name} = { _validate_and_filter_options(%attributes) }; $apply_modifiers->(); return; }; if ( my $info = $Role::Tiny::INFO{$target} ) { $info->{not_methods}{$option} = $option; } { no strict 'refs'; *{"${target}::option"} = $option; } $apply_modifiers->(); return; } my %filter_key = map { $_ => 1 } ( @OPTIONS_ATTRIBUTES, 'negativable' ); sub _filter_attributes { my %attributes = @_; return map { ( $_ => $attributes{$_} ) } grep { !exists $filter_key{$_} } keys %attributes; } sub _validate_and_filter_options { my (%options) = @_; $options{doc} = $options{documentation} if !defined $options{doc}; $options{order} = 0 if !defined $options{order}; if ( $options{json} || ( defined $options{format} && $options{format} eq 'json' ) ) { delete $options{repeatable}; delete $options{autosplit}; delete $options{autorange}; delete $options{negativable}; delete $options{negatable}; $options{json} = 1; $options{format} = 's'; } if ( $options{autorange} and not defined $options{autosplit} ) { # XXX maybe we should warn here since a previously beloved feature isn't enabled automatically eval { use_module("Data::Record"); use_module("Regexp::Common"); } and $options{autosplit} = ','; } exists $options{negativable} and $options{negatable} = delete $options{negativable}; my %cmdline_options = map { ( $_ => $options{$_} ) } grep { exists $options{$_} } @OPTIONS_ATTRIBUTES, 'required'; $cmdline_options{repeatable} = 1 if $cmdline_options{autosplit} or $cmdline_options{autorange}; $cmdline_options{format} .= "@" if $cmdline_options{repeatable} && defined $cmdline_options{format} && substr( $cmdline_options{format}, -1 ) ne '@'; croak( "Negatable params is not usable with non boolean value, don't pass format to use it !" ) if ( $cmdline_options{negatable} ) and defined $cmdline_options{format}; return %cmdline_options; } 1; __END__ =head1 NAME MooX::Options - Explicit Options eXtension for Object Class =head1 SYNOPSIS In myOptions.pm : package myOptions; use Moo; use MooX::Options; option 'show_this_file' => ( is => 'ro', format => 's', required => 1, doc => 'the file to display' ); 1; In myTool.pl : use myOptions; use Path::Class; my $opt = myOptions->new_with_options; print "Content of the file : ", file($opt->show_this_file)->slurp; To use it : perl myTool.pl --show_this_file=myFile.txt Content of the file: myFile content The help message : 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 The usage message : perl myTool.pl --usage USAGE: myTool.pl [ --show_this_file=String ] [ --usage ] [ --help ] [ --man ] The manual : perl myTool.pl --man =head1 DESCRIPTION Create a command line tool with your L, L objects. Everything is explicit. You have an C