t000755001752001752 012144156710 15170 5ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83mo.t100644001752001752 726612144156710 16143 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; use Carp; use FindBin qw/$RealBin/; use Try::Tiny; BEGIN { use Module::Load::Conditional qw/check_install/; plan skip_all => 'Need Mo for this test' unless check_install( module => 'Mo' ); } { 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', negativable => 1 ); option 'split' => ( is => 'ro', format => 'i@', autosplit => ',' ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); 1; } { package t; use Mo; use Role::Tiny::With; with 'tRole'; 1; } { package rRole; use Moo::Role; use Mo; 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 => "," ); 1; } { package sp_str; use Mo; use Role::Tiny::With; with 'sp_strRole'; 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; 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; } subtest "Mo" => sub { note "Test Mo"; require $RealBin . '/base.st'; }; done_testing; MooX-Options-3.83000755001752001752 012144156710 15004 5ustar00gitlab_cigitlab_ci000000000000README100644001752001752 51012144156710 15721 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83 This archive contains the distribution MooX-Options, version 3.83: add option keywords to your object (Mo/Moo/Moose) This software is copyright (c) 2011 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. Changes100644001752001752 1122512144156710 16401 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.833.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 * 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 moo.t100644001752001752 441312144156710 16311 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; use Carp; use FindBin qw/$RealBin/; use Try::Tiny; { package t; use Moo; use MooX::Options; option 'bool' => ( is => 'ro' ); option 'counter' => ( is => 'ro', repeatable => 1 ); option 'empty' => ( is => 'ro', negativable => 1 ); option 'split' => ( is => 'ro', format => 'i@', autosplit => ',' ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); 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 => "," ); 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; } subtest "Moo" => sub { note "Test Moo"; require $RealBin . '/base.st'; }; done_testing; doc.t100644001752001752 326212144156710 16265 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; use Carp; use FindBin qw/$RealBin/; use Try::Tiny; { 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 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 }; ok $trap->stdout =~ /\s+\-t\s+this\sis\sa\stest/x, 'documentation work'; } { my $opt = t1->new_with_options; trap { $opt->options_usage }; ok $trap->stdout =~ /\s+\-t\s+this\spass\sfirst/x, 'doc pass first'; } { my $opt = t2->new_with_options; trap { $opt->options_usage }; ok $trap->stdout =~ /\s+\-t\s+this\spass\sfirst/x, 'doc pass first'; } done_testing; pod.t100644001752001752 61712144156710 16263 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/tuse strict; use warnings FATAL => 'all'; BEGIN { unless ( $ENV{RELEASE_TESTING} ) { require Test::More; Test::More::plan( skip_all => 'these tests are for release candidate testing' ); } } use English qw( -no_match_vars ); local $OUTPUT_AUTOFLUSH = 1; use Test::More; use Test::Requires { 'Test::Pod' => 1.46 }; all_pod_files_ok(); done_testing(); __END__ LICENSE100644001752001752 4372512144156710 16125 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83This software is copyright (c) 2011 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) 2011 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, Suite 500, Boston, MA 02110-1335 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) 2011 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 dist.ini100644001752001752 116412144156710 16533 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83name = MooX-Options license = Perl_5 copyright_holder = celogeek copyright_year = 2011 version = 3.83 [@GRS] -remove = AutoPrereqs -remove = Prereqs [AutoPrereqs] skip=^Mo|Mouse|Moose$ skip=Role$ [Prereqs] Moo = 1.000003 Module::Metadata = 1.000011 Module::Load::Conditional = 0.54 [MetaResourcesFromGit] homepage = https://tasks.celogeek.com/projects/perl-modules-moox-options bugtracker.web = https://tasks.celogeek.com/projects/perl-modules-moox-options repository.url = https://github.com/celogeek/MooX-Options.git repository.web = https://github.com/celogeek/MooX-Options repository.type = git role.t100644001752001752 366612144156710 16471 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; { 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; }; ok( $trap->stdout =~ /\-\-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; }; ok( $trap->stdout =~ /\-\-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; META.yml100644001752001752 1241412144156710 16360 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83--- abstract: 'add option keywords to your object (Mo/Moo/Moose)' author: - 'celogeek ' build_requires: English: 0 File::Find: 0 File::Temp: 0 FindBin: 0 Module::Build: 0.3601 Role::Tiny::With: 0 Scalar::Util: 0 Test::More: 0.94 Test::Requires: 0 Test::Trap: 0 Try::Tiny: 0 namespace::clean: 0 perl: 5.004 configure_requires: Module::Build: 0.3601 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.130880' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooX-Options requires: Carp: 0 Data::Record: 0 Getopt::Long: 2.38 Getopt::Long::Descriptive: 0.091 JSON: 0 MRO::Compat: 0 Module::Load::Conditional: 0.54 Module::Metadata: 1.000011 Moo: 1.000003 Regexp::Common: 0 perl: 5.006 strict: 0 warnings: 0 resources: bugtracker: https://tasks.celogeek.com/projects/perl-modules-moox-options homepage: https://tasks.celogeek.com/projects/perl-modules-moox-options repository: https://github.com/celogeek/MooX-Options.git version: 3.83 x_Dist_Zilla: perl: version: 5.016003 plugins: - class: Dist::Zilla::Plugin::GatherDir name: '@GRS/@Filter/GatherDir' version: 4.300034 - class: Dist::Zilla::Plugin::PruneCruft name: '@GRS/@Filter/PruneCruft' version: 4.300034 - class: Dist::Zilla::Plugin::ManifestSkip name: '@GRS/@Filter/ManifestSkip' version: 4.300034 - class: Dist::Zilla::Plugin::MetaYAML name: '@GRS/@Filter/MetaYAML' version: 4.300034 - class: Dist::Zilla::Plugin::License name: '@GRS/@Filter/License' version: 4.300034 - class: Dist::Zilla::Plugin::Readme name: '@GRS/@Filter/Readme' version: 4.300034 - class: Dist::Zilla::Plugin::ExtraTests name: '@GRS/@Filter/ExtraTests' version: 4.300034 - class: Dist::Zilla::Plugin::ExecDir name: '@GRS/@Filter/ExecDir' version: 4.300034 - class: Dist::Zilla::Plugin::ShareDir name: '@GRS/@Filter/ShareDir' version: 4.300034 - class: Dist::Zilla::Plugin::Manifest name: '@GRS/@Filter/Manifest' version: 4.300034 - class: Dist::Zilla::Plugin::TestRelease name: '@GRS/@Filter/TestRelease' version: 4.300034 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@GRS/@Filter/ConfirmRelease' version: 4.300034 - class: Dist::Zilla::Plugin::ModuleBuild name: '@GRS/ModuleBuild' version: 4.300034 - class: Dist::Zilla::Plugin::ReportVersions name: '@GRS/ReportVersions' version: 1.110730 - class: Dist::Zilla::Plugin::OurPkgVersion name: '@GRS/OurPkgVersion' version: 0.004000 - class: Dist::Zilla::Plugin::Prepender name: '@GRS/Prepender' version: 1.112280 - class: Dist::Zilla::Plugin::MinimumPerl name: '@GRS/MinimumPerl' version: 1.003 - class: Dist::Zilla::Plugin::Test::Compile name: '@GRS/Test::Compile' version: 2.002 - class: Dist::Zilla::Plugin::Test::UnusedVars name: '@GRS/Test::UnusedVars' version: 2.000004 - class: Dist::Zilla::Plugin::PodCoverageTests name: '@GRS/PodCoverageTests' version: 4.300034 - class: Dist::Zilla::Plugin::PruneFiles name: '@GRS/PruneFiles' version: 4.300034 - class: Dist::Zilla::Plugin::ReadmeMarkdownFromPod name: '@GRS/ReadmeMarkdownFromPod' version: 0.120120 - class: Dist::Zilla::Plugin::MetaJSON name: '@GRS/MetaJSON' version: 4.300034 - class: Dist::Zilla::Plugin::MetaResourcesFromGit name: '@GRS/MetaResourcesFromGit' version: 1.103620 - class: Dist::Zilla::Plugin::MetaConfig name: '@GRS/MetaConfig' version: 4.300034 - class: Dist::Zilla::Plugin::PodWeaver name: '@GRS/PodWeaver' version: 3.101641 - class: Dist::Zilla::Plugin::PerlTidy name: '@GRS/PerlTidy' version: 0.13 - class: Dist::Zilla::Plugin::Test::Perl::Critic name: '@GRS/Test::Perl::Critic' version: 2.112410 - class: Dist::Zilla::Plugin::AutoPrereqs name: AutoPrereqs version: 4.300034 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: 4.300034 - class: Dist::Zilla::Plugin::MetaResourcesFromGit name: MetaResourcesFromGit version: 1.103620 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300034 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300034 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300034 MANIFEST100644001752001752 72412144156710 16201 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83Build.PL Changes LICENSE MANIFEST META.json META.yml README README.mkdn build.log coverage.txt dist.ini lib/MooX/Options.pm lib/MooX/Options/Role.pm t/00-compile.t t/000-report-versions.t t/author-critic.t t/base.st t/doc.t t/failure.t t/flavour.t t/lib/TestNamespaceClean.pm t/mo.t t/moo.t t/moose.t t/mouse.t t/multi_role.t t/namespace_clean.t t/no_option.t t/order.t t/pod.t t/release-pod-coverage.t t/release-unused-vars.t t/role.t xt/perlcritic.rc xt/perltidy.rc Build.PL100644001752001752 317312144156710 16365 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83 use strict; use warnings; use Module::Build 0.3601; my %module_build_args = ( "build_requires" => { "Module::Build" => "0.3601" }, "configure_requires" => { "Module::Build" => "0.3601" }, "dist_abstract" => "add option keywords to your object (Mo/Moo/Moose)", "dist_author" => [ "celogeek " ], "dist_name" => "MooX-Options", "dist_version" => "3.83", "license" => "perl", "module_name" => "MooX::Options", "recommends" => {}, "recursive_test_files" => 1, "requires" => { "Carp" => 0, "Data::Record" => 0, "Getopt::Long" => "2.38", "Getopt::Long::Descriptive" => "0.091", "JSON" => 0, "MRO::Compat" => 0, "Module::Load::Conditional" => "0.54", "Module::Metadata" => "1.000011", "Moo" => "1.000003", "Regexp::Common" => 0, "perl" => "5.006", "strict" => 0, "warnings" => 0 }, "script_files" => [], "test_requires" => { "English" => 0, "File::Find" => 0, "File::Temp" => 0, "FindBin" => 0, "Role::Tiny::With" => 0, "Scalar::Util" => 0, "Test::More" => "0.94", "Test::Requires" => 0, "Test::Trap" => 0, "Try::Tiny" => 0, "namespace::clean" => 0, "perl" => "5.004" } ); unless ( eval { Module::Build->VERSION(0.4004) } ) { my $tr = delete $module_build_args{test_requires}; my $br = $module_build_args{build_requires}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } my $build = Module::Build->new(%module_build_args); $build->create_build_script; build.log100644001752001752 650612144156710 16676 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83building test distribution under .build/NlQxmbdgU5 [DZ] beginning to build MooX-Options [DZ] guessing dist's main_module is lib/MooX/Options.pm [DZ] extracting distribution abstract from lib/MooX/Options.pm [@GRS/@Filter/ExtraTests] rewriting release test xt/release/unused-vars.t [@GRS/@Filter/ExtraTests] rewriting release test xt/release/pod-coverage.t [@GRS/@Filter/ExtraTests] rewriting author test xt/author/critic.t [@GRS/ReadmeMarkdownFromPod] Override README.mkdn in build [DZ] writing MooX-Options in .build/NlQxmbdgU5 Created MYMETA.yml and MYMETA.json Creating new 'Build' script for 'MooX-Options' version '3.83' Building MooX-Options t/00-compile.t ............ ok # Testing with Perl 5.016003, /home/gitlab_ci/perl5/perlbrew/perls/perl-5.16.3/bin/perl # Carp version is 1.26 # Data::Record version is 0.02 # English version is 1.05 # File::Find version is 1.20 # File::Temp version is 0.22 # FindBin version is 1.51 # Getopt::Long version is 2.38 # Getopt::Long::Descriptive version is 0.093 # JSON version is 2.57 # MRO::Compat version is 0.12 # Module::Build version is 0.4005 # Module::Load::Conditional version is 0.54 # Module::Metadata version is 1.000014 # Moo version is 1.002 # Regexp::Common version is 2013031301 # Role::Tiny::With version is undefined # Scalar::Util version is 1.25 # Test::More version is 0.98 # Test::Requires version is 0.06 # Test::Trap version is 0.2.2 # Try::Tiny version is 0.12 # namespace::clean version is 0.24 # strict version is 1.07 # warnings version is 1.13 t/000-report-versions.t ... ok t/author-critic.t ......... ok t/doc.t ................... ok t/failure.t ............... ok t/flavour.t ............... ok t/mo.t .................... skipped: Need Mo for this test t/moo.t ................... ok t/moose.t ................. ok t/mouse.t ................. skipped: Sorry, but I don't support Mouse anymore, the module doesn't work like any others and is fully incompatible with the new way I have wrote MooX::Options. If you really need it, help me to solve this. t/multi_role.t ............ ok t/namespace_clean.t ....... ok t/no_option.t ............. ok t/order.t ................. ok t/pod.t ................... skipped: Test requires module 'Test::Pod' but it's not found t/release-pod-coverage.t .. ok t/release-unused-vars.t ... ok t/role.t .................. ok All tests successful. Files=18, Tests=73, 16 wallclock secs ( 0.06 usr 0.01 sys + 14.60 cusr 0.62 csys = 15.29 CPU) Result: PASS cover Reading database from /home/gitlab_ci/repositories/celogeek/perl-modules-moox-options/.build/NlQxmbdgU5/cover_db ---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ blib/lib/MooX/Options.pm 100.0 100.0 100.0 100.0 n/a 72.2 100.0 .../lib/MooX/Options/Role.pm 100.0 100.0 100.0 100.0 100.0 27.8 100.0 Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 ---------------------------- ------ ------ ------ ------ ------ ------ ------ HTML output written to /home/gitlab_ci/repositories/celogeek/perl-modules-moox-options/.build/NlQxmbdgU5/cover_db/coverage.html done. leaving .build/NlQxmbdgU5 intact base.st100644001752001752 1444412144156710 16641 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t my @params = qw/bool counter empty/; 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 = ( '--bool', '--counter', '--counter', '--counter', '--empty' ); 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" ); done_testing(); }; subtest "negativable" => sub { note "negativable"; local @ARGV = ( '--empty', '--no-empty' ); my $t = t->new_with_options(); is( $t->empty, 0, "empty 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" ); } { local @ARGV = ('--split=1,2'); my $t = t->new_with_options(); is_deeply( $t->split, [ 1, 2 ], "split one arg autosplit" ); } { 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" ); } { 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" ); ok( $trap->stdout =~ /^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->stdout =~ /(multi_\d is missing)\n/g; 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 "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"; { 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",d'); my $t = sp_str->new_with_options(); is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' ); } done_testing(); }; subtest "should_die_ok" => sub { note "Test chain method"; try { d->new_with_options( should_die_ok => 1 ); } catch { ok( /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' ); ok( $trap->stdout =~ /usage work/, 'custom message is present' ); ok( $trap->stdout =~ /usage really work/, 'custom message is really present' ); ok( $trap->stdout =~ /help.*show this help message/, 'help is present' ); ok( $trap->stdout =~ /split_str.*no doc for split_str/, 'attr no doc is present' ); }; 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' ); ok( $trap->stdout =~ /t.*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 }; ok ($trap->stdout =~ /\-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'); } }; 1; order.t100644001752001752 467212144156710 16641 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More tests => 3; use Test::Trap; { 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 }; ok $trap->stdout =~ /first.+second.+third.+fourth/gms, 'order work w/ order attribute'; } { my $opt = t2->new_with_options; trap { $opt->options_usage }; ok $trap->stdout =~ /first.+fourth.+second.+third/gms, 'order work w/o order attribute'; } { my $opt = t3->new_with_options; trap { $opt->options_usage }; ok $trap->stdout =~ /fourth.+third.+first.+second/gms, 'order work w/ mixed mode'; } done_testing; moose.t100644001752001752 471512144156710 16646 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; use Carp; use FindBin qw/$RealBin/; use Try::Tiny; BEGIN { use Module::Load::Conditional qw/check_install/; plan skip_all => 'Need Moose for this test' unless check_install( module => 'Moose' ); } { package t; use Moose; use MooX::Options; option 'bool' => ( is => 'ro' ); option 'counter' => ( is => 'ro', repeatable => 1 ); option 'empty' => ( is => 'ro', negativable => 1 ); option 'split' => ( is => 'ro', format => 'i@', autosplit => ',' ); option 'has_default' => ( is => 'ro', default => sub {'foo'} ); 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 => "," ); 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; } subtest "Moose" => sub { note "Test Moose"; require $RealBin . '/base.st'; }; done_testing; mouse.t100644001752001752 105212144156710 16643 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; plan skip_all => "Sorry, but I don't support Mouse anymore, the module doesn't work like any others and is fully incompatible with the new way I have wrote MooX::Options. If you really need it, help me to solve this."; done_testing; META.json100644001752001752 2060612144156710 16532 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83{ "abstract" : "add option keywords to your object (Mo/Moo/Moose)", "author" : [ "celogeek " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.130880", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooX-Options", "prereqs" : { "build" : { "requires" : { "Module::Build" : "0.3601" } }, "configure" : { "requires" : { "Module::Build" : "0.3601" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "Carp" : "0", "Data::Record" : "0", "Getopt::Long" : "2.38", "Getopt::Long::Descriptive" : "0.091", "JSON" : "0", "MRO::Compat" : "0", "Module::Load::Conditional" : "0.54", "Module::Metadata" : "1.000011", "Moo" : "1.000003", "Regexp::Common" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "English" : "0", "File::Find" : "0", "File::Temp" : "0", "FindBin" : "0", "Role::Tiny::With" : "0", "Scalar::Util" : "0", "Test::More" : "0.94", "Test::Requires" : "0", "Test::Trap" : "0", "Try::Tiny" : "0", "namespace::clean" : "0", "perl" : "5.004" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://tasks.celogeek.com/projects/perl-modules-moox-options" }, "homepage" : "https://tasks.celogeek.com/projects/perl-modules-moox-options", "repository" : { "type" : "git", "url" : "https://github.com/celogeek/MooX-Options.git", "web" : "https://github.com/celogeek/MooX-Options" } }, "version" : "3.83", "x_Dist_Zilla" : { "perl" : { "version" : "5.016003" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GatherDir", "name" : "@GRS/@Filter/GatherDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@GRS/@Filter/PruneCruft", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@GRS/@Filter/ManifestSkip", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@GRS/@Filter/MetaYAML", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@GRS/@Filter/License", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@GRS/@Filter/Readme", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@GRS/@Filter/ExtraTests", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@GRS/@Filter/ExecDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@GRS/@Filter/ShareDir", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@GRS/@Filter/Manifest", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@GRS/@Filter/TestRelease", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@GRS/@Filter/ConfirmRelease", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ModuleBuild", "name" : "@GRS/ModuleBuild", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ReportVersions", "name" : "@GRS/ReportVersions", "version" : "1.110730" }, { "class" : "Dist::Zilla::Plugin::OurPkgVersion", "name" : "@GRS/OurPkgVersion", "version" : "0.004000" }, { "class" : "Dist::Zilla::Plugin::Prepender", "name" : "@GRS/Prepender", "version" : "1.112280" }, { "class" : "Dist::Zilla::Plugin::MinimumPerl", "name" : "@GRS/MinimumPerl", "version" : "1.003" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "name" : "@GRS/Test::Compile", "version" : "2.002" }, { "class" : "Dist::Zilla::Plugin::Test::UnusedVars", "name" : "@GRS/Test::UnusedVars", "version" : "2.000004" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@GRS/PodCoverageTests", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::PruneFiles", "name" : "@GRS/PruneFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::ReadmeMarkdownFromPod", "name" : "@GRS/ReadmeMarkdownFromPod", "version" : "0.120120" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@GRS/MetaJSON", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaResourcesFromGit", "name" : "@GRS/MetaResourcesFromGit", "version" : "1.103620" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@GRS/MetaConfig", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "name" : "@GRS/PodWeaver", "version" : "3.101641" }, { "class" : "Dist::Zilla::Plugin::PerlTidy", "name" : "@GRS/PerlTidy", "version" : "0.13" }, { "class" : "Dist::Zilla::Plugin::Test::Perl::Critic", "name" : "@GRS/Test::Perl::Critic", "version" : "2.112410" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "AutoPrereqs", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::MetaResourcesFromGit", "name" : "MetaResourcesFromGit", "version" : "1.103620" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300034" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300034" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300034" } } } README.mkdn100644001752001752 2347012144156710 16723 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83# NAME MooX::Options - add option keywords to your object (Mo/Moo/Moose) # VERSION version 3.83 # MooX::Options Use [Getopt::Long::Descritive](http://search.cpan.org/perldoc?Getopt::Long::Descritive) to provide command line option for your Mo/Moo/Moose Object. This module will add "option" which act as "has" but support additional feature for getopt. You will have "new\_with\_options" to instanciate new object for command line. # METHOD ## IMPORT The import method can take option : - %options - flavour pass extra arguments for Getopt::Long::Descriptive. it is usefull if you want to configure Getopt::Long. use MooX::Options flavour => [qw( pass_through )]; Any flavour is pass to [Getopt::Long](http://search.cpan.org/perldoc?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 you can skip some option to remove the possibility to the terminal. in that case, the 'option' keyword will just works like an 'has'. use MooX::Options skip_options => [qw/multi/]; If you have multiple tools that use the same Role to generate params, you can skip one and force his value. In my example, it could be a multithread option that you want to disabling in some case. - prefer\_commandline By default, arguments to [new\_with\_options()](#Keyword 'new\_with\_options') are used in preference of items provided via command line options. You may enable the ["prefer\_commandline"](#prefer\_commandline) option to reverse this behaviour; this allows you to provide some default values to [new\_with\_options()](#Keyword 'new\_with\_options') and override them on the command line. { package t; use Moo; use MooX::Options prefer_commandline => 1; option 'test' => (is => 'ro'); 1; } # parse ARGV for options but default to those provided here my $t = t->new_with_options( test => 'default' ); # USAGE First of all, I use [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive). Everything will be pass to the programs, more specially the format. { package t; use Moo; use MooX::Options; option 'test' => (is => 'ro'); 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here The keyword "option" work exactly like the keyword "has" and take extra argument of Getopt. You can also use it over a Role. { package tRole; use Moo::Role; use MooX::Options; option 'test' => (is => 'ro'); 1; } { package t; use Moo; use MooX::Options; #you have to add this, or the role will not find the necessary methods with 'tRole'; 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here If you use Mo, you have a little bit more work to do. Because Mo lack of "with" and "around". { package tRole; use Moo::Role; use Mo; use MooX::Options; option 'test' => (is => 'ro'); 1; } { package t; use Mo; use Role::Tiny::With; with 'tRole'; 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here It's a bit tricky but, hey, you are using Mo ! ## Keyword 'options\_usage' It display the usage message and return the exit code my $t = t->new_with_options(); $t->options_usage(1, "str is not valid"); Params : - $exit\_code Exit code after displaying the usage message - @messages Additional message to display before the usage message Ex: str is not valid ## Keyword 'new\_with\_options' It will parse your command line params and your inline params, validate and call the 'new' method. You can override the command line params : Ex: local @ARGV=('--str=ko'); t->new_with_options(str => 'ok'); t->str; #ok ## Keyword 'option' : EXTRA ARGS - doc Specified the documentation for the attribute - documentation Specified the documentation for the attribute. It is usefull if you chain with other module like [MooseX::App::Cmd](http://search.cpan.org/perldoc?MooseX::App::Cmd) that use this attribute. If doc attribute is defined, this one will be ignored. - required Specified if the attribute is needed - format Format of the params. It is the same as [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive). Example : 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 format with [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive). - negativable add the attribute "!" to the name. It will allow negative params. Ex : test --quiet => quiet = 1 test --quiet --no-quiet => quiet = 0 - repeatable add the attribute "@" to the name. It will allow repeatable params. Ex : test --verbose => verbose = 1 test --verbose --verbose => verbose = 2 it is advisable to use a "default" option on the attribute for repeatable params so that they behave as arrays "out of the box" when used outside of command line context. Ex: { package t; use Moo; use MooX::Options; option foo => (is => 'rw', format => 's@', default => sub { [] }); option bar => (is => 'rw', format => 'i@', default => sub { [] }); 1; } # this now works as expected and you will no longer see # "Can't use an undefined value as an ARRAY reference" my $t = t->new_with_options; push @{ $t->foo }, 'abc123'; 1; - autosplit auto split args to generate multiple value. It implie "repeatable". autosplit take the separator value, ex: ",". Ex : { package t; use Moo; use MooX::Options; option test => (is => 'ro', format => 'i@', autosplit => ','); #same as : option test => (is => 'ro', format => 'i', autosplit => ','); 1; } local @ARGV=('--test=1,2,3,4'); my $t = t->new_with_options; t->test # [1,2,3,4] I automatically take the quoted as a group separator value { package str; use Moo; use MooX::Options; option test => (is => 'ro', format => 's', repeatable => 1, autosplit => ','); 1; } local @ARGV=('--test=a,b,"c,d",e'); my $t = str->new_with_options; t->test # ['a','b','c,d','e'] - short give short name of an attribute. Ex : { package t; use Moo; use MooX::Options; option 'verbose' => (is => 'ro', repeatable => 1, short => 'v'); 1; } local @ARGV=('-vvv'); my $t = t->new_with_options; t->verbose # 3 - order Specified the order of the attribute. The order value is an integer. - json The parameter will be treat like a json string. Ex : { package t; use Moo; use MooX::Options; option 'hash' => (is => 'ro', json => 1); 1; } local @ARGV=('--hash', '{"a":1,"b":2}'); my $t = t->new_with_options; t->hash # { a => 1, b => 2 } # namespace::clean To use namespace::clean you need to add 2 methods as an exception. It is use by MooX::Options when you run the new\_with\_options methods. { package t; use Moo; use MooX::Options; use namespace::clean -except => [qw/_options_data _options_config/]; option 'v' => (is => 'rw'); 1; } my $r = t->new_with_options; # dash support You can call the option with underscore or dash in the name. For example, --start-date or --start\_date will fill the option 'start\_date'. # no more Mouse support If you are using Mouse, I'm sorry to say than the rewrite of this module has make it just incompatible. Mouse is not design to by compatible with anything else than Mouse itself. I could just suggest to use Moo instead, which is a great and compatible replacement. # More examples [http://perltalks.celogeek.com/slides/2012/08/moox-options-slide3d.html](http://perltalks.celogeek.com/slides/2012/08/moox-options-slide3d.html) # THANKS - Matt S. Trout (mst) : For his patience and advice. - Tomas Doran (t0m) : 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](http://search.cpan.org/perldoc?MooX) module also) # BUGS Please report any bugs or feature requests on the bugtracker website https://tasks.celogeek.com/projects/perl-modules-moox-options When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. # AUTHOR celogeek # COPYRIGHT AND LICENSE This software is copyright (c) 2011 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. flavour.t100644001752001752 475712144156710 17210 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Test::Trap; use Carp; use FindBin qw/$RealBin/; use Try::Tiny; { 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() }; like( $trap->die, qr/USAGE:/, "died with usage message" ); like( $trap->warn(0), qr/Unknown option: unknown_option/, "and a warning from GLD" ); } }; } 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; failure.t100644001752001752 360412144156710 17147 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!/usr/bin/env perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use Carp; eval < ( is => 'rw', negativable => 1, format => 'i', ); 1; EOF ; like $@, qr/^Negativable\sparams\sis\snot\susable\swith\snon\sboolean\svalue,\sdon't\spass\sformat\sto\suse\sit\s\!/x, "negativable and format are incompatible"; for my $ban ( qw/help option new_with_options parse_options options_usage _options_data _options_config/ ) { eval < ( 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 < (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 <can('new_with_options'), 't has crash' ); } done_testing; coverage.txt100644001752001752 104212144156710 17416 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83---------------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ---------------------------- ------ ------ ------ ------ ------ ------ ------ blib/lib/MooX/Options.pm 100.0 100.0 100.0 100.0 n/a 72.7 100.0 .../lib/MooX/Options/Role.pm 100.0 100.0 100.0 100.0 100.0 27.3 100.0 Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 ---------------------------- ------ ------ ------ ------ ------ ------ ------ no_option.t100644001752001752 71712144156710 17506 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; # last test to print { package t; use Moo; use MooX::Options; 1; } my $p = t->new_with_options; ok( $p, 't has options' ); done_testing; multi_role.t100644001752001752 203112144156710 17664 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::Trap; use Test::More; # last test to print { 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; xt000755001752001752 012144156710 15360 5ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83perltidy.rc100644001752001752 31512144156710 17661 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/xt#Perl Best Practice Conf -l=78 -i=4 -ci=4 #-st -se -vt=2 -cti=0 -pt=1 -bt=1 -sbt=1 -bbt=1 -nsfs -nolq -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" 00-compile.t100644001752001752 370212144156710 17364 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use strict; use warnings; use Test::More; use File::Find; use File::Temp qw{ tempdir }; my @modules; find( sub { return if $File::Find::name !~ /\.pm\z/; my $found = $File::Find::name; $found =~ s{^lib/}{}; $found =~ s{[/\\]}{::}g; $found =~ s/\.pm$//; # nothing to skip push @modules, $found; }, 'lib', ); sub _find_scripts { my $dir = shift @_; my @found_scripts = (); find( sub { return unless -f; my $found = $File::Find::name; # nothing to skip open my $FH, '<', $_ or do { note("Unable to open $found in ( $! ), skipping"); return; }; my $shebang = <$FH>; return unless $shebang =~ /^#!.*?\bperl\b\s*$/; push @found_scripts, $found; }, $dir, ); return @found_scripts; } my @scripts; do { push @scripts, _find_scripts($_) if -d $_ } for qw{ bin script scripts }; my $plan = scalar(@modules) + scalar(@scripts); $plan ? ( plan tests => $plan ) : ( plan skip_all => "no tests to run" ); { # fake home for cpan-testers # no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 ); like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" ) for sort @modules; SKIP: { eval "use Test::Script 1.05; 1;"; skip "Test::Script needed to test script compilation", scalar(@scripts) if $@; foreach my $file (@scripts) { my $script = $file; $script =~ s!.*/!!; script_compiles( $file, "$script script compiles" ); } } } perlcritic.rc100644001752001752 53012144156710 20164 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/xtseverity = 3 verbose = 6 top = 50 theme = pbp || core || bugs || security || maintenance criticism-fatal = 1 color = 1 allow-unsafe = 1 [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::RequireLocalizedPunctuationVars] allow = @ARGV [-Miscellanea::ProhibitUnrestrictedNoCritic] author-critic.t100644001752001752 132712144156710 20275 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # BEGIN { unless ( $ENV{AUTHOR_TESTING} ) { require Test::More; Test::More::plan( skip_all => 'these tests are for testing by the author' ); } } use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "xt/perlcritic.rc" ) if -e "xt/perlcritic.rc"; all_critic_ok(); MooX000755001752001752 012144156710 16355 5ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/libOptions.pm100755001752001752 3211612144156710 20534 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/lib/MooX# # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # package MooX::Options; # ABSTRACT: add option keywords to your object (Mo/Moo/Moose) use strict; use warnings; use Carp; our $VERSION = '3.83'; # VERSION my @OPTIONS_ATTRIBUTES = qw/format short repeatable negativable autosplit doc order json/; sub import { my ( undef, @import ) = @_; my $options_config = { protect_argv => 1, flavour => [], skip_options => [], prefer_commandline => 0, @import }; my $target = caller; 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) { #don't add this to a role #ISA of a role is always empty ! ## no critic qw/ProhibitStringyEval/ use warnings FATAL => 'redefine'; eval '{ package ' . $target . '; 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; }'; use warnings FATAL => qw/void/; croak $@ if $@; $around->( _options_config => sub { my ( $orig, $self ) = ( shift, shift ); return $self->$orig(@_), %$options_config; } ); ## use critic } my $options_data = {}; my $apply_modifiers = sub { return if $target->can('new_with_options'); $with->('MooX::Options::Role'); $around->( _options_data => sub { my ( $orig, $self ) = ( shift, shift ); return ( $self->$orig(@_), %$options_data ); } ); }; my $option = sub { my ( $name, %attributes ) = @_; for my $ban ( qw/help option new_with_options parse_options options_usage _options_data _options_config/ ) { croak "You cannot use an option with the name '$ban', it is implied by MooX::Options" if $name eq $ban; } $has->( $name => _filter_attributes(%attributes) ); $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; } sub _filter_attributes { my %attributes = @_; my %filter_key = map { $_ => 1 } @OPTIONS_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} ) { delete $options{repeatable}; delete $options{autosplit}; delete $options{negativable}; $options{format} = 's'; } my %cmdline_options = map { ( $_ => $options{$_} ) } grep { exists $options{$_} } @OPTIONS_ATTRIBUTES, 'required'; $cmdline_options{repeatable} = 1 if $cmdline_options{autosplit}; $cmdline_options{format} .= "@" if $cmdline_options{repeatable} && defined $cmdline_options{format} && substr( $cmdline_options{format}, -1 ) ne '@'; croak "Negativable params is not usable with non boolean value, don't pass format to use it !" if $cmdline_options{negativable} && defined $cmdline_options{format}; return %cmdline_options; } 1; __END__ =pod =head1 NAME MooX::Options - add option keywords to your object (Mo/Moo/Moose) =head1 VERSION version 3.83 =head1 MooX::Options Use L to provide command line option for your Mo/Moo/Moose Object. This module will add "option" which act as "has" but support additional feature for getopt. You will have "new_with_options" to instanciate new object for command line. =head1 METHOD =head2 IMPORT The import method can take option : =over =item %options =over =item flavour pass extra arguments for Getopt::Long::Descriptive. it is usefull if you want to configure Getopt::Long. use MooX::Options flavour => [qw( pass_through )]; Any flavour is pass to L as a configuration, check the doc to see what is possible. =item 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; =item skip_options you can skip some option to remove the possibility to the terminal. in that case, the 'option' keyword will just works like an 'has'. use MooX::Options skip_options => [qw/multi/]; If you have multiple tools that use the same Role to generate params, you can skip one and force his value. In my example, it could be a multithread option that you want to disabling in some case. =item prefer_commandline By default, arguments to L are used in preference of items provided via command line options. You may enable the L option to reverse this behaviour; this allows you to provide some default values to L and override them on the command line. { package t; use Moo; use MooX::Options prefer_commandline => 1; option 'test' => (is => 'ro'); 1; } # parse ARGV for options but default to those provided here my $t = t->new_with_options( test => 'default' ); =back =back =head1 USAGE First of all, I use L. Everything will be pass to the programs, more specially the format. { package t; use Moo; use MooX::Options; option 'test' => (is => 'ro'); 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here The keyword "option" work exactly like the keyword "has" and take extra argument of Getopt. You can also use it over a Role. { package tRole; use Moo::Role; use MooX::Options; option 'test' => (is => 'ro'); 1; } { package t; use Moo; use MooX::Options; #you have to add this, or the role will not find the necessary methods with 'tRole'; 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here If you use Mo, you have a little bit more work to do. Because Mo lack of "with" and "around". { package tRole; use Moo::Role; use Mo; use MooX::Options; option 'test' => (is => 'ro'); 1; } { package t; use Mo; use Role::Tiny::With; with 'tRole'; 1; } my $t = t->new_with_options(); #parse @ARGV my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here It's a bit tricky but, hey, you are using Mo ! =head2 Keyword 'options_usage' It display the usage message and return the exit code my $t = t->new_with_options(); $t->options_usage(1, "str is not valid"); Params : =over =item $exit_code Exit code after displaying the usage message =item @messages Additional message to display before the usage message Ex: str is not valid =back =head2 Keyword 'new_with_options' It will parse your command line params and your inline params, validate and call the 'new' method. You can override the command line params : Ex: local @ARGV=('--str=ko'); t->new_with_options(str => 'ok'); t->str; #ok =head2 Keyword 'option' : EXTRA ARGS =over =item doc Specified the documentation for the attribute =item documentation Specified the documentation for the attribute. It is usefull if you chain with other module like L that use this attribute. If doc attribute is defined, this one will be ignored. =item required Specified if the attribute is needed =item format Format of the params. It is the same as L. Example : 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 format with L. =item negativable add the attribute "!" to the name. It will allow negative params. Ex : test --quiet => quiet = 1 test --quiet --no-quiet => quiet = 0 =item repeatable add the attribute "@" to the name. It will allow repeatable params. Ex : test --verbose => verbose = 1 test --verbose --verbose => verbose = 2 it is advisable to use a "default" option on the attribute for repeatable params so that they behave as arrays "out of the box" when used outside of command line context. Ex: { package t; use Moo; use MooX::Options; option foo => (is => 'rw', format => 's@', default => sub { [] }); option bar => (is => 'rw', format => 'i@', default => sub { [] }); 1; } # this now works as expected and you will no longer see # "Can't use an undefined value as an ARRAY reference" my $t = t->new_with_options; push @{ $t->foo }, 'abc123'; 1; =item autosplit auto split args to generate multiple value. It implie "repeatable". autosplit take the separator value, ex: ",". Ex : { package t; use Moo; use MooX::Options; option test => (is => 'ro', format => 'i@', autosplit => ','); #same as : option test => (is => 'ro', format => 'i', autosplit => ','); 1; } local @ARGV=('--test=1,2,3,4'); my $t = t->new_with_options; t->test # [1,2,3,4] I automatically take the quoted as a group separator value { package str; use Moo; use MooX::Options; option test => (is => 'ro', format => 's', repeatable => 1, autosplit => ','); 1; } local @ARGV=('--test=a,b,"c,d",e'); my $t = str->new_with_options; t->test # ['a','b','c,d','e'] =item short give short name of an attribute. Ex : { package t; use Moo; use MooX::Options; option 'verbose' => (is => 'ro', repeatable => 1, short => 'v'); 1; } local @ARGV=('-vvv'); my $t = t->new_with_options; t->verbose # 3 =item order Specified the order of the attribute. The order value is an integer. =item json The parameter will be treat like a json string. Ex : { package t; use Moo; use MooX::Options; option 'hash' => (is => 'ro', json => 1); 1; } local @ARGV=('--hash', '{"a":1,"b":2}'); my $t = t->new_with_options; t->hash # { a => 1, b => 2 } =back =head1 namespace::clean To use namespace::clean you need to add 2 methods as an exception. It is use by MooX::Options when you run the new_with_options methods. { package t; use Moo; use MooX::Options; use namespace::clean -except => [qw/_options_data _options_config/]; option 'v' => (is => 'rw'); 1; } my $r = t->new_with_options; =head1 dash support You can call the option with underscore or dash in the name. For example, --start-date or --start_date will fill the option 'start_date'. =head1 no more Mouse support If you are using Mouse, I'm sorry to say than the rewrite of this module has make it just incompatible. Mouse is not design to by compatible with anything else than Mouse itself. I could just suggest to use Moo instead, which is a great and compatible replacement. =head1 More examples L =head1 THANKS =over =item Matt S. Trout (mst) : For his patience and advice. =item Tomas Doran (t0m) : To help me release the new version, and using it :) =item Torsten Raudssus (Getty) : to use it a lot in L (go to see L module also) =back =head1 BUGS Please report any bugs or feature requests on the bugtracker website https://tasks.celogeek.com/projects/perl-modules-moox-options When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR celogeek =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2011 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. =cut namespace_clean.t100644001752001752 51312144156710 20572 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/tuse strict; use warnings; use Test::More; use FindBin qw/ $Bin /; use lib "$Bin/lib"; use_ok 'TestNamespaceClean'; 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; 000-report-versions.t100644001752001752 3246312144156710 21223 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # use warnings; use strict; use Test::More 0.94; # Include a cut-down version of YAML::Tiny so we don't introduce unnecessary # dependencies ourselves. package Local::YAML::Tiny; use strict; use Carp 'croak'; # UTF Support? sub HAVE_UTF8 () { $] >= 5.007003 } BEGIN { if (HAVE_UTF8) { # The string eval helps hide this from Test::MinimumVersion eval "require utf8;"; die "Failed to load UTF-8 support" if $@; } # Class structure require 5.004; $YAML::Tiny::VERSION = '1.40'; # Error storage $YAML::Tiny::errstr = ''; } # Printable characters for escapes my %UNESCAPES = ( z => "\x00", a => "\x07", t => "\x09", n => "\x0a", v => "\x0b", f => "\x0c", r => "\x0d", e => "\x1b", '\\' => '\\', ); ##################################################################### # Implementation # Create an empty YAML::Tiny object sub new { my $class = shift; bless [@_], $class; } # Create an object from a file sub read { my $class = ref $_[0] ? ref shift : shift; # Check the file my $file = shift or return $class->_error('You did not specify a file name'); return $class->_error("File '$file' does not exist") unless -e $file; return $class->_error("'$file' is a directory, not a file") unless -f _; return $class->_error("Insufficient permissions to read '$file'") unless -r _; # Slurp in the file local $/ = undef; local *CFG; unless ( open( CFG, $file ) ) { return $class->_error("Failed to open file '$file': $!"); } my $contents = ; unless ( close(CFG) ) { return $class->_error("Failed to close file '$file': $!"); } $class->read_string($contents); } # Create an object from a string sub read_string { my $class = ref $_[0] ? ref shift : shift; my $self = bless [], $class; my $string = $_[0]; unless ( defined $string ) { return $self->_error("Did not provide a string to load"); } # Byte order marks # NOTE: Keeping this here to educate maintainers # my %BOM = ( # "\357\273\277" => 'UTF-8', # "\376\377" => 'UTF-16BE', # "\377\376" => 'UTF-16LE', # "\377\376\0\0" => 'UTF-32LE' # "\0\0\376\377" => 'UTF-32BE', # ); if ( $string =~ /^(?:\376\377|\377\376|\377\376\0\0|\0\0\376\377)/ ) { return $self->_error("Stream has a non UTF-8 BOM"); } else { # Strip UTF-8 bom if found, we'll just ignore it $string =~ s/^\357\273\277//; } # Try to decode as utf8 utf8::decode($string) if HAVE_UTF8; # Check for some special cases return $self unless length $string; unless ( $string =~ /[\012\015]+\z/ ) { return $self->_error("Stream does not end with newline character"); } # Split the file into lines my @lines = grep { !/^\s*(?:\#.*)?\z/ } split /(?:\015{1,2}\012|\015|\012)/, $string; # Strip the initial YAML header @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines; # A nibbling parser while (@lines) { # Do we have a document header? if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) { # Handle scalar documents shift @lines; if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) { push @$self, $self->_read_scalar( "$1", [undef], \@lines ); next; } } if ( !@lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) { # A naked document push @$self, undef; while ( @lines and $lines[0] !~ /^---/ ) { shift @lines; } } elsif ( $lines[0] =~ /^\s*\-/ ) { # An array at the root my $document = []; push @$self, $document; $self->_read_array( $document, [0], \@lines ); } elsif ( $lines[0] =~ /^(\s*)\S/ ) { # A hash at the root my $document = {}; push @$self, $document; $self->_read_hash( $document, [ length($1) ], \@lines ); } else { croak("YAML::Tiny failed to classify the line '$lines[0]'"); } } $self; } # Deparse a scalar string to the actual scalar sub _read_scalar { my ( $self, $string, $indent, $lines ) = @_; # Trim trailing whitespace $string =~ s/\s*\z//; # Explitic null/undef return undef if $string eq '~'; # Quotes if ( $string =~ /^\'(.*?)\'\z/ ) { return '' unless defined $1; $string = $1; $string =~ s/\'\'/\'/g; return $string; } if ( $string =~ /^\"((?:\\.|[^\"])*)\"\z/ ) { # Reusing the variable is a little ugly, # but avoids a new variable and a string copy. $string = $1; $string =~ s/\\"/"/g; $string =~ s/\\([never\\fartz]|x([0-9a-fA-F]{2}))/(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}/gex; return $string; } # Special cases if ( $string =~ /^[\'\"!&]/ ) { croak("YAML::Tiny does not support a feature in line '$lines->[0]'"); } return {} if $string eq '{}'; return [] if $string eq '[]'; # Regular unquoted string return $string unless $string =~ /^[>|]/; # Error croak("YAML::Tiny failed to find multi-line scalar content") unless @$lines; # Check the indent depth $lines->[0] =~ /^(\s*)/; $indent->[-1] = length("$1"); if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Pull the lines my @multiline = (); while (@$lines) { $lines->[0] =~ /^(\s*)/; last unless length($1) >= $indent->[-1]; push @multiline, substr( shift(@$lines), length($1) ); } my $j = ( substr( $string, 0, 1 ) eq '>' ) ? ' ' : "\n"; my $t = ( substr( $string, 1, 1 ) eq '-' ) ? '' : "\n"; return join( $j, @multiline ) . $t; } # Parse an array sub _read_array { my ( $self, $array, $indent, $lines ) = @_; while (@$lines) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) { # Inline nested hash my $indent2 = length("$1"); $lines->[0] =~ s/-/ /; push @$array, {}; $self->_read_hash( $array->[-1], [ @$indent, $indent2 ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) { # Array entry with a value shift @$lines; push @$array, $self->_read_scalar( "$2", [ @$indent, undef ], $lines ); } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) { shift @$lines; unless (@$lines) { push @$array, undef; return 1; } if ( $lines->[0] =~ /^(\s*)\-/ ) { my $indent2 = length("$1"); if ( $indent->[-1] == $indent2 ) { # Null array entry push @$array, undef; } else { # Naked indenter push @$array, []; $self->_read_array( $array->[-1], [ @$indent, $indent2 ], $lines ); } } elsif ( $lines->[0] =~ /^(\s*)\S/ ) { push @$array, {}; $self->_read_hash( $array->[-1], [ @$indent, length("$1") ], $lines ); } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) { # This is probably a structure like the following... # --- # foo: # - list # bar: value # # ... so lets return and let the hash parser handle it return 1; } else { croak("YAML::Tiny failed to classify line '$lines->[0]'"); } } return 1; } # Parse an array sub _read_hash { my ( $self, $hash, $indent, $lines ) = @_; while (@$lines) { # Check for a new document if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { while ( @$lines and $lines->[0] !~ /^---/ ) { shift @$lines; } return 1; } # Check the indent level $lines->[0] =~ /^(\s*)/; if ( length($1) < $indent->[-1] ) { return 1; } elsif ( length($1) > $indent->[-1] ) { croak("YAML::Tiny found bad indenting in line '$lines->[0]'"); } # Get the key unless ( $lines->[0] =~ s/^\s*([^\'\" ][^\n]*?)\s*:(\s+|$)// ) { if ( $lines->[0] =~ /^\s*[?\'\"]/ ) { croak( "YAML::Tiny does not support a feature in line '$lines->[0]'" ); } croak("YAML::Tiny failed to classify line '$lines->[0]'"); } my $key = $1; # Do we have a value? if ( length $lines->[0] ) { # Yes $hash->{$key} = $self->_read_scalar( shift(@$lines), [ @$indent, undef ], $lines ); } else { # An indent shift @$lines; unless (@$lines) { $hash->{$key} = undef; return 1; } if ( $lines->[0] =~ /^(\s*)-/ ) { $hash->{$key} = []; $self->_read_array( $hash->{$key}, [ @$indent, length($1) ], $lines ); } elsif ( $lines->[0] =~ /^(\s*)./ ) { my $indent2 = length("$1"); if ( $indent->[-1] >= $indent2 ) { # Null hash entry $hash->{$key} = undef; } else { $hash->{$key} = {}; $self->_read_hash( $hash->{$key}, [ @$indent, length($1) ], $lines ); } } } } return 1; } # Set error sub _error { $YAML::Tiny::errstr = $_[1]; undef; } # Retrieve error sub errstr { $YAML::Tiny::errstr; } ##################################################################### # Use Scalar::Util if possible, otherwise emulate it BEGIN { eval { require Scalar::Util; }; if ($@) { # Failed to load Scalar::Util eval <<'END_PERL'; sub refaddr { my $pkg = ref($_[0]) or return undef; if (!!UNIVERSAL::can($_[0], 'can')) { bless $_[0], 'Scalar::Util::Fake'; } else { $pkg = undef; } "$_[0]" =~ /0x(\w+)/; my $i = do { local $^W; hex $1 }; bless $_[0], $pkg if defined $pkg; $i; } END_PERL } else { Scalar::Util->import('refaddr'); } } ##################################################################### # main test ##################################################################### package main; BEGIN { # Skip modules that either don't want to be loaded directly, such as # Module::Install, or that mess with the test count, such as the Test::* # modules listed here. # # Moose::Role conflicts if Moose is loaded as well, but Moose::Role is in # the Moose distribution and it's certain that someone who uses # Moose::Role also uses Moose somewhere, so if we disallow Moose::Role, # we'll still get the relevant version number. my %skip = map { $_ => 1 } qw( App::FatPacker Class::Accessor::Classy Devel::Cover Module::Install Moose::Role POE::Loop::Tk Template::Test Test::Kwalitee Test::Pod::Coverage Test::Portability::Files Test::YAML::Meta open ); my $Test = Test::Builder->new; $Test->plan( skip_all => "META.yml could not be found" ) unless -f 'META.yml' and -r _; my $meta = ( Local::YAML::Tiny->read('META.yml') )->[0]; my %requires; for my $require_key ( grep {/requires/} keys %$meta ) { my %h = %{ $meta->{$require_key} }; $requires{$_}++ for keys %h; } delete $requires{perl}; diag("Testing with Perl $], $^X"); for my $module ( sort keys %requires ) { if ( $skip{$module} ) { note "$module doesn't want to be loaded directly, skipping"; next; } local $SIG{__WARN__} = sub { note "$module: $_[0]" }; require_ok $module or BAIL_OUT("can't load $module"); my $version = $module->VERSION; $version = 'undefined' unless defined $version; diag(" $module version is $version"); } done_testing; } release-unused-vars.t100644001752001752 107612144156710 21413 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # BEGIN { unless ( $ENV{RELEASE_TESTING} ) { require Test::More; Test::More::plan( skip_all => 'these tests are for release candidate testing' ); } } use Test::More; eval "use Test::Vars"; plan skip_all => "Test::Vars required for testing unused vars" if $@; all_vars_ok(); Options000755001752001752 012144156710 20010 5ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/lib/MooXRole.pm100644001752001752 1360612144156710 21435 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/lib/MooX/Options# # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # package MooX::Options::Role; # ABSTRACT: role that is apply to your object use strict; use warnings; our $VERSION = '3.83'; # VERSION use MRO::Compat; use Moo::Role; use Getopt::Long 2.38; use Getopt::Long::Descriptive 0.091; use Regexp::Common; use Data::Record; use JSON; requires qw/_options_data _options_config/; sub new_with_options { my ( $class, @params ) = @_; return $class->new( $class->parse_options(@params) ); } ## no critic qw/Modules::ProhibitExcessMainComplexity/ sub parse_options { my ( $class, %params ) = @_; my %options_data = $class->_options_data; my %options_config = $class->_options_config; my @skip_options; @skip_options = @{ $options_config{skip_options} } if defined $options_config{skip_options}; if (@skip_options) { delete @options_data{@skip_options}; } my @options; my $option_name = sub { my ( $name, %data ) = @_; my $cmdline_name = $name; $cmdline_name .= '|' . $data{short} if defined $data{short}; #dash name support my $dash_name = $name; $dash_name =~ tr/_/-/; if ( $dash_name ne $name ) { $cmdline_name .= '|' . $dash_name; } $cmdline_name .= '+' if $data{repeatable} && !defined $data{format}; $cmdline_name .= '!' if $data{negativable}; $cmdline_name .= '=' . $data{format} if defined $data{format}; return $cmdline_name; }; my %has_to_split; for my $name ( sort { $options_data{$a}{order} <=> $options_data{$b}{order} # sort by order or $a cmp $b # sort by attr name } keys %options_data ) { my %data = %{ $options_data{$name} }; my $doc = $data{doc}; $doc = "no doc for $name" if !defined $doc; push @options, [ $option_name->( $name, %data ), $doc ]; $has_to_split{$name} = Data::Record->new( { split => $data{autosplit}, unless => $RE{quoted} } ) if defined $data{autosplit}; } local @ARGV = @ARGV if $options_config{protect_argv}; if (%has_to_split) { my @new_argv; #parse all argv for my $i ( 0 .. $#ARGV ) { my $arg = $ARGV[$i]; my ( $arg_name, $arg_values ) = split( /=/x, $arg, 2 ); $arg_name =~ s/^--?//x; unless ( defined $arg_values ) { $arg_values = $ARGV[ ++$i ]; } if ( my $rec = $has_to_split{$arg_name} ) { foreach my $record ( $rec->records($arg_values) ) { #remove the quoted if exist to chain $record =~ s/^['"]|['"]$//gx; push @new_argv, "--$arg_name", $record; } } else { push @new_argv, $arg; } } @ARGV = @new_argv; } my @flavour; if ( defined $options_config{flavour} ) { push @flavour, { getopt_conf => $options_config{flavour} }; } my ( $opt, $usage ) = describe_options( ("USAGE: %c %o"), @options, [ 'help|h', "show this help message" ], @flavour ); if ( $opt->help() || defined $params{help} ) { print $usage, "\n"; my $exit_code = 0; $exit_code = 0 + $params{help} if defined $params{help}; exit($exit_code); } my @missing_required; my %cmdline_params = %params; for my $name ( keys %options_data ) { my %data = %{ $options_data{$name} }; if ( !defined $cmdline_params{$name} || $options_config{prefer_commandline} ) { my $val = $opt->$name(); if ( defined $val ) { if ( $data{json} ) { $cmdline_params{$name} = decode_json($val); } else { $cmdline_params{$name} = $val; } } } push @missing_required, $name if $data{required} && !defined $cmdline_params{$name}; } if (@missing_required) { print join( "\n", ( map { $_ . " is missing" } @missing_required ), '' ); print $usage, "\n"; exit(1); } return %cmdline_params; } ## use critic sub options_usage { my ( $self, $code, @messages ) = @_; $code = 0 if !defined $code; print join( "\n", @messages, '' ) if @messages; local @ARGV = (); return $self->parse_options( help => $code ); } 1; __END__ =pod =head1 NAME MooX::Options::Role - role that is apply to your object =head1 VERSION version 3.83 =head1 METHODS =head2 new_with_options Same as new but parse ARGV with L Check full doc L for more details. =head2 parse_options Parse your options, call L and convert the result for the "new" method. It is use by "new_with_options". =head2 options_usage Display help message. Check full doc L for more details. =head1 USAGE Don't use MooX::Options::Role directly. It is used by L to upgrade your module. But it is useless alone. =head1 BUGS Please report any bugs or feature requests on the bugtracker website https://tasks.celogeek.com/projects/perl-modules-moox-options When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. =head1 AUTHOR celogeek =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2011 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. =cut release-pod-coverage.t100644001752001752 142212144156710 21505 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t#!perl # # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # BEGIN { unless ( $ENV{RELEASE_TESTING} ) { require Test::More; Test::More::plan( skip_all => 'these tests are for release candidate testing' ); } } use Test::More; eval "use Test::Pod::Coverage 1.08"; plan skip_all => "Test::Pod::Coverage 1.08 required for testing POD coverage" if $@; eval "use Pod::Coverage::TrustPod"; plan skip_all => "Pod::Coverage::TrustPod required for testing POD coverage" if $@; all_pod_coverage_ok( { coverage_class => 'Pod::Coverage::TrustPod' } ); lib000755001752001752 012144156710 15736 5ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/tTestNamespaceClean.pm100644001752001752 65312144156710 22117 0ustar00gitlab_cigitlab_ci000000000000MooX-Options-3.83/t/lib# # This file is part of MooX-Options # # This software is copyright (c) 2011 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. # package TestNamespaceClean; use Moo; use MooX::Options; use namespace::clean -except => [qw/_options_data _options_config/]; option foo => ( is => 'ro', format => 's' ); 1;