MooseX-App-1.33/000755 000765 000024 00000000000 12514113027 013650 5ustar00marosstaff000000 000000 MooseX-App-1.33/Changes000644 000765 000024 00000012663 12514112733 015156 0ustar00marosstaff000000 000000 Release history for Perl module MooseX::App 1.33 2015-04-17 - Fix failing tests - Fix manifest 1.32 2015-03-21 - Improved Term Plugin (History, Delete, Pasting, Pos1/End, Cursors) - Documentation - Added app_command_register - Errors are now printed on STDERR - Disable fuzzy match for single letter parameters - Use proper exitcodes if errors occur - Add tests for subprocesses - Add MutexGroup plugin (implemented by Hunter McMillen) - Add Depends plugin (implemented by Hunter McMillen) 1.31 2015-02-08 - Dist cleanup (done by Sergey Romanov) - Moose cleanups (done by Sawyer X) - Fixed TERM plugin input - Coercion for ENV variables (implemented by Roman F.) - Refactor handling of boolean values - Allow for empty values - Add cmd_count option for counter attributes 1.30 2014-08-24 - Better error message if command was not specified - Help improved - Term plugin - Deprecate Env plugin; Now in core - Fix broken usage in M::A::Simple - Fix documentation being parsed called multiple times 1.29 2014-08-05 - Documentation improvements and fixups - Better error messages if type constraints fail - Better suggestions in case of errors - Handle enum type constraints in usage info - Display application documentation 1.28 2014-03-25 - Fix failing tests (reported by Michael Greb and Dagfinn Ilmari Mannsåker) 1.27 2014-03-02 - Fix warnings on warnings on 5.18 again - Documentation - Fix spelling (fixed by Gregor Herrmann) 1.26 2014-02-24 - Fix failing tests 1.25 2014-02-23 - Allow multiple command namespaces (implemented by Thilo Fester) - Documentation 1.24 2014-02-14 - Fix POD warnings (fixed by David Golden) - Always reuse existing MooseX::App::ParsedArgv instances - Parse @ARGV as soon as possible - Fix Win32 colorisation issues (fixed by J.R. Mash) - Add app_prefer_commandline option 1.23 2014-01-27 - Documentation - Manual plugin - More inheritance tests - Cleanup deprecated code 1.22 2013-05-24 - Silence experimental::smartmatch warnings on 5.18 (fixed by Mike Doherty) 1.21 2013-04-13 - Fix option sorting - Fix parsing of positional parameters 1.20 2013-04-08 - Add cmd_split and cmd_position option - Fixed parameter position (fixed by Yanick Champoux) - app_strict option to set if app should terminate when unknown parameters or options are supplied 1.19 2013-03-28 - Fixed failing tests - Fixed bug that was triggered by Moose 2.0800 - Fixed on MSWin 1.18 2013-03-24 - Added positional parameters with 'parameter' keyword (Attention: this change might break things if you used to work with @extra) - Parameters are handled in the meta class - Usage meta class methods refactored 1.17 2013-03-06 - Fix failing tests 1.16 2013-02-27 - Better license parsing - Fix failing tests - Use Class::Load instead of Class::MOP to load classes - Remove MooseX::Getopt dependency. Parse @ARGV ourself - Renamed meta class methods to use single prefix - Moved meta class methods to attribute meta class - Much more tests (95% statement and 90% total coverage) - Better error handling for Environment plugin 1.15 2013-01-18 - Fix wrong attribute initialisation order 1.14 2013-01-15 - Fix failing test - Update documentation - Optional usage information from POD (implemented by Yanick Champoux) - app_fuzzy now defaults to true - Version plugin prints license and copyright 1.13 2013-01-11 - Fix failing test - Update documentation 1.12 2013-01-10 - Fix failing test - Fix pod (Andrew Jones) 1.11 2013-01-08 - Parse DistZilla ABSTRACT for documentation - Improve tutorial and fix typo (fixed by George Hartzell) - Saner bash completion and version plugin - Fix fuzzy command and attribute matching - Deprecate fuzzy plugin, use typo plugin instead - Handle shell character encodings - More tests 1.10 2013-01-07 - Fix bash completion plugin (fixed by Steve Nolte) 1.09 2012-11-22 - Fix failing load test 1.08 2012-11-17 - Refactor object initialisation - Fix missing bash-completion prefix (fixed by Steve Nolte) - Require latest MooseX::Getopt (fixed by Steve Nolte) - Fix Plugin::Version docs RT81186 (fixed by Michael G) - Update documentation 1.07 2012-08-22 - Fix failing load tests 1.06 2012-08-20 - Single command interface (MooseX::App::Simple) - Fuzzy command matching plugin - Only lowercase command names - Environment plugin - Version plugin - Various cleanups 1.05 2012-06-04 - Fix broken load tests - Join M::A::Meta::Attribute::Base and M::A::Meta::Attribute::Option 1.04 2012-06-02 - Fix bugs in BashCompletion plugin - Remove code duplication - Fix --help flag in command classes - Fix pod to text conversion 1.03 2012-06-02 - Do not expose all attributes as options but only those defined via 'option' keyword - More tests - Internal changes (move methods to meta class, calculate loadable commands only once, ...) - Fix various bugs 1.02 2012-04-15 - Fix command usage generation bug - Automatically apply MooseX-Getopt attribute traits - Rename command_tag to cmd_tag attribute 1.01 2012-04-12 - Fix text failures - Fix Pod - Add missing tutorials to manifest 1.00 2012-04-07 - Initial version MooseX-App-1.33/LICENCE000644 000765 000024 00000050101 11014620472 014633 0ustar00marosstaff000000 000000 Terms of Perl 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 General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU 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. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), 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 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 show them these terms so they know 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. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 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 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 derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 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 License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 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. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary 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 License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 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 Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing 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 for copying, distributing or modifying the Program or works based on it. 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. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. 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 this 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 this License, you may choose any version ever published by the Free Software Foundation. 10. 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 11. 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. 12. 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 --------------------------------------------------------------------------- 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. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. 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 MooseX-App-1.33/MANIFEST000644 000765 000024 00000006376 12514113013 015010 0ustar00marosstaff000000 000000 Changes inc/Module/Install.pm inc/Module/Install/AuthorRequires.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/ReadmeFromPod.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm lib/MooseX/App.pm lib/MooseX/App/Command.pm lib/MooseX/App/Exporter.pm lib/MooseX/App/Message/Block.pm lib/MooseX/App/Message/BlockColor.pm lib/MooseX/App/Message/Envelope.pm lib/MooseX/App/Meta/Role/Attribute/Option.pm lib/MooseX/App/Meta/Role/Class/Base.pm lib/MooseX/App/Meta/Role/Class/Command.pm lib/MooseX/App/Meta/Role/Class/Documentation.pm lib/MooseX/App/Meta/Role/Class/Simple.pm lib/MooseX/App/ParsedArgv.pm lib/MooseX/App/ParsedArgv/Element.pm lib/MooseX/App/Plugin/BashCompletion.pm lib/MooseX/App/Plugin/BashCompletion/Command.pm lib/MooseX/App/Plugin/BashCompletion/Meta/Class.pm lib/MooseX/App/Plugin/Color.pm lib/MooseX/App/Plugin/Color/Meta/Class.pm lib/MooseX/App/Plugin/Config.pm lib/MooseX/App/Plugin/Config/Meta/Class.pm lib/MooseX/App/Plugin/ConfigHome.pm lib/MooseX/App/Plugin/ConfigHome/Meta/Class.pm lib/MooseX/App/Plugin/Depends.pm lib/MooseX/App/Plugin/Depends/Meta/Attribute.pm lib/MooseX/App/Plugin/Depends/Meta/Class.pm lib/MooseX/App/Plugin/Env.pm lib/MooseX/App/Plugin/Fuzzy.pm lib/MooseX/App/Plugin/Man.pm lib/MooseX/App/Plugin/Man/Command.pm lib/MooseX/App/Plugin/Man/Meta/Class.pm lib/MooseX/App/Plugin/MutexGroup.pm lib/MooseX/App/Plugin/MutexGroup/Meta/Attribute.pm lib/MooseX/App/Plugin/MutexGroup/Meta/Class.pm lib/MooseX/App/Plugin/Term.pm lib/MooseX/App/Plugin/Term/Meta/Attribute.pm lib/MooseX/App/Plugin/Term/Meta/Class.pm lib/MooseX/App/Plugin/Typo.pm lib/MooseX/App/Plugin/Typo/Meta/Class.pm lib/MooseX/App/Plugin/Version.pm lib/MooseX/App/Plugin/Version/Command.pm lib/MooseX/App/Plugin/Version/Meta/Class.pm lib/MooseX/App/Role.pm lib/MooseX/App/Role/Base.pm lib/MooseX/App/Role/Common.pm lib/MooseX/App/Simple.pm lib/MooseX/App/Tutorial.pod lib/MooseX/App/Utils.pm lib/MooseX/App/WritingPlugins.pod LICENCE Makefile.PL MANIFEST This list of files META.yml README t/00_load.t t/01_basic.t t/02_meta.t t/03_utils.t t/04_plugin_config.t t/05_extended.t t/06_env.t t/07_single.t t/08_plugin_various.t t/09_classes.t t/10_plugin_mutexgroup.t t/11_process.t t/12_plugin_depends.t t/config.pl t/example/test01.pl t/example/test02.pl t/example/test03.pl t/example/test04.pl t/example/test05.pl t/example/test06.pl t/example/test07.pl t/example/test08.pl t/testlib/MyMessage.pm t/testlib/Test01.pm t/testlib/Test01/CommandA.pm t/testlib/Test01/CommandB.pm t/testlib/Test01/CommandC1.pm t/testlib/Test01/CommandD.pm t/testlib/Test02.pm t/testlib/Test02/Command/Error.pm t/testlib/Test02/Command/Record.pm t/testlib/Test02/Command/Required.pm t/testlib/Test02/MoreCommands/Test.pm t/testlib/Test03.pm t/testlib/Test03/AnotherCommand.pm t/testlib/Test03/BrokenCommand.pm t/testlib/Test03/ExtraCommand.pm t/testlib/Test03/Role/TestRole.pm t/testlib/Test03/SomeCommand.pm t/testlib/Test03/YetAnotherCommand.pm t/testlib/Test03CommandBase.pm t/testlib/Test04.pm t/testlib/Test04Base.pm t/testlib/Test05.pm t/testlib/Test06.pm t/testlib/Test06/CommandA.pm t/testlib/Test06/CommandB.pm t/testlib/Test07.pm t/testlib/Test08.pm TODO xt/perlcritic.t xt/pod.t xt/podcoverage.t xt/podstyle.t MooseX-App-1.33/META.yml000644 000765 000024 00000001636 12514112767 015141 0ustar00marosstaff000000 000000 --- abstract: 'Write user-friendly command line apps with even less suffering' author: - 'Maroš Kollár' build_requires: ExtUtils::MakeMaker: 6.59 Test::Most: 0 Test::NoWarnings: 0 configure_requires: ExtUtils::MakeMaker: 6.59 distribution_type: module dynamic_config: 1 generated_by: 'Module::Install version 1.10' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-App no_index: directory: - inc - t - xt recommends: File::HomeDir: 0 IO::Interactive: 0 Term::ANSIColor: 0 Term::ReadKey: 0 Text::WagnerFischer: 0 requires: Config::Any: 0 List::Util: 0 Module::Pluggable: 0 Moose: '2.00' MooseX::Types::Path::Class: 0 Path::Class: 0 Pod::Elemental: 0 namespace::autoclean: 0 perl: 5.10.0 resources: license: http://dev.perl.org/licenses/ repository: git://github.com/maros/MooseX-App.git version: '1.33' MooseX-App-1.33/Makefile.PL000644 000765 000024 00000002640 12454262644 015641 0ustar00marosstaff000000 000000 # Load the Module::Install bundled in ./inc/ use strict; use inc::Module::Install 1.05; my $from = 'lib/MooseX/App.pm'; # Define metadata name 'MooseX-App'; all_from $from; readme_from $from; perl_version '5.010'; # Specific dependencies requires 'Moose' => '2.00'; requires 'namespace::autoclean' => 0; requires 'Module::Pluggable' => 0; requires 'Path::Class' => 0; requires 'MooseX::Types::Path::Class' => 0; requires 'Config::Any' => 0; requires 'List::Util' => 0; requires 'Pod::Elemental' => 0; recommends 'IO::Interactive' => 0; recommends 'Term::ReadKey' => 0; recommends 'Term::ANSIColor' => 0; recommends 'File::HomeDir' => 0; recommends 'Text::WagnerFischer' => 0; if ($^O eq 'MSWin32') { recommends 'Win32::Console::ANSI'; } build_requires 'Test::Most' => 0; build_requires 'Test::NoWarnings' => 0; author_requires 'Test::Pod' => '1.14'; author_requires 'Test::Pod::Coverage' => '1.04'; author_requires 'Test::Perl::Critic' => 0; author_requires 'Module::Install::ReadmeFromPod'=> 0; repository 'git://github.com/maros/MooseX-App.git'; WriteAll;MooseX-App-1.33/README000644 000765 000024 00000031006 12514112766 014541 0ustar00marosstaff000000 000000 NAME MooseX::App - Write user-friendly command line apps with even less suffering SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Color); option 'global_option' => ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); # Global option has 'private' => ( is => 'rw', ); # not exposed Write multiple command classes (If you have only a single command class you should use MooseX::App::Simple instead) package MyApp::SomeCommand; use MooseX::App::Command; # important (also imports Moose) extends qw(MyApp); # optional, only if you want to use global options from base class # Positional parameter parameter 'some_parameter' => ( is => 'rw', isa => 'Str', required => 1, documentation => q[Some parameter that you need to supply], ); option 'some_option' => ( is => 'rw', isa => 'Int', required => 1, documentation => q[Very important option!], ); # Option sub run { my ($self) = @_; # Do something } And then you need a simple wrapper script (called eg. myapp): #!/usr/bin/env perl use MyApp; MyApp->new_with_command->run; On the command line: bash$ myapp help usage: myapp [long options...] myapp help global options: --global_option Enable this to do fancy stuff [Flag] --help --usage -? Prints this usage information. [Flag] available commands: some_command Description of some command another_command Description of another command help Prints this usage information or bash$ myapp some_command --help usage: myapp some_command [long options...] myapp help myapp some_command --help parameters: some_parameter Some parameter that you need to supply [Required] options: --global_option Enable this to do fancy stuff [Flag] --some_option Very important option! [Int,Required] --help --usage -? Prints this usage information. [Flag] DESCRIPTION MooseX-App is a highly customisable helper to write user-friendly command line applications without having to worry about most of the annoying things usually involved. Just take any existing Moose class, add a single line ("use MooseX-App qw(PluginA PluginB ...);") and create one class for each command in an underlying namespace. Options and positional parameters can be defined as simple Moose accessors. MooseX-App will then * Find, load and initialise the command classes (see MooseX-App-Simple for single command applications) * Create automated help and documentation from modules POD as well as attributes metadata and type constraints * Read, encode and validate the command line options and positional parameters entered by the user from @ARGV and %ENV (and possibly prompt the user for additional parameters see MooseX-App-Plugin-Term) * Provide helpful error messages if user input cannot be validated (either missing or wrong attributes or Moose type constraints not satisfied) Commandline options are defined using the 'option' keyword which accepts the same attributes as Moose' 'has' keyword. option 'some_option' => ( is => 'rw', isa => 'Str', ); This is equivalent to has 'some_option' => ( is => 'rw', isa => 'Str', traits => ['AppOption'], # Load extra metaclass cmd_type => 'option', # Set attribute type ); Single letter options are treated as flags and may be combined with eachother. Positional parameters are defined with the 'parameter' keyword parameter 'some_option' => ( is => 'rw', isa => 'Str', ); This is equivalent to has 'some_option' => ( is => 'rw', isa => 'Str', traits => ['AppOption'], cmd_type => 'parameter', ); Furthermore, all options and parameters can also be supplied via %ENV option 'some_option' => ( is => 'rw', isa => 'Str', cmd_env => 'SOME_OPTION', ); Read the Tutorial for getting started with a simple MooseX::App command line application. METHODS new_with_command my $myapp_command = MyApp->new_with_command(); This constructor reads the command line arguments and tries to create a command class instance. If it fails it retuns a MooseX::App::Message::Envelope object holding an error message. You can pass a hash of default/fallback params to new_with_command my $obj = MyApp->new_with_command(%default); initialize_command_class my $obj = MyApp->initialize_command_class($command_name,%default); Helper method to instantiate the command class for the given command. GLOBAL OPTIONS app_base app_base 'my_script'; # Defaults to $0 Usually MooseX::App will take the name of the calling wrapper script to construct the program name in various help messages. This name can be changed via the app_base function. app_fuzzy app_fuzzy(1); # default OR app_fuzzy(0); Enables fuzzy matching of commands and attributes. Is turned on by default. app_strict app_strict(0); # default OR app_strict(1); If strict is enabled the program will terminate with an error message if superfluous/unknown positional parameters are supplied. If disabled all extra parameters will be copied to the extra_argv attribute. The command_strict config in the command classes allows one to set this option individually for each command in the respective command class. app_prefer_commandline app_prefer_commandline(0); # default or app_prefer_commandline(1); Specifies if parameters/options supplied via @ARGV,%ENV should take precedence over arguments passed to new_with_command. app_namespace app_namespace 'MyApp::Commands', 'YourApp::MoreCommands'; OR app_namespace(); Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed and you can add multiple extra namespaces. If app_namespace is called with no parameters then autoloading of command classes will be disabled entirely. app_command_name app_command_name { my ($package) = shift; # munge package name; return $command_name; }; This coderef can be used to control how autoloaded package names should be translated to command names. app_command_register app_command_register do => 'MyApp::Commands::DoSomething', undo => 'MyApp::Commands::UndoSomething'; This keyword can be used to register additional commands. Especially usefull in conjunction with app_namespace. app_description app_description qq[Description text]; Set the description. If not set this information will be taken from the Pod DESCRIPTION or OVERVIEW sections. app_usage app_usage qq[myapp --option ...]; Set custom usage. If not set this will be taken from the Pod SYNOPSIS or USAGE section. If both sections are not available, the usage information will be autogenerated. GLOBAL ATTRIBUTES All MooseX::App classes will have two extra attributes extra_argv Carries all parameters from @ARGV that were not consumed (only if app_strict is turned off, otherwise superfluous parameters will raise an exception). help_flag Help flag that is set when help was requested. ATTRIBUTE OPTIONS Options and parameters accept extra attributes for customisation: * cmd_tags - Extra tags (as used by the help) * cmd_flag - Override option/parameter name * cmd_aliases - Additional option/parameter names * cmd_split - Split values into ArrayRefs * cmd_position - Specify option/parameter order in help * cmd_env - Read options/parameters from %ENV * cmd_count - Value of option equals to number of occurences in @ARGV Refer to MooseX::App::Meta::Role::Attribute::Option for detailed documentation. METADATA MooseX::App will use your class metadata and POD to construct the commands and helpful error- or usage- messages. These bits of information are utilised and should be provided if possible: * Package names * required options for Moose attributes * documentation options for Moose attributes * Moose type constraints (Bool, ArrayRef, HashRef, Int, Num, and Enum) * Documentation set via app_description, app_usage, command_short_description, command_long_description and command_usage * POD (NAME, ABSTRACT, DESCRIPTION, USAGE, SYNOPSIS, OVERVIEW, COPYRIGHT, LICENSE, COPYRIGHT AND LICENSE, AUTHOR and AUTHORS sections) * Dzil ABSTRACT tag if no POD is available yet PLUGINS The behaviour of MooseX-App can be customised with plugins. To load a plugin just pass a list of plugin names after the "use MooseX-App" statement. (Attention: order sometimes matters) use MooseX::App qw(PluginA PluginB); Currently the following plugins are shipped with MooseX::App * MooseX::App::Plugin::BashCompletion Adds a command that genereates a bash completion script for your application. * MooseX::App::Plugin::Color Colorful output for your MooseX::App applications. * MooseX::App::Plugin::Config Config files for MooseX::App applications. * MooseX::App::Plugin::ConfigHome Search config files in users home directory. * MooseX::App::Plugin::Term Prompt user for options and parameters that were not provided via options or params. Prompt offers basic editing capabilities and history * MooseX::App::Plugin::Typo Handle typos in command names and provide suggestions. * MooseX::App::Plugin::Version Adds a command to display the version and license of your application. * MooseX::App::Plugin::Man Display full manpage of application and commands. * MooseX::App::Plugin::MutexGroup Allow for mutally exclusive options * MooseX::App::Plugin::Depends Adds dependent options Refer to Writing MooseX-App Plugins for documentation on how to create your own plugins. CAVEATS & KNOWN BUGS Startup time may be an issue - escpecially if you load many plugins. If you do not require the functionality of plugins and ability for fine grained customisation (or Moose for that matter) then you should probably use MooX::Options or MooX::Cmd. In some cases - especially when using non-standard class inheritance - you may end up with command classes lacking the help attribute. In this case you need to include the following line in your base class with qw(MooseX::App::Role::Common); SEE ALSO Read the Tutorial for getting started with a simple MooseX::App command line application. For alternatives you can check out MooseX::App::Cmd, MooseX::Getopt, MooX::Options, MooX::Cmd and App::Cmd SUPPORT Please report any bugs or feature requests to "bug-moosex-app@rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your report as I make changes. AUTHOR Maroš Kollár CPAN ID: MAROS maros [at] k-1.com http://www.k-1.com CONTRIBUTORS Special thanks to all contributors. In no particular order: Andrew Jones, George Hartzell, Steve Nolte, Michael G, Thomas Klausner, Yanick Champoux, Edward Baudrez, David Golden, J.R. Mash, Thilo Fester, Gregor Herrmann, Sergey Romanov, Sawyer X, Roman F., Hunter McMillen, Maik Hentsche COPYRIGHT MooseX::App is Copyright (c) 2012-15 Maroš Kollár. This library is free software and may be distributed under the same terms as perl itself. The full text of the licence can be found in the LICENCE file included with this module. MooseX-App-1.33/TODO000644 000765 000024 00000004542 12472011727 014354 0ustar00marosstaff000000 000000 A list of TODO tasks sorted by priority if you are interested in improving MooseX::App * Alias command names (Difficulty:Medium) * Permute (Difficulty:Medium) * see Getopt::Long permute * "--attr val1 --attr val2" vs. "--attr val1 val2" * Better support for Hashref attrs (Difficulty:Medium) * optionally use colons (or any other character) instead of equal signs as key-value separators * allow to specify multiple pairs in one attribute. ie. instead of --hash key=value --hash anotherkey=anothervalue allow the following syntax --hash key=value anotherkey=anothervalue also see permute * Getopt::Long compatibility (Difficulty:Medium) * coordinates=f{2} - Accept multiple values per key (see permute) * ! - Negation * Nested subcommands (Difficulty:Medium-Hard) * ie. "mycommand.pl some command" would translate to "MyCommand::Some::Command" * How to distinguish between subcommands and positional params? * Make sure that help handles subcomands (ie. "mycommand.pl some help" returns a list of available subcommands for "some") * Make sure that the typo plugin handles subcommands * Handle type constraint unions (Difficulty:Easy) * generating description for attributes * Better positional param detection (Difficulty:Medium) * Term plugin (Difficulty:Easy) * History callbacks * Bash completiton plugin (Difficulty:Easy-Medium) * Handle enum type constraints * Hide in help (?) * Hide bash completion from bash completion * Documentation * General improvements * Extend tutorials * Clarify and highlight MooseX::App::Simple * Add recipes (aka Moose recipes) * Better error messages on unrecognised params (Difficulty:Medium) * Improve "Did you mean ..." suggestions * Suggestions if attribute was supplied with only one leading dash * Rework Testsuite (Difficulty:Medium) * Testsuite fixtures are currently a mess * Allow alternative param/attribute syntax (Difficulty:Easy-Medium) * I18N (Difficulty:Hard) * Based on current user locale * Register languages * Register strings (ie by plugins) * How to handle PODs? * Language fallbacks * Allow to specify command documentation in multiple languages * Virtual attributes (Difficulty:Medium) * Handled via callbacks * Not sure if really needed - find workaround and add howto pod MooseX-App-1.33/inc/000755 000765 000024 00000000000 12514113027 014421 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/000755 000765 000024 00000000000 12514113027 014416 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/000755 000765 000024 00000000000 12514113027 014113 5ustar00marosstaff000000 000000 MooseX-App-1.33/xt/000755 000765 000024 00000000000 12514113027 014303 5ustar00marosstaff000000 000000 MooseX-App-1.33/xt/perlcritic.t000644 000765 000024 00000001010 11763711152 016630 0ustar00marosstaff000000 000000 #!perl -T use strict; use warnings; use File::Spec; use Test::More; use English qw(-no_match_vars); if ( not $ENV{TEST_AUTHOR} ) { my $msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.'; plan( skip_all => $msg ); } eval " use Test::Perl::Critic (-severity => 4, -exclude => ['ProhibitSubroutinePrototypes','ProhibitMultiplePackages'] ); "; if ( $EVAL_ERROR ) { my $msg = 'Test::Perl::Critic required to criticise code'; plan( skip_all => $msg ); } Test::Perl::Critic::all_critic_ok(); MooseX-App-1.33/xt/pod.t000644 000765 000024 00000000336 11003046630 015251 0ustar00marosstaff000000 000000 use strict; use warnings; use Test::More; eval "use Test::Pod 1.14"; plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_AUTHOR to enable this test' unless $ENV{TEST_AUTHOR}; all_pod_files_ok(); MooseX-App-1.33/xt/podcoverage.t000644 000765 000024 00000000365 11003046630 016767 0ustar00marosstaff000000 000000 use strict; use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@; plan skip_all => 'set TEST_AUTHOR to enable this test' unless $ENV{TEST_AUTHOR}; all_pod_coverage_ok(); MooseX-App-1.33/xt/podstyle.t000644 000765 000024 00000001735 11451766000 016345 0ustar00marosstaff000000 000000 use strict; use warnings; use Test::More; eval "use Pod::Simple::SimpleTree"; plan skip_all => 'Pod::Simple::SimpleTree required' if $@; eval "use Test::Pod"; plan skip_all => 'Test::Pod required' if $@; plan skip_all => 'set TEST_AUTHOR to enable this test' unless $ENV{TEST_AUTHOR}; my @files; foreach (all_pod_files()) { next if /Schema\//; next if /\.pl$/; push @files,$_; } my @required_heads=qw(NAME SYNOPSIS DESCRIPTION METHODS AUTHOR); plan tests => scalar @files * scalar @required_heads; foreach my $file (@files) { my $parser=Pod::Simple::SimpleTree->new; $parser->accept_targets('*'); my $root=$parser->parse_file($file)->root; shift(@$root);shift(@$root); my @heads; my %heads; foreach my $node (@$root) { next unless $node->[0] eq 'head1'; push(@heads,$node->[2]); $heads{$node->[2]}=1; } foreach my $heading (@required_heads) { ok($heads{$heading},"$file has $heading"); } } MooseX-App-1.33/t/00_load.t000755 000765 000024 00000006017 12501005032 015515 0ustar00marosstaff000000 000000 # -*- perl -*- # t/00_load.t - check module loading and create testing directory use Test::Most tests => 43; use_ok( 'MooseX::App' ); use_ok( 'MooseX::App::ParsedArgv' ); use_ok( 'MooseX::App::Command' ); #use_ok( 'MooseX::App::Role' ); # cannot test since it can only be loaded into a Moose::Role use_ok( 'MooseX::App::Utils' ); use_ok( 'MooseX::App::Message::Block' ); use_ok( 'MooseX::App::Message::Envelope' ); use_ok( 'MooseX::App::Meta::Role::Attribute::Option' ); use_ok( 'MooseX::App::Meta::Role::Class::Base' ); use_ok( 'MooseX::App::Meta::Role::Class::Command' ); use_ok( 'MooseX::App::Meta::Role::Class::Simple' ); use_ok( 'MooseX::App::Meta::Role::Class::Documentation'); use_ok( 'MooseX::App::Plugin::BashCompletion' ); use_ok( 'MooseX::App::Plugin::BashCompletion::Command'); use_ok( 'MooseX::App::Plugin::BashCompletion::Meta::Class'); use_ok( 'MooseX::App::Plugin::Config' ); use_ok( 'MooseX::App::Plugin::Config::Meta::Class'); use_ok( 'MooseX::App::Plugin::Version' ); use_ok( 'MooseX::App::Plugin::Version::Command'); use_ok( 'MooseX::App::Plugin::Version::Meta::Class'); use_ok( 'MooseX::App::Plugin::Man' ); use_ok( 'MooseX::App::Plugin::Man::Command'); use_ok( 'MooseX::App::Plugin::Man::Meta::Class'); use_ok( 'MooseX::App::Plugin::Depends' ); use_ok( 'MooseX::App::Plugin::Depends::Meta::Attribute'); use_ok( 'MooseX::App::Plugin::Depends::Meta::Class'); use_ok( 'MooseX::App::Plugin::MutexGroup' ); use_ok( 'MooseX::App::Plugin::MutexGroup::Meta::Attribute'); use_ok( 'MooseX::App::Plugin::MutexGroup::Meta::Class'); use_ok( 'MooseX::App::Utils'); use_ok( 'MooseX::App::Simple'); use_ok( 'MooseX::App::Exporter'); use_ok( 'MooseX::App::Role::Base'); use_ok( 'MooseX::App::Role::Common'); SKIP :{ my $ok = eval { Class::Load::load_class('Term::ReadKey'); Class::Load::load_class('IO::Interactive'); use_ok( 'MooseX::App::Plugin::Term' ); use_ok( 'MooseX::App::Plugin::Term::Meta::Class'); use_ok( 'MooseX::App::Plugin::Term::Meta::Attribute'); }; unless ($ok) { skip "Term::ReadKey and/or IO::Interactive are not installed",3; } } SKIP :{ my $ok = eval { Class::Load::load_class('Term::ANSIColor'); Class::Load::load_class('IO::Interactive'); use_ok( 'MooseX::App::Plugin::Color' ); use_ok( 'MooseX::App::Message::BlockColor' ); use_ok( 'MooseX::App::Plugin::Color::Meta::Class'); }; unless ($ok) { skip "Term::ANSIColor and/or IO::Interactive are not installed",3; } } SKIP :{ my $ok = eval { Class::Load::load_class('File::HomeDir'); use_ok( 'MooseX::App::Plugin::ConfigHome' ); use_ok( 'MooseX::App::Plugin::ConfigHome::Meta::Class'); }; unless ($ok) { skip "File::HomeDir is not installed",2; } } SKIP :{ my $ok = eval { Class::Load::load_class('Text::WagnerFischer'); use_ok( 'MooseX::App::Plugin::Typo' ); use_ok( 'MooseX::App::Plugin::Typo::Meta::Class'); }; unless ($ok) { skip "Text::WagnerFischer is not installed",2; } }MooseX-App-1.33/t/01_basic.t000755 000765 000024 00000013430 12465615274 015705 0ustar00marosstaff000000 000000 # -*- perl -*- # t/01_basic.t - Basic tests use Test::Most tests => 12+1; use Test::NoWarnings; use FindBin qw(); use lib 't/testlib'; use Test01; subtest 'Excact command with option' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --global 10)]); my $test01 = Test01->new_with_command(); isa_ok($test01,'Test01::CommandA'); is($test01->global,10,'Param is set'); }; subtest 'Fuzzy command with option' => sub { MooseX::App::ParsedArgv->new(argv => [qw(Command_A --globa 10)]); my $test02 = Test01->new_with_command(); isa_ok($test02,'Test01::CommandA'); is($test02->global,10,'Param is set'); }; subtest 'Wrong command' => sub { MooseX::App::ParsedArgv->new(argv => [qw(xxxx --global 10)]); my $test03 = Test01->new_with_command; isa_ok($test03,'MooseX::App::Message::Envelope'); is($test03->blocks->[0]->header,"Unknown command 'xxxx'",'Message is set'); is($test03->blocks->[0]->type,"error",'Message is of type error'); is($test03->blocks->[1]->header,"usage:",'Usage set'); is($test03->blocks->[1]->body," 01_basic.t [long options...] 01_basic.t help 01_basic.t --help",'Usage body set'); is($test03->blocks->[3]->header,"global options:",'Global options set'); is($test03->blocks->[3]->body," --config Path to command config file --global test [Required; Integer; Important!] --help -h --usage -? Prints this usage information. [Flag]",'Global options body set'); is($test03->blocks->[4]->header,"available commands:",'Available commands set'); is($test03->blocks->[4]->body," command_a Command A! command_b Test class command B for test 01 command_c1 Test C1 command_d Command A! help Prints this usage information",'Available commands body set'); }; subtest 'Help for command' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --help)]); my $test04 = Test01->new_with_command; isa_ok($test04,'MooseX::App::Message::Envelope'); is($test04->blocks->[0]->header,"usage:",'Usage is set'); is($test04->blocks->[0]->body," 01_basic.t command_a [long options...] 01_basic.t help 01_basic.t command_a --help",'Usage body set'); is($test04->blocks->[1]->header,"description:",'Description is set'); is($test04->blocks->[1]->body," Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dui velit, varius nec iaculis vitae, elementum eget mi. * bullet1 * bullet2 * bullet3 Cras eget mi nisi. In hac habitasse platea dictumst.",'Description body set'); is($test04->blocks->[2]->header,"options:",'Options header is set'); is($test04->blocks->[2]->body," --command_local1 some docs about the long texts that seem to occur randomly [Integer; Env: LOCAL1; Important] --command_local2 Verylongwordwithoutwhitespacestotestiftextformating worksproperly [Env: LOCAL2] --config Path to command config file --global test [Required; Integer; Important!] --help -h --usage -? Prints this usage information. [Flag]",'Options body is set'); }; subtest 'With extra args' => sub { MooseX::App::ParsedArgv->new(argv => [qw(Command_b --global 10 --param_b aaa)]); my $test02 = Test01->new_with_command( 'param_b' => 'bbb', 'global' => 20, 'private'=>5 ); isa_ok($test02,'Test01::CommandB'); is($test02->global,20,'Param global is set'); is($test02->param_b,'bbb','Param param_b is set'); is($test02->private,5,'Param private is set'); }; subtest 'Wrapper script' => sub { my $output = `$^X $FindBin::Bin/example/test01.pl command_a --command_local2 test --global 10`; is($output,'RUN COMMAND-A:test','Output is ok'); }; subtest 'Custom help text' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_b --help)]); my $test06 = Test01->new_with_command; isa_ok($test06,'MooseX::App::Message::Envelope'); is($test06->blocks->[0]->header,"usage:",'Usage is set'); is($test06->blocks->[0]->body," use with care",'Usage is ok'); is($test06->blocks->[1]->header,"description:",'description is set'); like($test06->blocks->[1]->body,qr/ Some description of \*command B\*/,'Description is ok'); }; subtest 'Input errors missing' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --command_local1)]); my $test07 = Test01->new_with_command; isa_ok($test07,'MooseX::App::Message::Envelope'); is($test07->blocks->[0]->header,"Missing value for 'command_local1'",'Error message ok'); }; subtest 'Input errors type' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --command_local1 sss)]); my $test08 = Test01->new_with_command; isa_ok($test08,'MooseX::App::Message::Envelope'); is($test08->blocks->[0]->header,"Invalid value for 'command_local1'",'Error message ok'); is($test08->blocks->[0]->body,"Value must be an integer (not 'sss')",'Error message ok'); }; subtest 'Global help requested' => sub { MooseX::App::ParsedArgv->new(argv => [qw(help)]); my $test09 = Test01->new_with_command; isa_ok($test09,'MooseX::App::Message::Envelope'); like($test09->blocks->[0]->body,qr/ 01_basic\.t \[long options\.\.\.\]/,'Help message ok'); }; subtest 'Missing command' => sub { MooseX::App::ParsedArgv->new(argv => []); my $test10 = Test01->new_with_command; isa_ok($test10,'MooseX::App::Message::Envelope'); is($test10->blocks->[0]->header,'Missing command','Error message ok'); }; subtest 'Extra params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a something else)]); my $test11 = Test01->new_with_command; isa_ok($test11,'MooseX::App::Message::Envelope'); is($test11->blocks->[0]->header,"Unknown parameter 'else'",'Error message ok'); }; MooseX-App-1.33/t/02_meta.t000644 000765 000024 00000006222 12465615274 015551 0ustar00marosstaff000000 000000 # -*- perl -*- # t/02_meta.t - MOP tests use Test::Most tests => 28+1; use Test::NoWarnings; use lib 't/testlib'; use Test01; my $meta = Test01->meta; my $commands = $meta->app_commands; is(join(',',sort keys %{$commands}),'command_a,command_b,command_c1,command_d','Commands found'); is(join(',',sort values %{$commands}),'Test01::CommandA,Test01::CommandB,Test01::CommandC1,Test01::CommandD','Commands found'); cmp_deeply($meta->app_namespace,[qw(Test01)],'Command namespace ok'); is($meta->app_base,'02_meta.t','Command base ok'); is($meta->app_messageclass,'MooseX::App::Message::Block','Message class'); ok(Test01->can('new_with_command'),'Role applied to base class'); ok(Test01->can('initialize_command_class'),'Role applied to base class'); is(scalar keys %{$commands},4,'Found three commands'); is($commands->{command_a},'Test01::CommandA','Command A found'); is($meta->command_find('COMMAND_a'),'command_a','Command A matched'); cmp_deeply($meta->command_candidates('COmmand'),['command_a','command_b','command_c1','command_d'],'Command A,B,C1 and D matched'); cmp_deeply($meta->command_candidates('command_C'),['command_c1'],'Command C1 matched fuzzy'); is($meta->command_candidates('command_c1'),'command_c1','Command C1 matched exactly'); my @attributes = $meta->command_usage_attributes; is(scalar(@attributes),3,'Has three attributes'); is($attributes[0]->cmd_usage_name,'--global','Usage name ok'); is($attributes[0]->cmd_usage_description,'test [Required; Integer; Important!]','Usage description ok'); is($attributes[1]->cmd_usage_name,'--config','Usage name ok'); is($attributes[2]->cmd_usage_name,'--help -h --usage -?','Usage name ok'); is($attributes[2]->cmd_usage_description,'Prints this usage information. [Flag]','Usage description ok'); my $meta_attribute = $meta->find_attribute_by_name('global'); is(join(',',$meta_attribute->cmd_tags_list($meta_attribute)),'Required,Integer,Important!','Tags ok'); $meta_attribute->cmd_tags(['Use with care']); is(join(',',$meta_attribute->cmd_tags_list()),'Required,Integer,Use with care','Changed tags ok'); require Test01::CommandA; my $description = $meta->command_usage_description(Test01::CommandA->meta); isa_ok($description,'MooseX::App::Message::Block'); like($description->body,qr/varius nec iaculis vitae/,'Description body ok'); require Test01::CommandB; is(Test01::CommandB->meta->command_short_description,'Test class command B for test 01','Pod short description parsed ok'); is(Test01::CommandB->meta->command_long_description,'Some description of *command B* some code some code some more desc * item 1 * item 2 * item 2.1 * item 2.2 hase ist so super and this is a very long sentence witch breaks after i have written some bla bla. another interesting paragraph.','Pod long description parsed ok'); require Test01::CommandC1; is(Test01::CommandB->meta->command_usage,'use with care','Command usage parsed ok'); is(Test01::CommandC1->meta->find_attribute_by_name('param_internal_name')->cmd_name_primary,'external_name','Attribute name ok'); is(join(',',Test01::CommandB->meta->find_attribute_by_name('param_b')->cmd_tags_list),'Required,Possible values: aaa, bbb, ccc, ddd, eee, fff','Check attributes tags');MooseX-App-1.33/t/03_utils.t000755 000765 000024 00000007200 12454262633 015757 0ustar00marosstaff000000 000000 # -*- perl -*- # t/03_utils.t use Test::Most tests => 4+1; use Test::NoWarnings; use MooseX::App::Utils; use MooseX::App::ParsedArgv; subtest 'Class to command' => sub { is(MooseX::App::Utils::class_to_command('Command'),'command','Command ok'); is(MooseX::App::Utils::class_to_command('CommandSuper'),'command_super','Command ok'); is(MooseX::App::Utils::class_to_command('CommandBA'),'command_ba','Command ok'); is(MooseX::App::Utils::class_to_command('CommandBA12'),'command_ba12','Command ok'); is(MooseX::App::Utils::class_to_command('CommandBALow'),'command_ba_low','Command ok'); }; subtest 'Format text' => sub { is( MooseX::App::Utils::format_text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae lectus purus, quis dapibus orci. Proin mollis est in nisl congue vel ornare felis imperdiet.'), ' Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vitae lectus purus, quis dapibus orci. Proin mollis est in nisl congue vel ornare felis imperdiet.', 'Format text ok'); is( MooseX::App::Utils::format_text('Loremipsumdolorsitamet,consecteturadipiscingelit.Namegetarcunecdolorbibendumblanditsitametnonipsum.'), ' Loremipsumdolorsitamet,consecteturadipiscingelit. Namegetarcunecdolorbibendumblanditsitametnonipsum.', 'Format text ok'); is( MooseX::App::Utils::format_text('LoremipsumdolorsitametconsecteturadipiscingelitNamegetarcunecdolorbibendumblanditsitametnonipsum.'), ' LoremipsumdolorsitametconsecteturadipiscingelitNamegetarcunecdolorbibendum blanditsitametnonipsum.', 'Format text ok'); }; subtest 'Formater' => sub { my $list = MooseX::App::Utils::format_list( ['part1','Lorem ipsum dolor sit amet, consectetur adipiscing elit. vitae lectus purus, quis dapibus orci.'], ['part2_something','Lorem ipsum dolor sit amet, consectetur adipiscing elit.'], ['part3',''], ); is( $list, ' part1 Lorem ipsum dolor sit amet, consectetur adipiscing elit. vitae lectus purus, quis dapibus orci. part2_something Lorem ipsum dolor sit amet, consectetur adipiscing elit. part3 ', 'Format list ok' ); }; subtest 'Parser' => sub { my $parser = MooseX::App::ParsedArgv->new({ argv => ['hello','--bool','mellow','-hui','--help','--help','--test','1','baer','--test','2','--key=value1','--key=value2','-u','--','hase','--luchs'], hints => ['bool'], }); is(scalar(@{$parser->elements}),12,'Has 12 elements'); is($parser->elements->[0]->key,'hello','Parameter parsed ok'); is($parser->elements->[0]->type,'parameter','Parameter type ok'); is($parser->elements->[1]->key,'bool','Flag parsed ok'); is($parser->elements->[1]->type,'option','Flag type ok'); is($parser->elements->[2]->key,'mellow','Parameter parsed ok'); is($parser->elements->[3]->key,'h','Flag parsed ok'); is($parser->elements->[4]->key,'u','Flag parsed ok'); is($parser->elements->[5]->key,'i','Flag parsed ok'); is($parser->elements->[6]->key,'help','Flag parsed ok'); is($parser->elements->[7]->key,'test','Option parsed ok'); cmp_deeply($parser->elements->[7]->value,[1,2],'Option value ok'); is($parser->elements->[8]->key,'baer','Parameter parsed ok'); is($parser->elements->[9]->key,'key','Option parsed ok'); is($parser->elements->[9]->key,'key','Extra parsed ok'); cmp_deeply($parser->elements->[9]->value,['value1','value2'],'Option value ok'); is($parser->elements->[10]->key,'hase','Extra parsed ok'); is($parser->elements->[11]->key,'--luchs','Extra parsed ok'); }; MooseX-App-1.33/t/04_plugin_config.t000644 000765 000024 00000003007 12454262644 017443 0ustar00marosstaff000000 000000 # -*- perl -*- # t/04_role_config.t - Test config role use Test::Most tests => 4+1; use Test::NoWarnings; use lib 't/testlib'; use Test01; subtest 'Command with config' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --config t/config.pl)]); my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandA'); is($test01->global,'234','Arg from command config'); is($test01->command_local1,'22','Arg from command config'); isa_ok($test01->config,'Path::Class::File'); is($test01->_config_data->{global}{global},'123','Config loaded'); }; subtest 'Another command with config' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_b --config t/config.pl --param_b bbb)]); my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandB'); is($test01->global,'123','Arg from command config'); }; subtest 'Command with config and argv' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --config t/config.pl --global 1234)]); my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandA'); is($test01->global,'1234','Arg from command config'); is($test01->command_local1,'22','Arg from command config'); }; subtest 'Missing config' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --config t/nosuchfile.pl --global 1234)]); my $test01 = Test01->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); like($test01->blocks->[0]->header,qr/Could not find/,'Error message set'); }; MooseX-App-1.33/t/05_extended.t000755 000765 000024 00000024572 12477001710 016424 0ustar00marosstaff000000 000000 # -*- perl -*- # t/05_extended.t - Extended tests use Test::Most tests => 24+1; use Test::NoWarnings; use FindBin qw(); use lib 't/testlib'; use Test03; Test03->meta->app_fuzzy(0); Test03->meta->app_strict(1); subtest 'Non-Fuzzy command matching' => sub { MooseX::App::ParsedArgv->new(argv => [qw(some --private 1)]); my $test01 = Test03->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); is($test01->blocks->[0]->header,"Unknown command 'some'","Message ok"); }; subtest 'Non-Fuzzy attribute matching' => sub { MooseX::App::ParsedArgv->new(argv => [qw(somecommand --private 1)]); my $test01 = Test03->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); is($test01->blocks->[0]->header,"Unknown option 'private'","Message ok"); }; Test03->meta->app_fuzzy(1); subtest 'Private option is not exposed' => sub { MooseX::App::ParsedArgv->new(argv => [qw(some --private 1)]); my $test01 = Test03->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); is($test01->blocks->[0]->header,"Unknown option 'private'","Message ok"); is($test01->blocks->[0]->type,"error",'Message is of type error'); }; subtest 'Options from role' => sub { MooseX::App::ParsedArgv->new(argv => [qw(some --another 10 --role 15)]); my $test02 = Test03->new_with_command; isa_ok($test02,'Test03::SomeCommand'); is($test02->another_option,'10','Param is set'); is($test02->roleattr,'15','Role param is set'); }; subtest 'Missing attribute value' => sub { MooseX::App::ParsedArgv->new(argv => [qw(some --another)]); my $test03 = Test03->new_with_command; isa_ok($test03,'MooseX::App::Message::Envelope'); is($test03->blocks->[0]->header,"Missing value for 'another'","Message ok"); is($test03->blocks->[0]->type,"error",'Message is of type error'); }; subtest 'All options available & no description' => sub { MooseX::App::ParsedArgv->new(argv => [qw(some --help)]); my $test04 = Test03->new_with_command; isa_ok($test04,'MooseX::App::Message::Envelope'); is($test04->blocks->[2]->header,'options:','No description'); is($test04->blocks->[2]->body," --another [Required; Not important] --global_option Enable this to do fancy stuff [Flag] --help -h --usage -? Prints this usage information. [Flag] --list [Multiple] --roleattr [Role] --some_option Very important option!","Message ok"); }; # Not working on cpan testers #subtest 'Test wrapper script encoding' => sub { # my $output = `LANG=en_US.UTF-8 $^X $FindBin::Bin/example/test03.pl some_command --another töst\\ möre --some_option "anöther täst"`; # is($output,'RUN:anöther täst:töst möre','Encoded output'); #} subtest 'Test type constraints integer' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --int 1a)]); my $test05 = Test03->new_with_command; isa_ok($test05,'MooseX::App::Message::Envelope'); is($test05->blocks->[0]->header,"Invalid value for 'integer'","Message ok"); }; subtest 'Test type constraints hash' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --hash xx)]); my $test06 = Test03->new_with_command; isa_ok($test06,'MooseX::App::Message::Envelope'); is($test06->blocks->[0]->header,"Invalid value for 'hash'","Message ok"); }; subtest 'Test type constraints number' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --number 2a)]); my $test07 = Test03->new_with_command; isa_ok($test07,'MooseX::App::Message::Envelope'); is($test07->blocks->[0]->header,"Invalid value for 'number'","Message ok"); }; subtest 'Test type constraints custom1' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --custom1 9)]); my $test08 = Test03->new_with_command; isa_ok($test08,'MooseX::App::Message::Envelope'); is($test08->blocks->[0]->header,"Invalid value for 'custom1'","Message ok"); }; subtest 'Test pass type constraints' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --hash key1=value1 --split a;b --split c --hash key2=value2 --integer 10 --number 10.10 --custom1 11 --custom2 test --extra1 wurtsch --count --count --cou)]); my $test09 = Test03->new_with_command; isa_ok($test09,'Test03::AnotherCommand'); is($test09->hash->{key1},"value1","Hash ok"); is($test09->hash->{key2},"value2","Hash ok"); is($test09->integer,10,"Integer ok"); is($test09->custom1,11,"Custom type 1 ok"); is(ref($test09->custom2),'SCALAR',"Custom type 2 ok"); is(${$test09->custom2},'test',"Custom type 2 ok"); is($test09->extra1,'wurtsch',"Attr set ok"); is($test09->count,3,"Count set ok"); cmp_deeply($test09->split,[qw(a b c)],'Split ok'); }; subtest 'Test ambiguous options' => sub { MooseX::App::ParsedArgv->new(argv => [qw(another --custom 1 --custom 2)]); my $test10 = Test03->new_with_command; isa_ok($test10,'MooseX::App::Message::Envelope'); is($test10->blocks->[0]->header,"Ambiguous option 'custom'","Message ok"); like($test10->blocks->[0]->body,qr/Could be custom1 custom2/,"Message ok"); }; subtest 'Test flags & defaults' => sub { MooseX::App::ParsedArgv->new(argv => [qw(yet --bool3)]); my $test11 = Test03->new_with_command; isa_ok($test11,'Test03::YetAnotherCommand'); is($test11->bool1,undef,'Bool1 flag is undef'); is($test11->bool2,1,'Bool2 flag is set'); is($test11->bool3,1,'Bool3 flag is set'); is($test11->value,'hase','Value is default'); }; subtest 'Test more flags & defaults' => sub { MooseX::App::ParsedArgv->new(argv => [qw(yet --bool3 -ab --value baer)]); my $test11 = Test03->new_with_command; isa_ok($test11,'Test03::YetAnotherCommand'); is($test11->bool1,1,'Bool1 flag is undef'); is($test11->bool2,1,'Bool2 flag is unset'); is($test11->bool3,1,'Bool3 flag is set'); is($test11->value,'baer','Value is set'); }; subtest 'Test positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra hui --value baer)]); my $test12 = Test03->new_with_command; isa_ok($test12,'Test03::ExtraCommand'); is($test12->extra1,'hui','Extra1 value is "hui"'); is($test12->extra2, undef,'Extra2 value is undef'); is($test12->alpha, undef,'alpha value is undef'); is($test12->value,'baer','Value is set'); }; subtest 'Test positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra --value baer hui)]); my $test12 = Test03->new_with_command; isa_ok($test12,'Test03::ExtraCommand'); is($test12->extra1,'hui','Extra1 value is "hui"'); is($test12->extra2, undef,'Extra2 value is undef'); is($test12->alpha, undef,'alpha value is undef'); is($test12->value,'baer','Value is set'); }; subtest 'Test optional positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra hui 11 --value baer)]); my $test12 = Test03->new_with_command; isa_ok($test12,'Test03::ExtraCommand'); is($test12->extra1,'hui','Extra1 value is "hui"'); is($test12->extra2,11,'Extra2 value is "11"'); is($test12->alpha, undef,'alpha value is undef'); is($test12->value,'baer','Value is set'); }; subtest 'Test wrong positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra hui aa --value baer)]); my $test13 = Test03->new_with_command; isa_ok($test13,'MooseX::App::Message::Envelope'); is($test13->blocks->[0]->header,"Invalid value for 'extra2'","Error message ok"); is($test13->blocks->[2]->header,"parameters:","Usage header ok"); is($test13->blocks->[2]->body," extra1 Important extra parameter [Required] extra2 [Integer] alpha [Integer]","Usage body ok"); }; subtest 'Test missing positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra --value baer)]); my $test14 = Test03->new_with_command; isa_ok($test14,'MooseX::App::Message::Envelope'); is($test14->blocks->[0]->header,"Required parameter 'extra1' missing","Message ok"); }; Test03->meta->app_fuzzy(1); Test03->meta->app_strict(0); subtest 'Test extra positional params' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra p1 22 33 marder dachs --value 44 --flag luchs --flagg fuchs -- baer --hase)]); my $test15 = Test03->new_with_command; isa_ok($test15,'Test03::ExtraCommand'); is($test15->extra1,'p1','Param 1 ok'); is($test15->extra2,'22','Param 2 ok'); is($test15->alpha,'33','Param 3 ok'); cmp_deeply($test15->extra_argv,[qw(marder dachs luchs fuchs baer --hase)],'Uncomsumed option ok'); }; subtest 'Test parameter preference' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra extra1 22 --value 13 --flag)]); my $test16 = Test03->new_with_command(extra1 => 'extra1man', value => 14, flag => 0, flaggo => 1); isa_ok($test16,'Test03::ExtraCommand'); is($test16->extra1,"extra1man","Extra param from new_with_command ok"); is($test16->extra2,22,"Extra param from argv ok"); is($test16->value,14,"value option from argv ok"); is($test16->flag,0,"Flag from new_with_command ok"); is($test16->flaggo,1,"Flago from new_with_command ok"); }; Test03->meta->app_prefer_commandline(1); subtest 'Test parameter preference reverse' => sub { MooseX::App::ParsedArgv->new(argv => [qw(extra extra1 22 --value 13 --flag)]); my $test17 = Test03->new_with_command(extra1 => 'extra1man', value => 14, flag => 0, flaggo => 1); isa_ok($test17,'Test03::ExtraCommand'); is($test17->extra1,"extra1","Extra param from new_with_command ok"); is($test17->extra2,22,"Extra param from argv ok"); is($test17->value,13,"value option from argv ok"); is($test17->flag,1,"Flag from new_with_command ok"); is($test17->flaggo,1,"Flago from new_with_command ok"); }; subtest 'Test enum error message' => sub { MooseX::App::ParsedArgv->new(argv => [qw(somecommand --another hase hh h ggg)]); my $test18 = Test03->new_with_command(); isa_ok($test18,'MooseX::App::Message::Envelope'); is($test18->blocks->[0]->body,"Value must be one of these values: aaa, bbb, ccc, ddd, eee, fff (not 'ggg')","Check enum error message"); }; subtest 'Test empty multi' => sub { MooseX::App::ParsedArgv->new(argv => [qw(somecommand --another hase --list val1 --list val2 --list)]); my $test19 = Test03->new_with_command(); isa_ok($test19,'Test03::SomeCommand'); is(scalar(@{$test19->list}),3,'Has three list items'); is($test19->list->[0],'val1','First value ok'); is($test19->list->[2],undef,'First value empty'); }; MooseX-App-1.33/t/06_env.t000644 000765 000024 00000003170 12465615274 015416 0ustar00marosstaff000000 000000 # -*- perl -*- # t/06_plugin_env.t - Test env use Test::Most tests => 5+1; use Test::NoWarnings; use lib 't/testlib'; use Test01; subtest 'Command with argv' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --command_local1 11 --global 1)]); my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandA'); is($test01->command_local1,'11','Arg from command config'); }; subtest 'Command only with env' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --global 1)]); local $ENV{LOCAL1} = 12; my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandA'); is($test01->command_local1,'12','Arg from command env'); }; subtest 'Command with env and argv' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --command_local1 13 --global 1)]); local $ENV{LOCAL1} = 12; my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandA'); is($test01->command_local1,'13','Arg from command argv'); }; subtest 'Env not passing type constraint' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_a --global 1)]); local $ENV{LOCAL1} = 'aa'; my $test01 = Test01->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); is($test01->blocks->[0]->header,"Invalid environment value for 'LOCAL1'","Message ok"); }; subtest 'Coerce env value' => sub { MooseX::App::ParsedArgv->new(argv => [qw(command_d --global 1)]); local $ENV{LOCAL1} = 42; my $test01 = Test01->new_with_command; isa_ok($test01,'Test01::CommandD'); is_deeply($test01->command_local1,[42],'Arg coerced from command env'); };MooseX-App-1.33/t/07_single.t000644 000765 000024 00000002010 12454262644 016075 0ustar00marosstaff000000 000000 # -*- perl -*- # t/07_single.t- Test MooseX::App::Single use Test::Most tests => 3+1; use Test::NoWarnings; use lib 't/testlib'; use Test05; subtest 'Single command' => sub { MooseX::App::ParsedArgv->new(argv => [qw()]); my $test05 = Test05->new_with_options; isa_ok($test05,'MooseX::App::Message::Envelope'); is($test05->blocks->[0]->header,"Required option 'another_option' missing","Check for error message"); }; subtest 'Single command' => sub { MooseX::App::ParsedArgv->new(argv => [qw(--another_option 123)]); my $test05 = Test05->new_with_options({ some_option => 1 }); isa_ok($test05,'Test05'); is($test05->another_option,'123','Arg from command ARGV'); is($test05->some_option,1,'Arg from new_with_options'); }; subtest 'Single command help' => sub { MooseX::App::ParsedArgv->new(argv => [qw(--help)]); my $test05 = Test05->new_with_options(); isa_ok($test05,'MooseX::App::Message::Envelope'); is($test05->blocks->[0]->header,"usage:","Usage header is first"); }; MooseX-App-1.33/t/08_plugin_various.t000644 000765 000024 00000002073 12454262644 017674 0ustar00marosstaff000000 000000 # -*- perl -*- # t/08_plugin_various.t - Test various plugin use Test::Most tests => 2+1; use Test::NoWarnings; use lib 't/testlib'; use Test03; subtest 'Bash completion' => sub { MooseX::App::ParsedArgv->new(argv => [qw(bash_completion)]); my $test01 = Test03->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); my $bash_completion = $test01->stringify; like($bash_completion,qr/_test03_macc_somecommand\(\)\s\{/,'some_command present'); like($bash_completion,qr/--global_option/,'global_option present'); like($bash_completion,qr/--roleattr/,'roleattr present'); }; subtest 'Version' => sub { MooseX::App::ParsedArgv->new(argv => [qw(version)]); my $test02 = Test03->new_with_command; isa_ok($test02,'MooseX::App::Message::Envelope'); my $version = $test02->stringify; like($version,qr/\s*test03\s+version\s+22\.02/s,'Check for app version'); like($version,qr/\s*MooseX::App\sversion\s\d+\.\d+/s,'Check for MooseX::App version'); like($version,qr/This library is free software/s,'License included'); };MooseX-App-1.33/t/09_classes.t000644 000765 000024 00000005043 12454262644 016264 0ustar00marosstaff000000 000000 # -*- perl -*- # t/09_classes.t - Test classes use Test::Most tests => 6+1; use Test::NoWarnings; use lib 't/testlib'; use Test04; use Test03; subtest 'Extend base class' => sub { MooseX::App::ParsedArgv->new(argv => [qw()]); my $test01 = Test04->new_with_command; isa_ok($test01,'MooseX::App::Message::Envelope'); like($test01->blocks->[2]->body,qr/--test1\s+\[Integer\]/,'--test1 included'); like($test01->blocks->[2]->body,qr/--test2\s+\[Flag\]/,'--test2 included'); unlike($test01->blocks->[2]->body,qr/--test3/,'--test3 not included'); }; subtest 'Wrong usage' => sub { throws_ok { Test03->new->new_with_command } qr/new_with_command is a class method/, 'Only callable as class method'; use Test03::SomeCommand; throws_ok { Test03::SomeCommand->new_with_command } qr/new_with_command may only be called from the application base package/, 'new_with_command may only be called from the application base package'; throws_ok { Test03->new_with_command(1,2,3) } qr/new_with_command got invalid extra arguments/, 'Wrong default args'; }; subtest 'Conflicts' => sub { MooseX::App::ParsedArgv->new(argv => [qw(broken --conflict a)]); throws_ok { Test03->new_with_command; } qr/Command line option conflict/, 'Conflict detected'; }; subtest 'Default args available with extra inheritance' => sub { MooseX::App::ParsedArgv->new(argv => [qw(yetanothercommand --help)]); my $another = Test03->new_with_command; isa_ok($another,'MooseX::App::Message::Envelope'); like($another->blocks->[0]->body,qr/test03\syetanothercommand/,'Help ok'); is($another->blocks->[0]->header,'usage:','Help ok'); MooseX::App::ParsedArgv->new(argv => [qw(yetanothercommand -ab --bool3)]); my $yetanother = Test03->new_with_command(private => 'test'); isa_ok($yetanother,'Test03::YetAnotherCommand'); is($yetanother->private,'test','Option has been passed on'); }; subtest 'Attributes from role' => sub { MooseX::App::ParsedArgv->new(argv => [qw(somecommand --roleattr a --another b)]); my $test03 = Test03->new_with_command(); isa_ok($test03,'Test03::SomeCommand'); is($test03->roleattr,'a','Attribute from role ok'); }; subtest 'Correct order from role ' => sub { MooseX::App::ParsedArgv->new(argv => [qw(somecommand a1 b2 ccc --another b)]); my $test03 = Test03->new_with_command; isa_ok($test03,'Test03::SomeCommand'); is($test03->param_c,'a1','First from role'); is($test03->param_a,'b2','Second from role'); is($test03->param_b,'ccc','Third from role'); }; MooseX-App-1.33/t/10_plugin_mutexgroup.t000644 000765 000024 00000002547 12500772622 020414 0ustar00marosstaff000000 000000 # -*- perl -*- # t/10_plugin_mutexgroup.t - Test MutexGroup use Test::Most tests => 1+1; use Test::NoWarnings; use lib 't/testlib'; use Test07; subtest 'MutexGroup' => sub { plan tests => 7; { my $test01 = Test07->new_with_options( UseAmmonia => 1, UseChlorine => 1 ); isa_ok( $test01, 'MooseX::App::Message::Envelope' ); my @errors = grep { $_->type eq 'error' } @{ $test01->blocks }; is( scalar @errors, 1, 'only returned a single error' ); is( $errors[0]->header, 'Options UseAmmonia and UseChlorine are mutally exclusive', 'generated an error when more than one option in the same mutexgroup is initialized' ); } { my $test02 = Test07->new_with_options(); isa_ok( $test02, 'MooseX::App::Message::Envelope' ); my @errors = grep { $_->type eq 'error' } @{ $test02->blocks }; is( scalar @errors, 1, 'only returned a single error' ); is( $errors[0]->header, 'Either UseAmmonia or UseChlorine must be specified', 'generated an error when no options in the same mutexgroup are initialized' ); } { my $test03 = Test07->new_with_options( UseAmmonia => 1 ); ok( $test03->isa('Test07'), 'generated no errors when only a single option from the same mutexgroup is initialized' ); } }; MooseX-App-1.33/t/11_process.t000644 000765 000024 00000005272 12507043273 016274 0ustar00marosstaff000000 000000 # -*- perl -*- # t/11_process.t - Test via subprocesses use Test::Most tests => 1+1; use Test::NoWarnings; use FindBin qw(); use IPC::Open3 qw(open3); use Symbol qw(gensym); my $BASE = "$^X $FindBin::Bin/example"; subtest 'Test basic exit codes' => sub { SKIP: { skip "Cannot test on MSWin",7 if $^O =~ /^MSWin/; test_subprocess( bin => 'test02.pl', exit => 127, out => '', err => qr/Missing command/, ); test_subprocess( bin => 'test02.pl error', exit => 25, err => qr/XXX/, ); test_subprocess( bin => 'test02.pl version', exit => 0, out => qr/VERSION/, err => '', ); test_subprocess( bin => 'test02.pl version', exit => 0, out => qr/VERSION/, err => '', ); test_subprocess( bin => 'test02.pl record --help', exit => 0, out => qr/usage:/, err => '', ); test_subprocess( bin => 'test02.pl record', exit => 0, out => qr/RAN/, err => '', ); test_subprocess( bin => 'test02.pl record --notthere', exit => 1, out => '', err => qr/Unknown option 'notthere'/, ); } }; sub test_subprocess { my (%params) = @_; $params{args} ||= []; my($in_fh, $out_fh, $err_fh, $out, $err, $pid, $exit); $err_fh = gensym; eval { $pid = open3( $in_fh, $out_fh, $err_fh, $BASE.'/'.$params{bin}, ); }; if ($@) { fail('Error running '.$params{bin}.' :'.$@); return; } if (defined $pid) { waitpid($pid,0); $exit = $? >> 8; $out = ''; while(<$out_fh>) { $out .= $_; } $err = ''; while(<$err_fh>) { $err .= $_; } } if (exists $params{exit}) { is($exit,$params{exit},'Exitcode ok'); } if (exists $params{out}) { if (ref $params{out} eq 'Regexp') { like($out,$params{out},'Output ok'); } else { is($out,$params{out},'Output ok'); } } if (exists $params{err}) { if (ref $params{err} eq 'Regexp') { like($err,$params{err},'Error ok'); } else { is($err,$params{err},'Error ok'); } } return; }MooseX-App-1.33/t/12_plugin_depends.t000644 000765 000024 00000003063 12501006162 017601 0ustar00marosstaff000000 000000 # -*- perl -*- # t/10_plugin_depends.t - Test Depends use Test::Most tests => 1+1; use Test::NoWarnings; use lib 't/testlib'; use Test08; subtest 'Depends' => sub { plan tests => 8; { my $test01 = Test08->new_with_options( WriteToFile => 1 ); isa_ok( $test01, 'MooseX::App::Message::Envelope' ); my @errors = grep { $_->type eq 'error' } @{ $test01->blocks }; is( scalar @errors, 1, 'only returned a single error' ); is( $errors[0]->header, 'Option \'WriteToFile\' requires \'FileFormat\' to be defined', 'generated an error when an option dependency was not present' ); } { my $test02 = Test08->new_with_options( ReadFromFile => 1 ); isa_ok( $test02, 'MooseX::App::Message::Envelope' ); my @errors = grep { $_->type eq 'error' } @{ $test02->blocks }; is( scalar @errors, 1, 'only returned a single error' ); is( $errors[0]->header, 'Option \'ReadFromFile\' requires \'FileFormat\' to be defined', 'generated an error when an option dependency was not present' ); } { my $test03 = Test08->new_with_options( WriteToFile => 1, FileFormat => 'tsv' ); ok( ! $test03->can('blocks'), 'generated no errors when both an option and its dependencies are defined' ); } { my $test04 = Test08->new_with_options( ReadFromFile => 1, FileFormat => 'tsv' ); ok( ! $test04->can('blocks'), 'generated no errors when both an option and its dependencies are defined' ); } }; MooseX-App-1.33/t/config.pl000644 000765 000024 00000000232 11762214012 015712 0ustar00marosstaff000000 000000 { global => { global => 123, }, command_a => { global => 234, command_local1 => 22, }, }MooseX-App-1.33/t/example/000755 000765 000024 00000000000 12514113027 015546 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/000755 000765 000024 00000000000 12514113027 015561 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/MyMessage.pm000644 000765 000024 00000002327 12375415636 020035 0ustar00marosstaff000000 000000 package MyMessage { use MooseX::App::Simple qw(Color Config Term); use Moose::Util::TypeConstraints qw(); app_strict(1); parameter 'recipient' => ( is => 'rw', required => 1, documentation => q[Recipient e-mail address], cmd_env => 'MYMESSAGE_RECIPIENT', ); option 'message' => ( is => 'rw', required => 1, documentation => q[Message text], cmd_term => 1, ); option 'level' => ( is => 'rw', isa => Moose::Util::TypeConstraints::enum([qw(low medium high)]), default => 'medium', documentation => q[Message severity], ); option 'verbose' => ( is => 'rw', isa => 'Bool', documentation => q[Be verbose], cmd_aliases => ['v'], ); option 'extra' => ( is => 'rw', isa => 'HashRef', documentation => q[Extra options], ); sub run { my ($self) = @_; use Data::Dumper; print 'Called run with '.Dumper($self); } =head1 DESCRIPTION This is how we roll =cut } 1; MooseX-App-1.33/t/testlib/Test01/000755 000765 000024 00000000000 12514113027 016641 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test01.pm000644 000765 000024 00000000560 12454262644 017215 0ustar00marosstaff000000 000000 package Test01; use Moose; use MooseX::App qw(Config); app_strict 1; app_description "Huissasa"; option 'global' => ( isa => 'Int', is => 'rw', required => 1, documentation => q[test], cmd_tags => ['Important!'], ); has 'private' => ( isa => 'Int', is => 'rw', ); 1;MooseX-App-1.33/t/testlib/Test02/000755 000765 000024 00000000000 12514113027 016642 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test02.pm000644 000765 000024 00000000711 12514112212 017172 0ustar00marosstaff000000 000000 package Test02; use Moose; use MooseX::App (qw(BashCompletion Version Man), ($ENV{HARNESS_ACTIVE} ? ():qw(ConfigHome Color Typo Term) )); our $VERSION = 1.01; app_namespace "Test02::Command","Test02::MoreCommands"; #app_fuzzy; sub run { print "RAN"; } 1; =encoding utf8 =head1 NAME Test02 - Test 02 =head1 SYNOPSIS do something =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. =cutMooseX-App-1.33/t/testlib/Test03/000755 000765 000024 00000000000 12514113027 016643 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test03.pm000644 000765 000024 00000001101 12130504066 017173 0ustar00marosstaff000000 000000 package Test03; use MooseX::App qw(BashCompletion Version); our $VERSION = '22.02'; app_base 'test03'; app_command_name { my ($package) = @_; return lc($package); }; option 'global_option' => ( is => 'rw', isa => 'Bool', #default => 0, #required => 1, documentation => q[Enable this to do fancy stuff], ); has 'hidden_option' => ( is => 'rw', ); sub run { print "RAN"; } 1; =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. =cutMooseX-App-1.33/t/testlib/Test03CommandBase.pm000644 000765 000024 00000000541 12454262644 021310 0ustar00marosstaff000000 000000 # ============================================================================ package Test03CommandBase; # ============================================================================ use utf8; use namespace::autoclean; use Moose; has 'private' => ( is => 'rw', isa => 'Str', ); __PACKAGE__->meta->make_immutable; 1;MooseX-App-1.33/t/testlib/Test04.pm000644 000765 000024 00000000264 12123556074 017215 0ustar00marosstaff000000 000000 package Test04; #use Moose; use MooseX::App; extends qw(Test04Base); option 'test1' => ( is => 'rw', isa => 'Int', ); option '+test2' => (); 1;MooseX-App-1.33/t/testlib/Test04Base.pm000644 000765 000024 00000000465 12113460743 020007 0ustar00marosstaff000000 000000 package Test04Base; use Moose; has 'test1' => ( is => 'rw', isa => 'Str', ); has 'test2' => ( is => 'rw', isa => 'Bool', ); has 'test3' => ( is => 'rw', isa => 'Str', ); sub run { print "RAN"; } 1;MooseX-App-1.33/t/testlib/Test05.pm000644 000765 000024 00000001043 12454262644 017216 0ustar00marosstaff000000 000000 package Test05; #use Moose; use MooseX::App::Simple qw(Config); app_fuzzy 1; option 'some_option' => ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); option 'another_option' => ( is => 'rw', isa => 'Str', documentation => q[Enable this to do fancy stuff], required => 1, cmd_env => 'ANOTHER', ); sub run { my ($self) = @_; warn $self->dump; } 1; =head1 DESCRIPTION this is how we use this command =cut MooseX-App-1.33/t/testlib/Test06/000755 000765 000024 00000000000 12514113027 016646 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test06.pm000644 000765 000024 00000000654 12472007251 017215 0ustar00marosstaff000000 000000 package Test06; use MooseX::App qw(Config); app_fuzzy(1); #app_namespace(); app_command_name { my @parts = split( /[_\s]+|\b|(? 'Test03::ExtraCommand'; option 'some_option' => ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); 1;MooseX-App-1.33/t/testlib/Test07.pm000644 000765 000024 00000000653 12500364632 017216 0ustar00marosstaff000000 000000 package Test07; use MooseX::App::Simple qw(MutexGroup); option 'UseAmmonia' => ( is => 'ro', isa => 'Bool', mutexgroup => 'NonMixableCleaningChemicals', ); option 'UseChlorine' => ( is => 'ro', isa => 'Bool', mutexgroup => 'NonMixableCleaningChemicals' ); has 'private_option' => ( is => 'ro', isa => 'Int', default => 0, ); sub run { print "ok"; } 1; MooseX-App-1.33/t/testlib/Test08.pm000644 000765 000024 00000001047 12500772612 017216 0ustar00marosstaff000000 000000 package Test08; use MooseX::App::Simple qw(MutexGroup Depends); use Moose::Util::TypeConstraints; option 'FileFormat' => ( is => 'ro', isa => enum([qw(csv tsv xml)]), ); option 'WriteToFile' => ( is => 'ro', isa => 'Bool', mutexgroup => 'FileOp', depends => [qw(FileFormat)], ); option 'ReadFromFile' => ( is => 'ro', isa => 'Bool', mutexgroup => 'FileOp', depends => [qw(FileFormat)], ); has 'private_option' => ( is => 'ro', isa => 'Int', default => 0, ); 1; MooseX-App-1.33/t/testlib/Test06/CommandA.pm000644 000765 000024 00000001261 12113460743 020670 0ustar00marosstaff000000 000000 package Test06::CommandA; use Moose; use MooseX::App::Command; extends qw(Test06); use Moose::Util::TypeConstraints; subtype 'Test06::local2' => as 'Str' => where { $_ =~ /^[aA]/ }; #=> message { "Must start with an 'A'" }; no Moose::Util::TypeConstraints; option 'command_local2' => ( isa => 'Test06::local2', is => 'rw', documentation => q[Verylongwordwithoutwhitespacestotestiftextformatingworksproperly], cmd_env => 'LOCAL2', ); sub run { my ($self) = @_; print "NEW WITH A"; $self->initialize_command_class('Test06::CommandB')->run; #$self->initialize_command_class('Test06::CommandB'); } 1;MooseX-App-1.33/t/testlib/Test06/CommandB.pm000644 000765 000024 00000000325 12042256202 020663 0ustar00marosstaff000000 000000 package Test06::CommandB; use Moose; #use MooseX::App::Command; extends qw(Test06); has 'email' => ( isa => 'Str', is => 'rw', ); sub run { my ($self) = @_; warn $self; } 1;MooseX-App-1.33/t/testlib/Test03/AnotherCommand.pm000644 000765 000024 00000002177 12465625113 022120 0ustar00marosstaff000000 000000 package Test03::AnotherCommand; use MooseX::App::Command; extends qw(Test03CommandBase); use Moose::Util::TypeConstraints; subtype 'Test03::Type::Custom1', as 'Int', where { $_ > 10 }, message { "Must be greater than 10" }; subtype 'Test03::Type::Custom2', as 'ScalarRef'; coerce 'Test03::Type::Custom2', from 'Str', via { \$_ }; no Moose::Util::TypeConstraints; option 'hash' => ( is => 'rw', isa => 'HashRef', ); option 'integer' => ( is => 'rw', isa => 'Int', ); option 'number' => ( is => 'rw', isa => 'Num', ); option 'custom1' => ( is => 'rw', isa => 'Test03::Type::Custom1', ); option 'custom2' => ( is => 'rw', isa => 'Test03::Type::Custom2', coerce => 1, ); option 'split' => ( is => 'rw', isa => 'ArrayRef[Str]', cmd_split => qr/;/i, ); option 'count' => ( is => 'rw', cmd_count => 1, ); option ['extra1','extra2'] => ( is => 'rw', ); sub run { my ($self) = @_; } 1;MooseX-App-1.33/t/testlib/Test03/BrokenCommand.pm000644 000765 000024 00000000541 12215374470 021731 0ustar00marosstaff000000 000000 package Test03::BrokenCommand; use MooseX::App::Command; option 'conflict1' => ( is => 'rw', isa => 'Bool', cmd_flag => 'conflict', ); option 'conflict2' => ( is => 'rw', isa => 'Bool', cmd_flag => 'conflict', default => 1, ); sub run { my ($self) = @_; } 1;MooseX-App-1.33/t/testlib/Test03/ExtraCommand.pm000644 000765 000024 00000001531 12454262633 021576 0ustar00marosstaff000000 000000 package Test03::ExtraCommand; use MooseX::App::Command; parameter 'extra1' => ( is => 'rw', isa => 'Str', required => 1, documentation => q[Important extra parameter], ); parameter 'extra2' => ( is => 'rw', isa => 'Int', ); parameter 'alpha' => ( is => 'rw', isa => 'Int', ); option 'value' => ( is => 'rw', isa => 'Str', required => 1, default => sub { return "hase" }, ); option 'flag' => ( is => 'rw', isa => 'Bool', ); option 'flaggo' => ( is => 'rw', isa => 'Bool', ); sub run { my ($self) = @_; use Data::Dumper; { local $Data::Dumper::Maxdepth = 2; warn __FILE__.':line'.__LINE__.':'.Dumper($self); } } 1; MooseX-App-1.33/t/testlib/Test03/Role/000755 000765 000024 00000000000 12514113027 017544 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test03/SomeCommand.pm000644 000765 000024 00000001666 12462530442 021422 0ustar00marosstaff000000 000000 package Test03::SomeCommand; use MooseX::App::Command; extends qw(Test03); with qw(Test03::Role::TestRole); use Moose::Util::TypeConstraints; parameter 'param_a' => ( is => 'rw', isa => 'Str', ); parameter 'param_b' => ( is => 'rw', isa => enum([qw(aaa bbb ccc ddd eee fff)]), ); option 'some_option' => ( is => 'rw', isa => 'Str', documentation => q[Very important option!], ); option 'another_option' => ( is => 'rw', isa => 'Str', required => 1, cmd_flag => 'another', cmd_tags => ['Not important'], ); option 'list' => ( is => 'rw', isa => 'ArrayRef[Maybe[Str]]', ); has 'private' => ( is => 'rw', isa => 'Str', ); sub run { my ($self) = @_; print "RUN:".($self->some_option||'').":".($self->another_option||''); } 1;MooseX-App-1.33/t/testlib/Test03/YetAnotherCommand.pm000644 000765 000024 00000001420 12454262644 022574 0ustar00marosstaff000000 000000 package Test03::YetAnotherCommand; use MooseX::App::Command; extends qw(Test03CommandBase); with qw(MooseX::App::Role::Common); option 'bool1' => ( is => 'rw', isa => 'Bool', cmd_flag => 'a', ); option 'bool2' => ( is => 'rw', isa => 'Bool', cmd_flag => 'b', default => 1, ); option 'bool3' => ( is => 'rw', isa => 'Bool', required => 1, ); option 'value' => ( is => 'rw', isa => 'Str', required => 1, default => sub { return "hase" }, ); sub run { my ($self) = @_; use Data::Dumper; { local $Data::Dumper::Maxdepth = 2; warn __FILE__.':line'.__LINE__.':'.Dumper($self); } } 1;MooseX-App-1.33/t/testlib/Test03/Role/TestRole.pm000644 000765 000024 00000000710 12454262633 021654 0ustar00marosstaff000000 000000 # ============================================================================ package Test03::Role::TestRole; # ============================================================================ use utf8; use namespace::autoclean; use MooseX::App::Role; option 'roleattr' => ( is => 'rw', isa => 'Str', cmd_tags => ['Role'], ); parameter 'param_c' => ( is => 'rw', isa => 'Str', ); 1;MooseX-App-1.33/t/testlib/Test02/Command/000755 000765 000024 00000000000 12514113027 020220 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test02/MoreCommands/000755 000765 000024 00000000000 12514113027 021226 5ustar00marosstaff000000 000000 MooseX-App-1.33/t/testlib/Test02/MoreCommands/Test.pm000644 000765 000024 00000001115 12454262644 022516 0ustar00marosstaff000000 000000 # ============================================================================ package Test02::MoreCommands::Test; # ============================================================================ use strict; use warnings; use utf8; use Moose; use MooseX::App::Command; extends qw(Test02); use Moose::Util::TypeConstraints; parameter 'first' => ( isa => enum([qw(a1 b2 b3)]), is => 'rw', required => 1, cmd_term => 1, ); option 'second' => ( isa => 'Int', is => 'rw', cmd_term => 1, ); 1;MooseX-App-1.33/t/testlib/Test02/Command/Error.pm000644 000765 000024 00000000533 12504577025 021663 0ustar00marosstaff000000 000000 package Test02::Command::Error; use Moose; use MooseX::App::Command; extends qw(Test02); sub BUILD { warn('XXX'); exit 25; } sub run { warn('YYY'); exit 77; } command_usage "Use me not"; command_long_description "A very long description about a command that will always fail"; command_short_description "Short description"; 1;MooseX-App-1.33/t/testlib/Test02/Command/Record.pm000644 000765 000024 00000000137 12056145645 022011 0ustar00marosstaff000000 000000 package Test02::Command::Record; use Moose; use MooseX::App::Command; extends qw(Test02); 1;MooseX-App-1.33/t/testlib/Test02/Command/Required.pm000644 000765 000024 00000000561 12454262644 022355 0ustar00marosstaff000000 000000 package Test02::Command::Required; use Moose; use MooseX::App::Command; extends qw(Test02); option 'local1' => ( isa => 'Int', is => 'rw', required => 1, cmd_term => 1, ); option 'local2' => ( isa => 'Bool', is => 'rw', default => 1, cmd_term => 1, ); 1;MooseX-App-1.33/t/testlib/Test01/CommandA.pm000644 000765 000024 00000001765 12215374555 020704 0ustar00marosstaff000000 000000 package Test01::CommandA; use Moose; use MooseX::App::Command; extends qw(Test01); option 'command_local1' => ( isa => 'Int', is => 'rw', documentation => 'some docs about the long texts that seem to occur randomly', cmd_tags => [qw(Important)], cmd_env => 'LOCAL1', ); option 'command_local2' => ( isa => 'Str', is => 'rw', documentation => q[Verylongwordwithoutwhitespacestotestiftextformatingworksproperly], cmd_env => 'LOCAL2', ); has 'anotherprivate' => ( is => 'rw', isa => 'Str', ); command_long_description "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dui velit, varius nec iaculis vitae, elementum eget mi. * bullet1 * bullet2 * bullet3 Cras eget mi nisi. In hac habitasse platea dictumst."; command_short_description "Command A!"; sub run { my ($self) = @_; print "RUN COMMAND-A:".($self->command_local2 // 'undef'); } 1;MooseX-App-1.33/t/testlib/Test01/CommandB.pm000644 000765 000024 00000001555 12454262644 020702 0ustar00marosstaff000000 000000 package Test01::CommandB; use Moose; use MooseX::App::Command; extends qw(Test01); use Moose::Util::TypeConstraints; has 'param_a' => ( isa => 'Str', is => 'rw', ); option 'param_b' => ( isa => enum([qw(aaa bbb ccc ddd eee fff)]), is => 'rw', required => 1, ); sub run { print "RUN COMMAND-B"; } =encoding utf8 =head1 NAME Test01::CommandB - Test class command B for test 01 =head1 SYNOPSIS use with care =head1 DESCRIPTION Some description of B some code some code some more desc =over =item * item 1 =item * item 2 =over =item * item 2.1 =item * item 2.2 =back =back hase ist so super and this is a very long sentence witch breaks after i have written some bla bla. another interesting paragraph. =head1 METHODS hase =head2 SUB A bär =head1 SUB B some methods =cut 1;MooseX-App-1.33/t/testlib/Test01/CommandC1.pm000644 000765 000024 00000000401 12217341316 020740 0ustar00marosstaff000000 000000 package Test01::CommandC1 ; use Moose; use MooseX::App::Command; extends qw(Test01); option 'param_internal_name' => ( isa => 'Str', is => 'rw', cmd_flag => 'external_name', required => 1, ); # ABSTRACT: Test C1 1;MooseX-App-1.33/t/testlib/Test01/CommandD.pm000644 000765 000024 00000001602 12465615274 020700 0ustar00marosstaff000000 000000 package Test01::CommandD; use Moose; use MooseX::App::Command; extends qw(Test01); use Moose::Util::TypeConstraints; subtype 'ArrayRefOfInts', as 'ArrayRef[Int]'; coerce 'ArrayRefOfInts', from 'Int', via { [ $_ ] }; option 'command_local1' => ( isa => 'ArrayRefOfInts', coerce => 1, is => 'rw', documentation => 'some docs about the long texts that seem to occur randomly', cmd_tags => [qw(Important)], cmd_env => 'LOCAL1', ); command_long_description "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dui velit, varius nec iaculis vitae, elementum eget mi. * bullet1 * bullet2 * bullet3 Cras eget mi nisi. In hac habitasse platea dictumst."; command_short_description "Command A!"; sub run { my ($self) = @_; print "RUN COMMAND-A:".($self->command_local2 // 'undef'); } 1;MooseX-App-1.33/t/example/test01.pl000755 000765 000024 00000000254 12075527062 017241 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test01; Test01->new_with_command( global => 1 )->run;MooseX-App-1.33/t/example/test02.pl000755 000765 000024 00000000235 12074052212 017226 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test02; Test02->new_with_command->run;MooseX-App-1.33/t/example/test03.pl000755 000765 000024 00000000235 12074052212 017227 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test03; Test03->new_with_command->run;MooseX-App-1.33/t/example/test04.pl000755 000765 000024 00000000235 12074052212 017230 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test04; Test04->new_with_command->run;MooseX-App-1.33/t/example/test05.pl000755 000765 000024 00000000235 12074052271 017236 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test05; Test05->new_with_options->run;MooseX-App-1.33/t/example/test06.pl000755 000765 000024 00000000235 12074052241 017234 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test06; Test06->new_with_command->run;MooseX-App-1.33/t/example/test07.pl000755 000765 000024 00000000235 12500364573 017245 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test07; Test07->new_with_options->run;MooseX-App-1.33/t/example/test08.pl000755 000765 000024 00000000235 12501005146 017233 0ustar00marosstaff000000 000000 #!/usr/bin/env perl use strict; use warnings; use 5.010; use FindBin qw(); use lib $FindBin::Bin.'/../testlib'; use Test08; Test08->new_with_options->run;MooseX-App-1.33/lib/MooseX/000755 000765 000024 00000000000 12514113027 015630 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/000755 000765 000024 00000000000 12514113027 016350 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App.pm000644 000765 000024 00000040226 12514112354 016714 0ustar00marosstaff000000 000000 # ============================================================================« package MooseX::App; # ============================================================================« use 5.010; use utf8; use strict; use warnings; our $AUTHORITY = 'cpan:MAROS'; our $VERSION = '1.33'; use MooseX::App::Meta::Role::Attribute::Option; use MooseX::App::Exporter qw(app_usage app_description app_base app_fuzzy app_strict app_prefer_commandline option parameter); use MooseX::App::Message::Envelope; use Moose::Exporter; use Scalar::Util qw(blessed); my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods( with_meta => [ qw(app_usage app_description app_namespace app_base app_fuzzy app_command_name app_command_register app_strict option parameter) ], also => [ 'Moose' ], as_is => [ 'new_with_command' ], install => [ 'unimport','init_meta' ], ); sub import { my ( $class, @plugins ) = @_; # Get caller my ($caller_class) = caller(); # Process plugins MooseX::App::Exporter->process_plugins($caller_class,@plugins); # Call Moose-Exporter generated importer return $class->$IMPORT( { into => $caller_class } ); } sub init_meta { my ($class,%args) = @_; $args{roles} = ['MooseX::App::Role::Base']; $args{metaroles} = { class => [ 'MooseX::App::Meta::Role::Class::Base', 'MooseX::App::Meta::Role::Class::Documentation' ], attribute => ['MooseX::App::Meta::Role::Attribute::Option'], }; return MooseX::App::Exporter->process_init_meta(%args); } sub app_command_name(&) { my ( $meta, $namesub ) = @_; return $meta->app_command_name($namesub); } sub app_command_register(%) { my ( $meta, %commands ) = @_; foreach my $command (keys %commands) { $meta->command_register($command,$commands{$command}); } return; } sub app_namespace(@) { my ( $meta, @namespaces ) = @_; return $meta->app_namespace( \@namespaces ); } sub new_with_command { my ($class,@args) = @_; Moose->throw_error('new_with_command is a class method') if ! defined $class || blessed($class); my $meta = $class->meta; my $metameta = $meta->meta; Moose->throw_error('new_with_command may only be called from the application base package:'.$class) if $metameta->does_role('MooseX::App::Meta::Role::Class::Command') || ! $metameta->does_role('MooseX::App::Meta::Role::Class::Base'); # Extra args my %args; if (scalar @args == 1 && ref($args[0]) eq 'HASH' ) { %args = %{$args[0]}; } elsif (scalar @args % 2 == 0) { %args = @args; } else { Moose->throw_error('new_with_command got invalid extra arguments'); } # Get ARGV my $parsed_argv = MooseX::App::ParsedArgv->instance(); my $first_argv = $parsed_argv->first_argv; # Requested help if (defined $first_argv && lc($first_argv) =~ m/^(help|h|\?|usage|-h|--help|-\?|--usage)$/) { return MooseX::App::Message::Envelope->new( $meta->command_usage_global(), ); # No args } elsif (! defined $first_argv || $first_argv =~ m/^\s*$/ || $first_argv =~ m/^-{1,2}\w/) { return MooseX::App::Message::Envelope->new( $meta->command_message( header => "Missing command", # LOCALIZE type => "error", ), $meta->command_usage_global(), 127, # exitcode ); # Looks like a command } else { my $return = $meta->command_find($first_argv); # Nothing found if (blessed $return && $return->isa('MooseX::App::Message::Block')) { return MooseX::App::Message::Envelope->new( $return, $meta->command_usage_global(), 127, # exitcode ); # One command found } else { my $command_class = $meta->command_get($return); return $class->initialize_command_class($command_class,%args); } } } no Moose; 1; __END__ =encoding utf8 =head1 NAME MooseX::App - Write user-friendly command line apps with even less suffering =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Color); option 'global_option' => ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); # Global option has 'private' => ( is => 'rw', ); # not exposed Write multiple command classes (If you have only a single command class you should use L instead) package MyApp::SomeCommand; use MooseX::App::Command; # important (also imports Moose) extends qw(MyApp); # optional, only if you want to use global options from base class # Positional parameter parameter 'some_parameter' => ( is => 'rw', isa => 'Str', required => 1, documentation => q[Some parameter that you need to supply], ); option 'some_option' => ( is => 'rw', isa => 'Int', required => 1, documentation => q[Very important option!], ); # Option sub run { my ($self) = @_; # Do something } And then you need a simple wrapper script (called eg. myapp): #!/usr/bin/env perl use MyApp; MyApp->new_with_command->run; On the command line: bash$ myapp help usage: myapp [long options...] myapp help global options: --global_option Enable this to do fancy stuff [Flag] --help --usage -? Prints this usage information. [Flag] available commands: some_command Description of some command another_command Description of another command help Prints this usage information or bash$ myapp some_command --help usage: myapp some_command [long options...] myapp help myapp some_command --help parameters: some_parameter Some parameter that you need to supply [Required] options: --global_option Enable this to do fancy stuff [Flag] --some_option Very important option! [Int,Required] --help --usage -? Prints this usage information. [Flag] =head1 DESCRIPTION MooseX-App is a highly customisable helper to write user-friendly command line applications without having to worry about most of the annoying things usually involved. Just take any existing L class, add a single line (C) and create one class for each command in an underlying namespace. Options and positional parameters can be defined as simple L accessors. MooseX-App will then =over =item * Find, load and initialise the command classes (see L for single command applications) =item * Create automated help and documentation from modules POD as well as attributes metadata and type constraints =item * Read, encode and validate the command line options and positional parameters entered by the user from @ARGV and %ENV (and possibly prompt the user for additional parameters see L) =item * Provide helpful error messages if user input cannot be validated (either missing or wrong attributes or Moose type constraints not satisfied) =back Commandline options are defined using the 'option' keyword which accepts the same attributes as Moose' 'has' keyword. option 'some_option' => ( is => 'rw', isa => 'Str', ); This is equivalent to has 'some_option' => ( is => 'rw', isa => 'Str', traits => ['AppOption'], # Load extra metaclass cmd_type => 'option', # Set attribute type ); Single letter options are treated as flags and may be combined with eachother. Positional parameters are defined with the 'parameter' keyword parameter 'some_option' => ( is => 'rw', isa => 'Str', ); This is equivalent to has 'some_option' => ( is => 'rw', isa => 'Str', traits => ['AppOption'], cmd_type => 'parameter', ); Furthermore, all options and parameters can also be supplied via %ENV option 'some_option' => ( is => 'rw', isa => 'Str', cmd_env => 'SOME_OPTION', ); Read the L for getting started with a simple MooseX::App command line application. =head1 METHODS =head2 new_with_command my $myapp_command = MyApp->new_with_command(); This constructor reads the command line arguments and tries to create a command class instance. If it fails it retuns a L object holding an error message. You can pass a hash of default/fallback params to new_with_command my $obj = MyApp->new_with_command(%default); =head2 initialize_command_class my $obj = MyApp->initialize_command_class($command_name,%default); Helper method to instantiate the command class for the given command. =head1 GLOBAL OPTIONS =head2 app_base app_base 'my_script'; # Defaults to $0 Usually MooseX::App will take the name of the calling wrapper script to construct the program name in various help messages. This name can be changed via the app_base function. =head2 app_fuzzy app_fuzzy(1); # default OR app_fuzzy(0); Enables fuzzy matching of commands and attributes. Is turned on by default. =head2 app_strict app_strict(0); # default OR app_strict(1); If strict is enabled the program will terminate with an error message if superfluous/unknown positional parameters are supplied. If disabled all extra parameters will be copied to the L attribute. The command_strict config in the command classes allows one to set this option individually for each command in the respective command class. =head2 app_prefer_commandline app_prefer_commandline(0); # default or app_prefer_commandline(1); Specifies if parameters/options supplied via @ARGV,%ENV should take precedence over arguments passed to new_with_command. =head2 app_namespace app_namespace 'MyApp::Commands', 'YourApp::MoreCommands'; OR app_namespace(); Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed and you can add multiple extra namespaces. If app_namespace is called with no parameters then autoloading of command classes will be disabled entirely. =head2 app_command_name app_command_name { my ($package) = shift; # munge package name; return $command_name; }; This coderef can be used to control how autoloaded package names should be translated to command names. =head2 app_command_register app_command_register do => 'MyApp::Commands::DoSomething', undo => 'MyApp::Commands::UndoSomething'; This keyword can be used to register additional commands. Especially usefull in conjunction with app_namespace. =head2 app_description app_description qq[Description text]; Set the description. If not set this information will be taken from the Pod DESCRIPTION or OVERVIEW sections. =head2 app_usage app_usage qq[myapp --option ...]; Set custom usage. If not set this will be taken from the Pod SYNOPSIS or USAGE section. If both sections are not available, the usage information will be autogenerated. =head1 GLOBAL ATTRIBUTES All MooseX::App classes will have two extra attributes =head2 extra_argv Carries all parameters from @ARGV that were not consumed (only if app_strict is turned off, otherwise superfluous parameters will raise an exception). =head2 help_flag Help flag that is set when help was requested. =head1 ATTRIBUTE OPTIONS Options and parameters accept extra attributes for customisation: =over =item * cmd_tags - Extra tags (as used by the help) =item * cmd_flag - Override option/parameter name =item * cmd_aliases - Additional option/parameter names =item * cmd_split - Split values into ArrayRefs =item * cmd_position - Specify option/parameter order in help =item * cmd_env - Read options/parameters from %ENV =item * cmd_count - Value of option equals to number of occurences in @ARGV =back Refer to L for detailed documentation. =head1 METADATA MooseX::App will use your class metadata and POD to construct the commands and helpful error- or usage- messages. These bits of information are utilised and should be provided if possible: =over =item * Package names =item * L options for Moose attributes =item * L options for Moose attributes =item * Moose type constraints (Bool, ArrayRef, HashRef, Int, Num, and Enum) =item * Documentation set via app_description, app_usage, command_short_description, command_long_description and command_usage =item * POD (NAME, ABSTRACT, DESCRIPTION, USAGE, SYNOPSIS, OVERVIEW, COPYRIGHT, LICENSE, COPYRIGHT AND LICENSE, AUTHOR and AUTHORS sections) =item * Dzil ABSTRACT tag if no POD is available yet =back =head1 PLUGINS The behaviour of MooseX-App can be customised with plugins. To load a plugin just pass a list of plugin names after the C statement. (Attention: order sometimes matters) use MooseX::App qw(PluginA PluginB); Currently the following plugins are shipped with MooseX::App =over =item * L Adds a command that genereates a bash completion script for your application. =item * L Colorful output for your MooseX::App applications. =item * L Config files for MooseX::App applications. =item * L Search config files in users home directory. =item * L Prompt user for options and parameters that were not provided via options or params. Prompt offers basic editing capabilities and history =item * L Handle typos in command names and provide suggestions. =item * L Adds a command to display the version and license of your application. =item * L Display full manpage of application and commands. =item * L Allow for mutally exclusive options =item * L Adds dependent options =back Refer to L for documentation on how to create your own plugins. =head1 CAVEATS & KNOWN BUGS Startup time may be an issue - escpecially if you load many plugins. If you do not require the functionality of plugins and ability for fine grained customisation (or Moose for that matter) then you should probably use L or L. In some cases - especially when using non-standard class inheritance - you may end up with command classes lacking the help attribute. In this case you need to include the following line in your base class with qw(MooseX::App::Role::Common); =head1 SEE ALSO Read the L for getting started with a simple MooseX::App command line application. For alternatives you can check out L, L, L, L and L =head1 SUPPORT Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your report as I make changes. =head1 AUTHOR Maroš Kollár CPAN ID: MAROS maros [at] k-1.com http://www.k-1.com =head1 CONTRIBUTORS Special thanks to all contributors. In no particular order: Andrew Jones, George Hartzell, Steve Nolte, Michael G, Thomas Klausner, Yanick Champoux, Edward Baudrez, David Golden, J.R. Mash, Thilo Fester, Gregor Herrmann, Sergey Romanov, Sawyer X, Roman F., Hunter McMillen, Maik Hentsche =head1 COPYRIGHT MooseX::App is Copyright (c) 2012-15 Maroš Kollár. This library is free software and may be distributed under the same terms as perl itself. The full text of the licence can be found in the LICENCE file included with this module. =cut MooseX-App-1.33/lib/MooseX/App/Command.pm000644 000765 000024 00000006236 12454262644 020310 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Command; # ============================================================================ use 5.010; use utf8; use strict; use warnings; use Moose (); use MooseX::App::Meta::Role::Attribute::Option; use MooseX::App::Exporter qw(option parameter command_short_description command_long_description command_usage command_strict); use Moose::Exporter; Moose::Exporter->setup_import_methods( with_meta => [qw(command_short_description command_long_description command_strict command_usage option parameter)], also => 'Moose', ); sub init_meta { my ($class,%args) = @_; my $meta = Moose->init_meta( %args ); Moose::Util::MetaRole::apply_metaroles( for => $meta, class_metaroles => { class => [ 'MooseX::App::Meta::Role::Class::Documentation', 'MooseX::App::Meta::Role::Class::Command' ], attribute => ['MooseX::App::Meta::Role::Attribute::Option'], }, ); Moose::Util::MetaRole::apply_base_class_roles( for => $args{for_class}, roles => ['MooseX::App::Role::Common'], ); return $meta; } 1; __END__ =pod =head1 NAME MooseX::App::Command - Load command class metaclasses =head1 SYNOPSIS package MyApp::SomeCommand; use Moose; # optional use MooseX::App::Command option 'testattr' => ( isa => 'rw', cmd_tags => [qw(Important! Nice))], ); command_short_description 'This is a short description'; command_long_description 'This is a much longer description yadda yadda'; command_usage 'script some_command --testattr 123'; =head1 DESCRIPTION By loading this class into your command classes you enable all documentation features such as: =over =item * Parsing command documentation from Pod =item * Setting the command documentation manually via C and C =item * Overriding the automated usage header with custom usage from Pod or via C =item * Adding the C, C, C and C attributes to options =back =head1 FUNCTIONS =head2 command_short_description Set the short description. If not set this information will be taken from the Pod NAME or ABSTRACT section. Alternative this will be taken from the DistZilla ABSTRACT tag. =head2 command_long_description Set the long description. If not set this information will be taken from the Pod DESCRIPTION or OVERVIEW sections. =head2 command_usage Set custom usage. If not set this will be taken from the Pod SYNOPSIS or USAGE section. If those sections are not available, the usage information will be autogenerated. =head2 command_strict command_strict(0); # default OR command_strict(1); If strict is enabled the program will terminate with an error message if superfluous/unknown positional parameters are supplied. If disabled all extra parameters will be copied to the L attribute. The app_strict function in the app classes allows one to set this option globally. =cut 1; MooseX-App-1.33/lib/MooseX/App/Exporter.pm000644 000765 000024 00000012020 12454262644 020526 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Exporter; # ============================================================================ use 5.010; use utf8; use strict; use warnings; use Moose::Exporter; use MooseX::App::Utils; use MooseX::App::ParsedArgv; no if $] >= 5.018000, warnings => qw(experimental::smartmatch); my %PLUGIN_SPEC; sub import { my ( $class, @imports ) = @_; my $caller_class = caller(); my $caller_stash = Package::Stash->new($caller_class); my $exporter_stash = Package::Stash->new(__PACKAGE__); foreach my $import (@imports) { my $symbol = $exporter_stash->get_symbol('&'.$import); Carp::confess(sprintf('Symbol %s not defined in %s',$import,__PACKAGE__)) unless defined $symbol; $caller_stash->add_symbol('&'.$import, $symbol); } return; } sub parameter { my ($meta,$name,@rest) = @_; return _handle_attribute($meta,$name,'parameter',@rest); } sub option { my ($meta,$name,@rest) = @_; return _handle_attribute($meta,$name,'option',@rest); } sub _handle_attribute { my ($meta,$name,$type,@rest) = @_; Moose->throw_error('Usage: option \'name\' => ( key => value, ... )') if @rest % 2 == 1; my %info; @info{qw(package file line)} = caller(2); my %attributes = ( definition_context => \%info, @rest ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; $attributes{'cmd_type'} = $type; foreach my $attr (@$attrs) { my %local_attributes = %attributes; if ($attr =~ m/^\+(.+)/) { my $meta_attribute = $meta->find_attribute_by_name($1); unless ($meta_attribute->does('MooseX::App::Meta::Role::Attribute::Option')) { $local_attributes{traits} ||= []; push @{$local_attributes{traits}},'MooseX::App::Meta::Role::Attribute::Option' unless 'AppOption' ~~ $local_attributes{traits} || 'MooseX::App::Meta::Role::Attribute::Option' ~~ $local_attributes{traits}; } } $meta->add_attribute( $attr, %local_attributes ); } return; } sub app_prefer_commandline($) { my ( $meta, $value ) = @_; return $meta->app_prefer_commandline($value); } sub app_strict($) { my ( $meta, $value ) = @_; return $meta->app_strict($value); } sub app_fuzzy($) { my ( $meta, $value ) = @_; return $meta->app_fuzzy($value); } sub app_base($) { my ( $meta, $name ) = @_; return $meta->app_base($name); } sub process_plugins { my ($self,$caller_class,@plugins) = @_; # Loop all requested plugins my @plugin_classes; foreach my $plugin (@plugins) { my $plugin_class = 'MooseX::App::Plugin::'.$plugin; # TODO eval plugin class Class::Load::load_class($plugin_class); push (@plugin_classes,$plugin_class); } # Store plugin spec $PLUGIN_SPEC{$caller_class} = \@plugin_classes; return; } sub process_init_meta { my ($self,%args) = @_; my $meta = Moose->init_meta( %args ); my $plugins = $PLUGIN_SPEC{$args{for_class}} || []; my $apply_metaroles = delete $args{metaroles} || {}; my $apply_roles = delete $args{roles} || []; foreach my $plugin (@$plugins) { push(@{$apply_roles},$plugin,{ -excludes => [ 'plugin_metaroles' ] } ) } push(@{$apply_roles},'MooseX::App::Role::Common') unless $apply_roles ~~ 'MooseX::App::Role::Common'; # Process all plugins in the given order foreach my $plugin_class (@{$plugins}) { if ($plugin_class->can('plugin_metaroles')) { my ($metaroles) = $plugin_class->plugin_metaroles($args{for_class}); if (ref $metaroles eq 'HASH') { foreach my $type (keys %$metaroles) { $apply_metaroles->{$type} ||= []; push (@{$apply_metaroles->{$type}},@{$metaroles->{$type}}); } } } } # Add meta roles Moose::Util::MetaRole::apply_metaroles( for => $args{for_class}, class_metaroles => $apply_metaroles ); # Add class roles Moose::Util::apply_all_roles($args{for_class},@{$apply_roles}); foreach my $plugin_class (@{$plugins}) { if ($plugin_class->can('init_plugin')) { $plugin_class->init_plugin($args{for_class}); } } return $meta; } sub command_short_description($) { my ( $meta, $description ) = @_; return $meta->command_short_description($description); } sub command_long_description($) { my ( $meta, $description ) = @_; return $meta->command_long_description($description); } sub command_usage($) { my ( $meta, $usage ) = @_; return $meta->command_usage($usage); } *app_description = \&command_long_description; *app_usage = \&command_usage; sub command_strict($) { my ( $meta, $value ) = @_; return $meta->command_strict($value); } 1; MooseX-App-1.33/lib/MooseX/App/Message/000755 000765 000024 00000000000 12514113027 017734 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Meta/000755 000765 000024 00000000000 12514113027 017236 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/ParsedArgv/000755 000765 000024 00000000000 12514113027 020406 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/ParsedArgv.pm000644 000765 000024 00000016754 12467206231 020770 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::ParsedArgv; # ============================================================================ use 5.010; use utf8; use Moose; use Encode qw(decode); use MooseX::App::ParsedArgv::Element; no if $] >= 5.018000, warnings => qw(experimental::smartmatch); my $SINGLETON; has 'argv' => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { my @argv; @argv = eval { require I18N::Langinfo; I18N::Langinfo->import(qw(langinfo CODESET)); my $codeset = langinfo(CODESET()); # TODO Not sure if this is the right place? binmode(STDOUT, ":encoding(UTF-8)") if $codeset =~ m/^UTF-?8$/i; return map { decode($codeset,$_) } @ARGV; }; # Fallback to standard if ($@) { @argv = @ARGV; } return \@argv; }, ); has 'hints' => ( is => 'rw', isa => 'ArrayRef[Str]', default => sub { [] }, ); # Hints for the parser has 'elements' => ( is => 'ro', isa => 'ArrayRef[MooseX::App::ParsedArgv::Element]', lazy => 1, builder => '_build_elements', clearer => 'reset_elements', ); sub BUILD { my ($self) = @_; $SINGLETON = $self; return $self; } sub instance { my ($class) = @_; unless (defined $SINGLETON) { return $class->new(); } return $SINGLETON; } sub first_argv { my ($self) = @_; $self->reset_elements; return shift(@{$self->argv}); } sub _build_elements { my ($self) = @_; my (@elements); my %options; my $lastkey; my $stopprocessing; foreach my $element (@{$self->argv}) { if ($stopprocessing) { push (@elements,MooseX::App::ParsedArgv::Element->new( key => $element, type => 'extra', )); } else { given ($element) { # Flags when (m/^-([^-][[:alnum:]]*)$/) { undef $lastkey; foreach my $flag (split(//,$1)) { unless (defined $options{$flag}) { $options{$flag} = MooseX::App::ParsedArgv::Element->new( key => $flag, type => 'option', raw => $element, ); push(@elements,$options{$flag}); } else { $options{$flag}->inc_occurence; } $lastkey = $options{$flag}; } } # Key-value combined when (m/^--([^-=][^=]*)=(.+)$/) { undef $lastkey; my ($key,$value) = ($1,$2); unless (defined $options{$key}) { $options{$key} = MooseX::App::ParsedArgv::Element->new( key => $key, type => 'option', raw => $element, ); push(@elements,$options{$key}); } else { $options{$key}->inc_occurence; } $options{$key}->add_value($value); } # Key when (m/^--([^-].*)/) { my $key = $1; unless (defined $options{$key}) { $options{$key} = MooseX::App::ParsedArgv::Element->new( key => $key, type => 'option', raw => $element, ); push(@elements,$options{$key}); } else { $options{$key}->inc_occurence; } $lastkey = $options{$key}; } # Extra values when ('--') { undef $lastkey; $stopprocessing = 1; } # Value default { if (defined $lastkey) { # No value if ($lastkey->key ~~ $self->hints) { push(@elements,MooseX::App::ParsedArgv::Element->new( key => $element, type => 'parameter' )); # Has value } else { $lastkey->add_value($element); } undef $lastkey; } else { push(@elements,MooseX::App::ParsedArgv::Element->new( key => $element, type => 'parameter' )); } } } } } return \@elements; } sub available { my ($self,$type) = @_; my @elements; foreach my $element (@{$self->elements}) { next if $element->consumed; next if defined $type && $element->type ne $type; push(@elements,$element); } return @elements; } sub consume { my ($self,$type) = @_; foreach my $element (@{$self->elements}) { next if $element->consumed; next if defined $type && $element->type ne $type; $element->consume; return $element; } return; } sub extra { my ($self) = @_; my @extra; foreach my $element (@{$self->elements}) { next if $element->consumed; next unless $element->type eq 'parameter' || $element->type eq 'extra'; push(@extra,$element->key); } return @extra; } __PACKAGE__->meta->make_immutable; 1; __END__ =pod =head1 NAME MooseX::App::ParsedArgv - Parses @ARGV =head1 SYNOPSIS use MooseX::App::ParsedArgv; my $argv = MooseX::App::ParsedArgv->instance; foreach my $option ($argv->available('option')) { say "Parsed ".$option->key; } =head1 DESCRIPTION This is a helper class that holds all options parsed from @ARGV. It is implemented as a singleton. Unless you are developing a MooseX::App plugin you usually do not need to interact with this class. =head1 METHODS =head2 new Create a new MooseX::App::ParsedArgv instance. Needs to be called as soon as possible. =head2 instance Get the current MooseX::App::ParsedArgv instance. If there is no instance a new one will be created. =head2 argv Accessor for the initinal @ARGV. =head2 hints ArrayRef of attributes that tells the parser which attributes should be regarded as flags without values. =head2 first_argv Shifts the current first element from @ARGV. =head2 available my @options = $self->available($type); OR my @options = $self->available(); Returns an array of all parsed options or parameters that have not yet been consumed. The array elements will be L objects. =head2 consume my $option = $self->consume($type); OR my $option = $self->consume(); Returns the first option/parameter of the local @ARGV that has not yet been consumed as a L object. =head2 elements Returns all parsed options and parameters. =head2 extra Returns an array reference of unconsumed positional parameters and extra values. =cutMooseX-App-1.33/lib/MooseX/App/Plugin/000755 000765 000024 00000000000 12514113027 017606 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Role/000755 000765 000024 00000000000 12514113027 017251 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Role.pm000644 000765 000024 00000002604 12454262644 017626 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Role; # ============================================================================ use 5.010; use utf8; use strict; use warnings; use Moose::Role (); use MooseX::App::Exporter qw(option parameter); use Moose::Exporter; Moose::Exporter->setup_import_methods( also => 'Moose::Role', with_meta => [qw(option parameter)], ); sub init_meta { my (undef,%args) = @_; my $meta = Moose::Role->init_meta( %args ); Moose::Util::MetaRole::apply_metaroles( for => $meta, role_metaroles => { applied_attribute => ['MooseX::App::Meta::Role::Attribute::Option'], }, ); return $meta; } 1; __END__ =pod =head1 NAME MooseX::App::Role - Define attributes in a role =head1 SYNOPSIS package MyApp::Role::SomeRole; use Moose::Role; # optional use MooseX::App::Role; option 'testattr' => ( isa => 'rw', cmd_tags => [qw(Important! Nice))], ); =head1 DESCRIPTION Enables the 'option' and 'parameter' keywords in your roles. Alternatively you can also just use attribute traits: has 'testattr' => ( isa => 'rw', traits => ['AppOption'], # required cmd_type => 'option', # required cmd_tags => [qw(Important! Nice))], ); =cutMooseX-App-1.33/lib/MooseX/App/Simple.pm000644 000765 000024 00000010447 12503332073 020147 0ustar00marosstaff000000 000000 package MooseX::App::Simple; # ============================================================================« use 5.010; use utf8; use strict; use warnings; our $AUTHORITY = 'cpan:MAROS'; our $VERSION = 1.32; use Moose::Exporter; use MooseX::App::Exporter qw(app_usage app_description app_base app_fuzzy app_strict app_prefer_commandline option parameter command_short_description command_long_description command_usage command_strict); use MooseX::App::Meta::Role::Attribute::Option; use MooseX::App::Message::Envelope; use Scalar::Util qw(blessed); my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods( with_meta => [ qw(app_usage app_description app_base app_fuzzy app_strict option parameter command_short_description command_long_description command_usage command_strict) ], also => [ 'Moose' ], as_is => [ 'new_with_options' ], install => [ 'unimport', 'init_meta' ], ); sub import { my ( $class, @plugins ) = @_; # Get caller my ($caller_class) = caller(); # Process plugins MooseX::App::Exporter->process_plugins($caller_class,@plugins); # Call Moose-Exporter generated importer return $class->$IMPORT( { into => $caller_class } ); } sub init_meta { my ($class,%args) = @_; my $for_class = $args{for_class}; $args{roles} = ['MooseX::App::Role::Base' ]; $args{metaroles} = { class => [ 'MooseX::App::Meta::Role::Class::Base', 'MooseX::App::Meta::Role::Class::Simple', 'MooseX::App::Meta::Role::Class::Documentation' ], attribute => [ 'MooseX::App::Meta::Role::Attribute::Option' ], }; my $meta = MooseX::App::Exporter->process_init_meta(%args); $for_class->meta->app_commands({ 'self' => $for_class }); return $meta; } sub new_with_options { my ($class,@args) = @_; Moose->throw_error('new_with_options is a class method') if ! defined $class || blessed($class); my %args; if (scalar @args == 1 && ref($args[0]) eq 'HASH' ) { %args = %{$args[0]}; } elsif (scalar @args % 2 == 0) { %args = @args; } else { Moose->throw_error('new_with_command got invalid extra arguments'); } my $parsed_argv = MooseX::App::ParsedArgv->instance(); return $class->initialize_command_class($class,%args); } no Moose; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Simple - Single command applications =head1 SYNOPSIS package MyApp; use MooseX::App::Simple qw(Config Color); parameter 'param' => ( is => 'rw', isa => 'Str', documentation => q[First parameter], required => 1, ); # Positional parameter option 'my_option' => ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); # Option (--my_option) has 'private' => ( is => 'rw', ); # not exposed sub run { my ($self) = @_; # Do something } And then in some simple wrapper script: #!/usr/bin/env perl use MyApp; MyApp->new_with_options->run; =head1 DESCRIPTION MooseX-App-Simple works basically just as MooseX-App, however it does not search for commands and assumes that you have all options and parameters defined in the current class. Read the L for getting started with a simple MooseX::App command line application. =head1 METHODS =head2 new_with_options my $myapp_command = MyApp->new_with_options(); This method reads the command line arguments from the user and tries to create instantiate the current class with the ARGV-input. If it fails it retuns a L object holding an error message. You can pass a hash or hashref of default params to new_with_options MyApp->new_with_options( %default ); =head1 OPTIONS Same as in L =head1 PLUGINS Same as in L. However plugings adding commands (eg. version) will not work with MooseX::App::Simple. =head1 SEE ALSO Read the L for getting started with a simple MooseX::App command line application. See L and L for alternatives =cut MooseX-App-1.33/lib/MooseX/App/Tutorial.pod000644 000765 000024 00000016715 12477077767 020725 0ustar00marosstaff000000 000000 =pod =head1 NAME MooseX::App::Tutorial - getting started with MooseX::App =head1 GETTING STARTED To create a simple command-line application with MooseX::App you need =over =item * A base class =item * Multiple command classes (unless you use L) =item * and an invocation script =back =head1 BASE CLASS The simplest possible base class just contains a single use statement which loads all roles and metaclasses you need to get started as well as Moose. package MyApp; use MooseX::App; 1; The base class can be customized by =over =item * adding MooseX-App plugins =item * changing the command-class namespace =item * defining global attributes used by all command classes (if they inherit from the base class) =item * add documentation (either POD or via the app_usage and app_description functions) =item * and changing MooseX-App flags (eg. turn fuzzy matching off) =back It is also possible to add global options and parameters to your base class and inherit your command classes from the base class (inheriting your command classes from your base class is purely optional). package MyApp; use MooseX::App qw(Config Color); # Loads the Config and Color plugin # This attribute will be available at the command line option 'some_global_option' => ( is => 'rw', isa => 'Str', documentation => q[Some important global option], ); # This attribute will not be exposed has 'private_option' => ( is => 'rw', isa => 'Str', ); 1; When adding attributes make sure to include a documentation and possibly a type constraint. MooseX-App will use this information to build a user documentation for each attribute and command. The attribute documentation can be customized by providing additional options (see L) =head1 COMMAND CLASSES After you have created a base class it is time to create one class for each command you want to provide (unless you are using L). The command classes must reside in the namespace of the base class (eg. 'MyApp::SomeCommand'). The namespace for the command classes however can be changed via the 'app_namespace' function in the base class, or by simply registering command classes manually via 'app_command_register'. All command classes must use MooseX::App::Command. package MyApp::SomeCommand; use MooseX::App::Command; If you want to use global options defined in the base class you can optionally extend the base class with your command class. package MyApp::SomeCommand; use MooseX::App::Command; extends qw(MyApp); To provide a description for each command you need to set the C, C and optionally C information. The command descriptions may contain linebreaks. command_short_description q[This command is awesome]; command_long_description q[This command is so awesome, yadda yadda yadda]; If not provided, MooseX-App will try to parse the command description from the POD. The NAME or ABSTRACT section will become the short description and the DESCRIPTION or OVERVIEW section the long description. The usage header can either be set by adding C command_usage q[script some_command --some_option NUMBER]; or by adding a SYNOPSIS or USAGE section to the module' POD. If neither command_usage nor SYNOPSIS/USAGE are set, then the usage header will be autogenerated. Attributes can be documented using the Moose built-in C option as well as C, C and C which are defined by MooseX-App (see L) option 'some_option' => ( is => 'rw', isa => 'Integer', required => 1, documentation => q[Some important option], cmd_tags => [qw(Important!)], # Extra tags. Displayed in square brackets cmd_aliases => [qw(s)], # Alternative option name cmd_flag => 'some', # Option should be called 'some' instead of 'some_option' ); It is also possible to define positional parameters with the 'parameter' keyword # This attribute will become a positional parameter parameter 'id' => ( is => 'rw', isa => 'Int', documentation => q[Some ID], required => 1, ); The help for this command would look something like this (with autogenerated usage headers): usage: my_app some_command [long options...] my_app help my_app some_command --help description: This command is awesome, yadda yadda yadda parameter: ID Some ID [Integer; Required] options: --config Path to command config file --some -s Some important option [Required; Integer; Important!] --help --usage -? Prints this usage information. [Flag] In case you want to include an attribute not defined with the 'option' or 'parameter' keyword you can use the 'AppOption' trait and 'cmd_type' attribute. (see L). has 'myoption' => ( is => 'rw', traits => ['AppOption'], # only required if not definded in base or command class cmd_type => 'option', # or 'parameter' ); Finally your command classes will need a method which should be called if the command is invoked by the user. sub run { my ($self) = @_; # do something } If you need to implement only a single command you should use L instead of L, and omit command classes. In this case of course you have to declare all options and implement the application logic in the base class: package MyApp; use MooseX::App::Simple qw(Config); # Loads the Config plugin option 'some_global_option' => ( is => 'rw', isa => 'Str', documentation => q[Some important global option], ); sub run { my ($self) = @_; # do something } 1; =head1 INVOCATION SCRIPT Once you have the base and command classes ready, you need to write a small invocation script: #!/usr/bin/env perl use MyApp; MyApp->new_with_command->run(); Cnew_with_command> will try to instantiate a command class. If it fails it will return a L object possibly containing an error message and a usage message. Since L follows the Null object pattern you can call any method on it without checking the object type. Note that MooseX::App::Message::Envelope objects may also have an exitcode set. In this case whenever the object gets stringified, it print on STDERR/STDOUT and exits the programm using the specified exitcode. Don't use the ovleroad stingification if you don't want this behaviour. You can also pass default/fallback values to the constructor #!/usr/bin/env perl use MyApp; MyApp->new_with_command( some_global_option => 'something' )->run(); If using L your invocation script needs some modification. #!/usr/bin/env perl use MyApp; MyApp->new_with_options->run(); =head1 HOW TO CONTINUE Once you have a basic working application you can make it more user friendly by adding documentation (either by using the app_description, app_usage, command_short_description, ... functions or by writing POD) and Moose type constraints and additional plugins (eg. colorise the output). =cutMooseX-App-1.33/lib/MooseX/App/Utils.pm000644 000765 000024 00000015731 12454262644 020032 0ustar00marosstaff000000 000000 package MooseX::App::Utils; use 5.010; use utf8; use strict; use warnings; use List::Util qw(max); our $SCREEN_WIDTH = 78; our $INDENT = 4; use Moose::Util::TypeConstraints; subtype 'MooseX::App::Types::List' => as 'ArrayRef'; coerce 'MooseX::App::Types::List' => from 'Str' => via { [$_] }; subtype 'MooseX::App::Types::CmdTypes' => as enum([qw(proto option parameter)]); subtype 'MooseX::App::Types::MessageString' => as 'Str'; coerce 'MooseX::App::Types::MessageString' => from 'ArrayRef' => via { sprintf(@{$_}) }; subtype 'MooseX::App::Types::Env' => as 'Str' => where { m/^[A-Z0-9_]+$/ }; no Moose::Util::TypeConstraints; no if $] >= 5.018000, warnings => qw/ experimental::smartmatch /; # Default package name to command name translation function sub class_to_command { my ($class) = @_; return unless defined $class; my @parts = split( /[_\s]+|\b|(?[0]) } @list); my $description_length = $SCREEN_WIDTH - $max_length - 7; my $prefix_length = $max_length + $INDENT + 2; my @return; foreach my $command (@list) { my $description = $command->[1] // ''; my @lines = split_string($description_length,$description); push (@return,(' 'x$INDENT).sprintf('%-*s %s',$max_length,$command->[0],shift(@lines))); while (my $line = shift (@lines)) { push(@return,' 'x $prefix_length.$line); } } return join("\n",@return); } # Simple splitting of long sentences on whitespaces or punctuation sub split_string { my ($maxlength, $string) = @_; return unless defined $string; return $string if length $string <= $maxlength; my (@lines,$line); $line = ''; foreach my $word (split(m/(\p{IsPunct}|\p{IsSpace})/,$string)) { if (length($line.$word) <= $maxlength) { $line .= $word; } else { push(@lines,$line) if ($line ne ''); $line = ''; if (length($word) > $maxlength) { my (@parts) = grep { $_ ne '' } split(/(.{$maxlength})/,$word); my $lastline = pop(@parts); push(@lines,@parts); if (defined $lastline && $lastline ne '') { $line = $lastline; } } else { $line = $word; } } } push(@lines,$line) if ($line ne ''); @lines = map { m/^\s*(.+?)\s*$/ ? $1 : $_ } @lines; return @lines; } # Try to get filename for a given package name sub package_to_filename { my ($package) = @_; # Package to filename my $package_filename = $package; $package_filename =~ s/::/\//g; $package_filename .= '.pm'; my $package_filepath; if (defined $INC{$package_filename}) { $package_filepath = $INC{$package_filename}; $package_filepath =~ s/\/{2,}/\//g; } # No filename available return unless defined $package_filepath && -e $package_filepath; return $package_filepath; } # Parse pod sub parse_pod { my ($package) = @_; my $package_filepath = package_to_filename($package); return unless $package_filepath; # Parse pod my $document = Pod::Elemental->read_file($package_filepath); Pod::Elemental::Transformer::Pod5->new->transform_node($document); my $nester_head = Pod::Elemental::Transformer::Nester->new({ top_selector => Pod::Elemental::Selectors::s_command('head1'), content_selectors => [ Pod::Elemental::Selectors::s_command([ qw(head2 head3 head4 over back item) ]), Pod::Elemental::Selectors::s_flat() ], }); $document = $nester_head->transform_node($document); # Process pod my %pod; foreach my $element (@{$document->children}) { # Distzilla ABSTRACT tag if ($element->isa('Pod::Elemental::Element::Pod5::Nonpod')) { if ($element->content =~ m/^\s*#+\s*ABSTRACT:\s*(.+)$/m) { $pod{ABSTRACT} ||= $1; } # Pod head1 sections } elsif ($element->isa('Pod::Elemental::Element::Nested') && $element->command eq 'head1') { if ($element->content eq 'NAME') { my $content = _pod_node_to_text($element->children); next unless defined $content; $content =~ s/^$package(\s-)?\s//; chomp($content); $pod{NAME} = $content; } else { my $content = _pod_node_to_text($element->children); next unless defined $content; chomp($content); $pod{uc($element->content)} = $content; } } } return %pod; } # Transform POD to simple markup sub _pod_node_to_text { my ($node,$indent) = @_; unless (defined $indent) { my $indent_init = 0; $indent = \$indent_init; } my (@lines); if (ref $node eq 'ARRAY') { foreach my $element (@$node) { push (@lines,_pod_node_to_text($element,$indent)); } } else { given (ref($node)) { when ('Pod::Elemental::Element::Pod5::Ordinary') { my $content = $node->content; return if $content =~ m/^=cut/; $content =~ s/\n/ /g; $content =~ s/\s+/ /g; push (@lines,$content."\n"); } when ('Pod::Elemental::Element::Pod5::Verbatim') { push (@lines,$node->content."\n"); } when ('Pod::Elemental::Element::Pod5::Command') { given ($node->command) { when ('over') { ${$indent}++; } when ('item') { push (@lines,(' ' x ($$indent-1)) . $node->content); } when ('back') { push (@lines,"\n"); ${$indent}--; } } } } } return unless scalar @lines; my $return = join ("\n", grep { defined $_ } @lines); $return =~ s/\n\n\n+/\n\n/g; # Max one empty line $return =~ s/I<([^>]+)>/_$1_/g; $return =~ s/B<([^>]+)>/*$1*/g; $return =~ s/[LCBI]<([^>]+)>/$1/g; $return =~ s/[LCBI]<([^>]+)>/$1/g; return $return; } 1; MooseX-App-1.33/lib/MooseX/App/WritingPlugins.pod000644 000765 000024 00000003315 12454262644 022060 0ustar00marosstaff000000 000000 =encoding utf8 =pod =head1 NAME MooseX::App::WritingPlugins - Writing plugins for MooseX::App =head1 SYNOPSIS package MooseX::App::Plugin::MyPlugin; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::MyPlugin::Meta::Class'], } } around 'initialize_command_class' => sub { ... }; =head1 DESCRIPTION Plugins are implemented as Moose roles and must reside in the MooseX::App::Plugin::* namespace. Metaclasses can be altered via the 'plugin_metaroles' callback method. Furthermore Moose method modifiers (around, after, before) can be used to alter the behaviour of MooseX::App or its meta classes. =head1 CALLBACKS =head2 plugin_metaroles Optional callback method that should return a hash reference specifying which metaroles will be applied to the class metaclass and its contained metaclasses and helper classes. Each key should in turn point to an array reference of role names. It accepts the following keys: =over =item * class =item * attribute =item * method =item * wrapped_method =item * instance =item * constructor =item * destructor =item * error =back =head1 METACLASSES Most of MooseX-App behaviour is implemented in metaclass roles. When writing plugins you will most likely need to alter/augument the behaviour of these roles. Implementation details can be found in the respective packages. =over =item * L is applied to the base metaclass =item * L is applied to the command metaclass =item * L is applied to all attributes in the base and command meta classes =back =cut MooseX-App-1.33/lib/MooseX/App/Role/Base.pm000644 000765 000024 00000004702 12476532400 020473 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Role::Base; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub initialize_command_class { my ($class,$command_class,%args) = @_; my $meta = $class->meta; Moose->throw_error('initialize_command_class is a class method') if blessed($class); my ($ok,$error) = Class::Load::try_load_class($command_class); unless ($ok) { Moose->throw_error($error); } my $command_meta = $command_class->meta || $meta; my $parsed_argv = MooseX::App::ParsedArgv->instance(); #$parsed_argv->fuzzy($meta->app_fuzzy); $parsed_argv->hints($meta->command_parser_hints($command_meta)); my ($proto_result,$proto_errors) = $meta->command_proto($command_meta); # TODO return some kind of null class object return unless defined $proto_result; my @errors = @{$proto_errors}; # Return user-requested help if ($proto_result->{help_flag}) { return MooseX::App::Message::Envelope->new( $meta->command_usage_command($command_class->meta), ); } my ($result,$errors) = $meta->command_args($command_meta); push(@errors,@{$errors}); my %params; if ($meta->app_prefer_commandline) { %params = ( %args, # configs passed to new %{ $proto_result }, # config params %{ $result }, # params from CLI ); } else { %params = ( %{ $proto_result }, # config params %{ $result }, # params from CLI %args, # configs passed to new ); } $meta->command_check_attributes($command_meta,\@errors,\%params); if (scalar @errors) { return MooseX::App::Message::Envelope->new( @errors, $meta->command_usage_command($command_meta), 1, # exitcode ); } my $command_object = $command_class->new( %params, extra_argv => [ $parsed_argv->extra ], ); if (scalar @errors) { return MooseX::App::Message::Envelope->new( @errors, $meta->command_usage_command($command_meta), 1, # exitcode ); } return $command_object; } 1;MooseX-App-1.33/lib/MooseX/App/Role/Common.pm000644 000765 000024 00000001231 12454262644 021051 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Role::Common; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; has extra_argv => ( is => 'rw', isa => 'ArrayRef', ); has 'help_flag' => ( is => 'ro', isa => 'Bool', traits => ['AppOption'], cmd_flag => 'help', cmd_aliases => [ qw(h usage ?) ], # LOCALIZE cmd_type => 'proto', cmd_position => 99999, documentation => 'Prints this usage information.', # LOCALIZE ); 1;MooseX-App-1.33/lib/MooseX/App/Plugin/BashCompletion/000755 000765 000024 00000000000 12514113027 022515 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/BashCompletion.pm000644 000765 000024 00000002273 12147322150 023060 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::BashCompletion; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::BashCompletion::Meta::Class'], } } around 'initialize_command_class' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); if (blessed $return && $return->isa('MooseX::App::Plugin::BashCompletion::Command')) { return $return->bash_completion($self); } return $return; }; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::BashCompletion - Bash completion for your MooseX::App applications =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(BashCompletion); In your shell bash$ myapp bash_completion > myapp-complete.sh bash$ source myapp-complete.sh =head1 DESCRIPTION This plugin generates a bash completion definition for your application. =head1 SEE ALSO L =cut MooseX-App-1.33/lib/MooseX/App/Plugin/Color/000755 000765 000024 00000000000 12514113027 020664 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Color.pm000644 000765 000024 00000001245 12147322150 021225 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Color; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Color::Meta::Class'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Color - Colorful output for your MooseX::App applications =head1 SYNOPSIS package MyApp; use MooseX::App qw(Color); =head1 DESCRIPTION This plugin enables colors for messages generated by MooseX-App. =cutMooseX-App-1.33/lib/MooseX/App/Plugin/Config/000755 000765 000024 00000000000 12514113027 021013 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Config.pm000644 000765 000024 00000003456 12454262633 021374 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Config; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use MooseX::App::Role; use MooseX::Types::Path::Class; use Config::Any; has 'config' => ( is => 'ro', isa => 'Path::Class::File', coerce => 1, predicate => 'has_config', documentation => q[Path to command config file], traits => ['AppOption'], cmd_type => 'proto', cmd_position => 99990, ); has '_config_data' => ( is => 'ro', isa => 'HashRef', predicate => 'has_config_data', ); sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Config::Meta::Class'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Config - Config files your MooseX::App applications =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Config); option 'global_option' => ( is => 'rw', isa => 'Int', ); In your command class: package MyApp::Some_Command; use MooseX::App::Command; extends qw(MyApp); option 'some_option' => ( is => 'rw', isa => 'Str', ); Now create a config file (see L) eg. a yaml file: --- global: global_option: 123 some_command: global_option: 234 some_option: "hello world" The user can now call the program with a config file: bash$ myapp some_command --config /path/to/config.yml =head1 METHODS =head2 config Read the config filename =head2 _config_data The full content of the loaded config file =head1 SEE ALSO L =cutMooseX-App-1.33/lib/MooseX/App/Plugin/ConfigHome/000755 000765 000024 00000000000 12514113027 021624 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/ConfigHome.pm000644 000765 000024 00000001633 12147322150 022166 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::ConfigHome; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; with qw(MooseX::App::Plugin::Config); sub plugin_metaroles { my ($self,$class) = @_; return { class => [ 'MooseX::App::Plugin::Config::Meta::Class', 'MooseX::App::Plugin::ConfigHome::Meta::Class' ], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::ConfigHome - Config files in users home directory =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(ConfigHome); =head1 DESCRIPTION Works just like L but assumes that the config file always resides in the user's home directory. ~/.${app-base}/config.(yml|xml|ini|...) =cutMooseX-App-1.33/lib/MooseX/App/Plugin/Depends/000755 000765 000024 00000000000 12514113027 021170 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Depends.pm000644 000765 000024 00000002504 12501006073 021525 0ustar00marosstaff000000 000000 package MooseX::App::Plugin::Depends; use Moose::Role; use namespace::clean; sub plugin_metaroles { my ($self, $class) = @_; return { attribute => ['MooseX::App::Plugin::Depends::Meta::Attribute'], class => ['MooseX::App::Plugin::Depends::Meta::Class'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Depends - Adds dependent options =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Depends); use Moose::Util::TypeConstraints; option 'FileFormat' => ( is => 'ro', isa => enum( [qw(tsv csv xml)] ), ); option 'WriteToFile' => ( is => 'ro', isa => 'Bool', depends => [qw(FileFormat)], ); In your script: #!/usr/bin/env perl use strict; use warnings; use MyApp; MyApp->new_with_options( WriteToFile => 1 ); # generates Error # Option 'WriteToFile' requires 'FileFormat' to be defined MyApp->new_with_options( WriteToFile => 1, FileFormat => 'tsv ); # generates no errors MyApp->new_with_options(); # generates no errors =head1 DESCRIPTION In many real-world scenarios, sets of options are, by design, needed to be specified together. This plugin adds the ability to create dependent options to your application, options that require one or more other options for your application to perform properly. =cut MooseX-App-1.33/lib/MooseX/App/Plugin/Env.pm000644 000765 000024 00000000625 12454262644 020714 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Env; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; warn "MooseX::App Env plugin is deprecated. Functionality moved to core"; return; } 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Fuzzy.pm000644 000765 000024 00000000620 12454262644 021306 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Fuzzy; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; warn "MooseX::App Fuzzy plugin is deprecated. Use Typo instead"; return; } 1; MooseX-App-1.33/lib/MooseX/App/Plugin/Man/000755 000765 000024 00000000000 12514113027 020321 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Man.pm000644 000765 000024 00000002013 12466752775 020704 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Man; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Man::Meta::Class'], } } around 'initialize_command_class' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); if (blessed $return && $return->isa('MooseX::App::Plugin::Man::Command')) { return $return->man($self); } return $return; }; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Man - Adds a command to display the full manual =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Man); In your shell bash$ myapp man somecommand =head1 DESCRIPTION This plugin adds a command to display the full manpage/perldoc of your application. =cut MooseX-App-1.33/lib/MooseX/App/Plugin/MutexGroup/000755 000765 000024 00000000000 12514113027 021725 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/MutexGroup.pm000644 000765 000024 00000003130 12477373617 022305 0ustar00marosstaff000000 000000 package MooseX::App::Plugin::MutexGroup; use Moose::Role; use namespace::autoclean; sub plugin_metaroles { my ($self, $class) = @_; return { attribute => ['MooseX::App::Plugin::MutexGroup::Meta::Attribute'], class => ['MooseX::App::Plugin::MutexGroup::Meta::Class'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::MutexGroup - Adds mutually exclusive options =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(MutexGroup); option 'UseAmmonia' => ( is => 'ro', isa => 'Bool', mutexgroup => 'NonMixableCleaningChemicals', ); option 'UseChlorine' => ( is => 'ro', isa => 'Bool', mutexgroup => 'NonMixableCleaningChemicals' ); In your script: #!/usr/bin/env perl use strict; use warnings; use MyApp; MyApp->new_with_options( UseAmmonia => 1, UseChlorine => 1 ); # generates Error # More than one attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *cannot* be specified MyApp->new_with_options(); # generates Error # One attribute from mutexgroup NonMixableCleaningChemicals('UseAmmonia','UseChlorine') *must* be specified MyApp->new_with_options( UseAmmonia => 1 ); # generates no errors MyApp->new_with_options( UseChlorine => 1 ); # generates no errors =head1 DESCRIPTION This plugin adds mutually exclusive options to your application. In the current implementation, all defined MutexGroups *must* have exactly one initialized option. This means that there is an implicit requiredness of one option from each MutexGroup. =cut MooseX-App-1.33/lib/MooseX/App/Plugin/Term/000755 000765 000024 00000000000 12514113027 020515 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Term.pm000644 000765 000024 00000003114 12466212057 021063 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Term; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Term::Meta::Class'], attribute => ['MooseX::App::Plugin::Term::Meta::Attribute'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Term - Allows one to specify options/parameters via terminal prompts =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Term); In your command class: package MyApp::SomeCommand; use MooseX::App::Command; option 'some_option' => ( is => 'rw', isa => 'Int', documentation => 'Something' cmd_term => 1, ); sub run { my ($self) = @_; say "Some option is ".$self->some_option; } In your shell bash$ myapp some_command Something (Required, an integer): test Value must be an integer (not 'test') 1 Some option is 1 =head1 DESCRIPTION This plugin can prompt the user for missing options/parameters on the terminal. The user will only be promted if the parameter were not provided by different means (parameter and option or config files and environment values if the respectice plugins have been loaded before this plugin) and if the script is connected to an interactive terminal. Term input has basic editing capabilities (cursor, del, backspace and history) =cut MooseX-App-1.33/lib/MooseX/App/Plugin/Typo/000755 000765 000024 00000000000 12514113027 020541 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Typo.pm000644 000765 000024 00000001375 12147322150 021106 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Typo; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Typo::Meta::Class'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Typo - Handle typos in command names =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Typo); In your shell bash$ myapp pusl Ambiguous command 'pusl' Which command did you mean? * push * pull =head1 DESCRIPTION This plugin tries to handle typos in command names =cutMooseX-App-1.33/lib/MooseX/App/Plugin/Version/000755 000765 000024 00000000000 12514113027 021233 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Version.pm000644 000765 000024 00000002566 12466753053 021621 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Version; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Version::Meta::Class'], } } around 'initialize_command_class' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); if (blessed $return && $return->isa('MooseX::App::Plugin::Version::Command')) { return $return->version($self); } return $return; }; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::Version - Adds a command to display the version and license of your application =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Version); In your shell bash$ myapp version VERSION MyApp version 2.1 MooseX::App version 1.08 Perl version 5.16.2 LICENSE This library is free software and may be distributed under the same terms as perl itself. =head1 DESCRIPTION This plugin adds a command to display the version of your application, MooseX::App and perl. Furthermore it tries to parse the Pod of the base class and extract LICENSE, AUTHOR and COPYRIGHT sections =cut MooseX-App-1.33/lib/MooseX/App/Plugin/Version/Command.pm000644 000765 000024 00000002434 12454262633 023165 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Version::Command; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Command; command_short_description q(Print the current version); sub version { my ($self,$app) = @_; my $version = ''; $version .= $app->meta->app_base. ' version '.$app->VERSION."\n"; $version .= "MooseX::App version ".$MooseX::App::VERSION."\n"; $version .= "Perl version ".sprintf("%vd", $^V); my $message_class = $app->meta->app_messageclass; my @parts = ($message_class->new({ header => 'VERSION', body => MooseX::App::Utils::format_text($version) })); my %pod_raw = MooseX::App::Utils::parse_pod($app->meta->name); foreach my $part ('COPYRIGHT','LICENSE','COPYRIGHT AND LICENSE','AUTHOR','AUTHORS') { if (defined $pod_raw{$part}) { push(@parts,$message_class->new({ header => $part, body => MooseX::App::Utils::format_text($pod_raw{$part}), })); } } return MooseX::App::Message::Envelope->new(@parts); } __PACKAGE__->meta->make_immutable; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Version/Meta/000755 000765 000024 00000000000 12514113027 022121 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Version/Meta/Class.pm000644 000765 000024 00000001035 12454262644 023540 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Version::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use MooseX::App::Plugin::Version::Command; around '_build_app_commands' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); $return->{version} ||= 'MooseX::App::Plugin::Version::Command'; return $return; }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Typo/Meta/000755 000765 000024 00000000000 12514113027 021427 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Typo/Meta/Class.pm000644 000765 000024 00000002005 12147322150 023030 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Typo::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use Text::WagnerFischer qw(distance); around 'command_candidates' => sub { my ($orig,$self,$command) = @_; my $lc_command = lc($command); my $commands = $self->app_commands; # Fuzzy match my @candidates; my $candidate_length = length($command); # Compare all commands to find matching candidates foreach my $command_name (keys %$commands) { my $candidate_substr = substr($command_name,0,$candidate_length+1); if ($lc_command eq $command_name) { return $command_name; } elsif ($lc_command eq $candidate_substr || distance($lc_command,$candidate_substr) <= 1) { push(@candidates,$command_name); } } return [ sort @candidates ]; }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Term/Meta/000755 000765 000024 00000000000 12514113027 021403 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Term/Meta/Attribute.pm000644 000765 000024 00000022364 12477373617 023740 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Term::Meta::Attribute; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; no if $] >= 5.018000, warnings => qw(experimental::smartmatch); use Term::ReadKey; has 'cmd_term' => ( is => 'ro', isa => 'Bool', default => sub {0}, ); has 'cmd_term_label' => ( is => 'ro', isa => 'Str', predicate => 'has_cmd_term_label', ); sub cmd_term_label_full { my ($self) = @_; my $label = $self->cmd_term_label_name; my @tags; if ($self->is_required) { push(@tags,'Required'); } else { push(@tags,'Optional'); } if ($self->has_type_constraint) { my $type_constraint = $self->type_constraint; if ($type_constraint->is_a_type_of('Bool')) { push(@tags,'Y/N'); } else { push(@tags,$self->cmd_type_constraint_description($type_constraint)); } } if (scalar @tags) { $label .= ' ('.join(', ',@tags).')'; } return $label; } sub cmd_term_label_name { my ($self) = @_; my $label; if ($self->has_cmd_term_label) { return $self->cmd_term_label; } elsif ($self->has_documentation) { return $self->documentation; } else { return $self->name; } } sub cmd_term_read { my ($self) = @_; if ($self->has_type_constraint && $self->type_constraint->is_a_type_of('Bool')) { return $self->cmd_term_read_bool(); } else { return $self->cmd_term_read_string(); } } sub cmd_term_read_string { my ($self) = @_; my $label = $self->cmd_term_label_full; my ($return,@history,$history_disable); binmode STDIN,':encoding(UTF-8)'; # Prefill history with enums if ($self->has_type_constraint && $self->type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) { push(@history,@{$self->type_constraint->values}); $history_disable = 1 } else { push(@history,""); } my $history_index = 0; my $history_add = sub { my $entry = shift; if (! $history_disable && defined $entry && $entry !~ m/^\s*$/ && ! ($entry ~~ \@history)) { push(@history,$entry); } }; ReadMode('cbreak'); # change input mode TRY_STRING: while (1) { print "\n" if defined $return && $return !~ /^\s*$/; $return = ''; if (defined $Term::ANSIColor::VERSION) { say Term::ANSIColor::color('white bold').$label.' :'.Term::ANSIColor::color('reset'); } else { say $label.": "; } 1 while defined ReadKey -1; # discard any previous input my $cursor = 0; KEY_STRING: while (1) { my $key = ReadKey 0; # read a single character my $length = length($return); given (ord($key)) { when (10) { # Enter print "\n"; my $error; if ($return =~ m/^\s*$/) { if ($self->is_required) { $error = 'Value is required'; } else { $return = undef; last TRY_STRING; } } else { $error = $self->cmd_type_constraint_check($return); } if ($error) { if (defined $Term::ANSIColor::VERSION) { say Term::ANSIColor::color('bright_red bold').$error.Term::ANSIColor::color('reset'); } else { say $error; } $history_add->($return); next TRY_STRING; } else { last TRY_STRING; } } when (27) { # Escape sequence my $escape; while (1) { # Read rest of escape sequence my $code = ReadKey -1; last unless defined $code; $escape .= $code; } if (defined $escape) { given ($escape) { when ('[D') { # Cursor left if ($cursor > 0) { print "\b"; $cursor--; } } when ($escape eq '[C') { # Cursor right if ($cursor < length($return)) { print substr $return,$cursor,1; $cursor++; } } when ($escape eq '[A') { # Cursor up $history_add->($return); print "\b" x $cursor; print " " x length($return); print "\b" x length($return); $history_index ++ if defined $history[$history_index] && $history[$history_index] eq $return; $history_index = 0 unless defined $history[$history_index]; $return = $history[$history_index]; $cursor = length($return); print $return; $history_index++; } when ($escape eq '[3~') { # Del if ($cursor != length($return)) { substr $return,$cursor,1,''; print substr $return,$cursor; print " ".(("\b") x (length($return) - $cursor + 1)); } } when ($escape eq 'OH') { # Pos 1 print (("\b") x $cursor); $cursor = 0; } when ($escape eq 'OF') { # End print substr $return,$cursor; $cursor = length($return); } #default { # print $escape; #} } } else { $history_add->($return); next TRY_STRING; } } when (127) { # Backspace if ($cursor == 0) { # Ignore first next KEY_STRING; } $cursor--; substr $return,$cursor,1,''; # string print "\b".substr $return,$cursor; # print print " ".(("\b") x (length($return) - $cursor + 1)); # cursor } default { # Character if ($_ <= 31) { # ignore controll chars next KEY_STRING; } substr $return,$cursor,0,$key; # string print substr $return,$cursor; # print $cursor++; print (("\b") x (length($return) - $cursor)); # cursor } } } } ReadMode 0; return $return; } sub cmd_term_read_bool { my ($self) = @_; my $label = $self->cmd_term_label_full; my $return; if (defined $Term::ANSIColor::VERSION) { say Term::ANSIColor::color('white bold').$label.' :'.Term::ANSIColor::color('reset'); } else { say $label.": "; } ReadMode 4; # change to raw input mode TRY: while (1) { 1 while defined ReadKey -1; # discard any previous input my $key = ReadKey 0; # read a single character if ($key =~ /^[yn]$/i) { say uc($key); $return = uc($key) eq 'Y' ? 1:0; last; } elsif ((ord($key) == 10 || ord($key) == 27) && ! $self->is_required) { last; } elsif (ord($key) == 3) { ReadMode 0; kill INT => $$; # Not sure ? } } ReadMode 0; return $return; } around 'cmd_tags_list' => sub { my $orig = shift; my ($self) = @_; my @tags = $self->$orig(); push(@tags,'Term') if $self->can('cmd_term') && $self->cmd_term; return @tags; }; { package Moose::Meta::Attribute::Custom::Trait::AppTerm; use strict; use warnings; sub register_implementation { return 'MooseX::App::Plugin::Term::Meta::Attribute' } } 1; MooseX-App-1.33/lib/MooseX/App/Plugin/Term/Meta/Class.pm000644 000765 000024 00000002712 12454262644 023025 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Term::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use IO::Interactive qw(is_interactive); around 'command_check_attributes' => sub { my ($orig,$self,$command_meta,$errors,$params) = @_; $command_meta ||= $self; if (scalar @{$errors} == 0 && is_interactive()) { my $prompt = 1; foreach my $attribute ($self->command_usage_attributes($command_meta,'all')) { if ($attribute->is_required && ! exists $params->{$attribute->name} && (! $attribute->can('cmd_term') || $attribute->cmd_term == 0 )) { $prompt = 0; } } if ($prompt) { foreach my $attribute ($self->command_usage_attributes($command_meta,'all')) { next unless $attribute->can('cmd_term') && $attribute->cmd_term; if (! defined $params->{$attribute->name}) { my $return = $attribute->cmd_term_read(); $params->{$attribute->name} = $return if defined $return; } } } } return $self->$orig($command_meta,$errors,$params); }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/MutexGroup/Meta/000755 000765 000024 00000000000 12514113027 022613 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/MutexGroup/Meta/Attribute.pm000644 000765 000024 00000001357 12500366465 025135 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::MutexGroup::Meta::Attribute; # ============================================================================ use Moose::Role; use namespace::autoclean; has 'mutexgroup' => ( is => 'ro', isa => 'Str', ); around 'cmd_tags_list' => sub { my $orig = shift; my ($self) = @_; my @tags = $self->$orig(); push(@tags,'MutexGroup') if $self->can('mutexgroup') && $self->mutexgroup; return @tags; }; { package Moose::Meta::Attribute::Custom::Trait::AppMutexGroup; use strict; use warnings; sub register_implementation { return 'MooseX::App::Plugin::MutexGroup::Meta::Attribute' } } 1; MooseX-App-1.33/lib/MooseX/App/Plugin/MutexGroup/Meta/Class.pm000644 000765 000024 00000003511 12500772622 024225 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::MutexGroup::Meta::Class; # ============================================================================ use Moose::Role; use namespace::autoclean; around 'command_check_attributes' => sub { my ( $orig, $self, $command_meta, $errors, $params ) = @_; $command_meta ||= $self; my %mutex_groups; foreach my $attribute ( $self->command_usage_attributes( $command_meta, 'all' ) ) { push @{ $mutex_groups{ $attribute->mutexgroup } }, $attribute if $attribute->can('mutexgroup') && defined $attribute->mutexgroup; } foreach my $options ( values %mutex_groups ) { my @initialized_options = grep { defined $params->{ $_->name } } @$options; unless ( scalar @initialized_options == 1 ) { my $error_msg; if (scalar @initialized_options == 0) { my $last = pop @$options; $error_msg = "Either ". join(",", map { $_->cmd_name_primary } @$options). " or ". $last->cmd_name_primary. " must be specified"; } else { my @list = map { $_->cmd_name_primary } @initialized_options; my $last = pop(@list); $error_msg = "Options ". join(",",@list). " and ". $last. " are mutally exclusive"; } push @$errors, $self->command_message( header => $error_msg, type => "error", ); } } return $self->$orig( $command_meta, $errors, $params ); }; 1; MooseX-App-1.33/lib/MooseX/App/Plugin/Man/Command.pm000644 000765 000024 00000002537 12454262644 022261 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Man::Command; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Command; use Pod::Perldoc; command_short_description q(Full manpage); has 'command' => ( is => 'ro', isa => 'Str', predicate => 'has_command', documentation => q[Command], traits => ['AppOption'], cmd_type => 'parameter', cmd_position => 1, ); sub man { my ($self,$app) = @_; my $meta = $app->meta; my $class; if ($self->has_command) { my $return = $meta->command_find($self->command); # Nothing found if (blessed $return && $return->isa('MooseX::App::Message::Block')) { return MooseX::App::Message::Envelope->new( $return, $meta->command_usage_command($self->meta), ); } $class = $meta->command_get($return); } else { $class = $meta->name; } Class::Load::load_class($class); my $filename = MooseX::App::Utils::package_to_filename($class); exec('perldoc',$filename); #return $MooseX::App::Null::NULL; } __PACKAGE__->meta->make_immutable; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Man/Meta/000755 000765 000024 00000000000 12514113027 021207 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Man/Meta/Class.pm000644 000765 000024 00000001015 12454262644 022624 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Man::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use MooseX::App::Plugin::Man::Command; around '_build_app_commands' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); $return->{man} ||= 'MooseX::App::Plugin::Man::Command'; return $return; }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Depends/Meta/000755 000765 000024 00000000000 12514113027 022056 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Depends/Meta/Attribute.pm000644 000765 000024 00000001406 12500772612 024366 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Depends::Meta::Attribute; # ============================================================================ use Moose::Role; use namespace::autoclean; has 'depends' => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, ); around 'cmd_tags_list' => sub { my $orig = shift; my ($self) = @_; my @tags = $self->$orig(); push(@tags,'Depends') if $self->can('depends') && $self->depends; return @tags; }; { package Moose::Meta::Attribute::Custom::Trait::AppDepends; use strict; use warnings; sub register_implementation { return 'MooseX::App::Plugin::Depends::Meta::Attribute' } } 1; MooseX-App-1.33/lib/MooseX/App/Plugin/Depends/Meta/Class.pm000644 000765 000024 00000002345 12501006073 023463 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Depends::Meta::Class; # ============================================================================ use Moose::Role; use namespace::autoclean; around 'command_check_attributes' => sub { my ($orig, $self, $command_meta, $errors, $params) = @_; $command_meta ||= $self; ATTR: foreach my $attribute ( $self->command_usage_attributes($command_meta, 'all') ) { next ATTR unless defined $params->{ $attribute->cmd_name_primary }; next ATTR unless $attribute->can('depends') && ref($attribute->depends) eq 'ARRAY' && scalar @{ $attribute->depends } > 0; OPT: foreach my $required_option ( @{ $attribute->depends } ) { next OPT if defined $params->{$required_option}; my $error_msg = "Option " . "'" . $attribute->cmd_name_primary . "'" . " requires '$required_option' to be defined"; push @$errors, $self->command_message( header => $error_msg, type => 'error', ); } } return $self->$orig($command_meta, $errors, $params); }; 1; MooseX-App-1.33/lib/MooseX/App/Plugin/ConfigHome/Meta/000755 000765 000024 00000000000 12514113027 022512 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/ConfigHome/Meta/Class.pm000644 000765 000024 00000001624 12147322150 024121 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::ConfigHome::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use File::HomeDir qw(); around 'proto_config' => sub { my $orig = shift; my ($self,$command_class,$result,$errors) = @_; unless (defined $result->{config}) { my $home_dir = Path::Class::Dir->new(File::HomeDir->my_home); my $data_dir = $home_dir->subdir('.'.$self->app_base); foreach my $extension (Config::Any->extensions) { my $check_file = $data_dir->file('config.'.$extension); if (-e $check_file) { $result->{config} = $check_file; last; } } } return $self->$orig($command_class,$result,$errors); }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Config/Meta/000755 000765 000024 00000000000 12514113027 021701 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Config/Meta/Class.pm000644 000765 000024 00000004275 12454262644 023331 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Config::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; around 'command_proto' => sub { my ($orig,$self,$metaclass) = @_; my ($result,$errors) = $self->$orig($metaclass); delete $result->{config} unless defined $result->{config}; return $self->proto_config($metaclass,$result,$errors); }; sub proto_config { my ($self,$metaclass,$result,$errors) = @_; # Check if we have a config return ($result,$errors) unless defined $result->{config}; # Read config my $config_file = Path::Class::File->new($result->{config}); unless (-e $config_file->stringify) { push(@{$errors}, $self->command_message( header => "Could not find config file '".$config_file->stringify."'", type => "error", ), ); return ($result,$errors); } my $config_file_name = $config_file->stringify; my $configs = Config::Any->load_files({ files => [ $config_file_name ], use_ext => 1, }); my $command_name = $self->command_class_to_command($metaclass->name); my ($config_data) = values %{$configs->[0]}; # Merge $config_data->{global} ||= {}; $config_data->{$command_name} ||= {}; # Set config data $result->{config} = $result->{config}; $result->{_config_data} = $config_data; # Lopp all attributes foreach my $attribute ($self->command_usage_attributes($metaclass,'all')) { my $attribute_name = $attribute->name; next if $attribute_name eq 'config' || $attribute_name eq 'help_flag'; $result->{$attribute_name} = $config_data->{global}{$attribute_name} if defined $config_data->{global}{$attribute_name}; $result->{$attribute_name} = $config_data->{$command_name}{$attribute_name} if defined $config_data->{$command_name}{$attribute_name}; } return ($result,$errors); }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/Color/Meta/000755 000765 000024 00000000000 12514113027 021552 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/Color/Meta/Class.pm000644 000765 000024 00000000627 12147322150 023163 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Color::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use MooseX::App::Message::BlockColor; around '_build_app_messageclass' => sub { return 'MooseX::App::Message::BlockColor' }; 1;MooseX-App-1.33/lib/MooseX/App/Plugin/BashCompletion/Command.pm000644 000765 000024 00000005066 12476647333 024463 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::BashCompletion::Command; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Command; command_short_description q(Bash completion automator); sub bash_completion { my ($self,$app) = @_; my %command_map; my $app_meta = $app->meta; my $commands = $app_meta->app_commands; my $command_list = join (' ', keys %{$commands}); my $package = __PACKAGE__; my $prefix = $app_meta->app_base; my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); $year += 1900; $mday = sprintf('%02i',$mday); $mon = sprintf('%02i',$mon+1); $prefix =~ tr/./_/; while (my ($command,$command_class) = each %$commands) { Class::Load::load_class($command_class); #my @parameters = $app_meta->command_usage_attributes($command_class->meta,'parameter'); my @options = $app_meta->command_usage_attributes($command_class->meta,[qw(option proto)]); $command_map{$command} = { #parameters => [ map { $_->is_required } @parameters ], options => [ map { $_->cmd_usage_name } @options ], }; } my $syntax = '';; $syntax .= <<"EOT"; #!/bin/bash # Built with $package on $year/$mon/$mday ${prefix}_COMMANDS='help $command_list' _${prefix}_macc_help() { if [ \$COMP_CWORD = 2 ]; then _${prefix}_compreply "\$${prefix}_COMMANDS" else COMPREPLY=() fi } EOT while (my ($command, $data) = each %command_map) { $syntax .= "_${prefix}_macc_${command}() {\n _${prefix}_compreply \""; #$syntax .= join(" ", @{$data->{parameters}}); $syntax .= join(" ", @{$data->{options}}); $syntax .= "\"\n}\n\n"; } $syntax .= <<"EOT"; _${prefix}_compreply() { COMPREPLY=(\$(compgen -W "\$1" -- \${COMP_WORDS[COMP_CWORD]})) } _${prefix}_macc() { case \$COMP_CWORD in 0) ;; 1) _${prefix}_compreply "\$${prefix}_COMMANDS" ;; *) eval _${prefix}_macc_\${COMP_WORDS[1]} esac } EOT $syntax .= "complete -o default -F _${prefix}_macc ". $app_meta->app_base. "\n"; return MooseX::App::Message::Envelope->new( MooseX::App::Message::Block->new({ body => $syntax }) ); } __PACKAGE__->meta->make_immutable; 1; MooseX-App-1.33/lib/MooseX/App/Plugin/BashCompletion/Meta/000755 000765 000024 00000000000 12514113027 023403 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Plugin/BashCompletion/Meta/Class.pm000644 000765 000024 00000001072 12454262644 025023 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::BashCompletion::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; use MooseX::App::Plugin::BashCompletion::Command; around '_build_app_commands' => sub { my $orig = shift; my $self = shift; my $return = $self->$orig(@_); $return->{bash_completion} ||= 'MooseX::App::Plugin::BashCompletion::Command'; return $return; }; 1;MooseX-App-1.33/lib/MooseX/App/ParsedArgv/Element.pm000644 000765 000024 00000006427 12465625117 022363 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::ParsedArgv::Element; # ============================================================================ use 5.010; use utf8; use Moose; no if $] >= 5.018000, warnings => qw(experimental::smartmatch); has 'key' => ( is => 'ro', isa => 'Str', required => 1, ); has 'value' => ( is => 'ro', isa => 'ArrayRef[Str]', traits => ['Array'], default => sub { [] }, handles => { add_value => 'push', has_values => 'count', get_value => 'get', raw_values => 'elements', } ); has 'consumed' => ( is => 'rw', isa => 'Bool', default => sub {0}, ); has 'type' => ( is => 'ro', isa => 'Str', required => 1, ); has 'raw' => ( is => 'ro', isa => 'Str', predicate => 'has_raw', ); has 'occurence' => ( is => 'ro', isa => 'Int', default => sub { 1 }, traits => ['Counter'], handles => { inc_occurence => 'inc', } ); sub original { my ($self) = @_; if ($self->has_raw) { return $self->raw; } else { return $self->key; } } sub consume { my ($self,$attribute) = @_; Moose->throw_error('Element '.$self->type.' '.$self->key.' is already consumed') if $self->consumed; $self->consumed(1); return $self; } sub full_value { my ($self) = @_; # Fill up empty values if ($self->has_values < $self->occurence) { return [ $self->raw_values, (undef) x ($self->occurence - $self->has_values) ]; } else { return $self->value; } } #sub set_value { # my ($self,$value) = @_; # # unless (scalar @{$self->value}) { # $self->add_value($value); # } else { # if (! defined $self->value->[-1]) { # $self->value->[-1] = $value; # } else { # $self->add_value($value); # } # } #} sub serialize { my ($self) = @_; given ($self->type) { when ('extra') { return $self->key } when ('parameter') { return $self->key } when ('option') { my $key = (length $self->key == 1 ? '-':'--').$self->key; return join(' ',map { $key.' '.$_ } @{$self->value}); } } return; } __PACKAGE__->meta->make_immutable(); 1; =pod =head1 NAME MooseX::App::ParsedArgv::Element - Parsed element from @ARGV =head1 DESCRIPTION Every instance of this class represents a logical entity from @ARGV =head1 METHODS =head2 key Parameter value or option key =head2 value Arrayref of values =head2 raw Raw value as supplied by the user =head2 type Type of element. Can be 'option', 'parameter' or 'extra' =head2 occurence Number of occurences in @ARGV =head2 consumed Flag that indicates if element was already consumed =head2 consume Consumes element. Dies if element is already consumed =head2 serialize Serializes element (Does not procuce output that is identical with original @ARGV) =cutMooseX-App-1.33/lib/MooseX/App/Meta/Role/000755 000765 000024 00000000000 12514113027 020137 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Meta/Role/Attribute/000755 000765 000024 00000000000 12514113027 022102 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Meta/Role/Class/000755 000765 000024 00000000000 12514113027 021204 5ustar00marosstaff000000 000000 MooseX-App-1.33/lib/MooseX/App/Meta/Role/Class/Base.pm000644 000765 000024 00000072100 12476647502 022435 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Base; # ============================================================================ use utf8; use 5.010; use List::Util qw(max); use namespace::autoclean; use Moose::Role; use MooseX::App::Utils; use Path::Class; use Module::Pluggable::Object; no if $] >= 5.018000, warnings => qw(experimental::smartmatch); has 'app_messageclass' => ( is => 'rw', isa => 'ClassName', lazy => 1, builder => '_build_app_messageclass', ); has 'app_namespace' => ( is => 'rw', isa => 'MooseX::App::Types::List', coerce => 1, lazy => 1, builder => '_build_app_namespace', ); has 'app_base' => ( is => 'rw', isa => 'Str', default => sub { Path::Class::File->new($0)->basename }, ); has 'app_strict' => ( is => 'rw', isa => 'Bool', default => sub {0}, ); has 'app_fuzzy' => ( is => 'rw', isa => 'Bool', default => sub {1}, ); has 'app_command_name' => ( is => 'rw', isa => 'CodeRef', default => sub { \&MooseX::App::Utils::class_to_command }, ); has 'app_prefer_commandline' => ( is => 'rw', isa => 'Bool', default => sub {0}, ); has 'app_commands' => ( is => 'rw', isa => 'HashRef[Str]', traits => ['Hash'], handles => { command_register => 'set', command_get => 'get', }, lazy => 1, builder => '_build_app_commands', ); sub _build_app_messageclass { my ($self) = @_; return 'MooseX::App::Message::Block' } sub _build_app_namespace { my ($self) = @_; return [ $self->name ]; } sub _build_app_commands { my ($self) = @_; my @list; foreach my $namespace ( @{ $self->app_namespace } ) { push(@list,$self->command_scan_namespace($namespace)); } return { @list }; } sub command_scan_namespace { my ($self,$namespace) = @_; my $mpo = Module::Pluggable::Object->new( search_path => [ $namespace ], ); my $commandsub = $self->app_command_name; my %return; foreach my $command_class ($mpo->plugins) { my $command_class_name = substr($command_class,length($namespace)+2); next if $command_class_name =~ m/::/; $command_class_name =~ s/^\Q$namespace\E:://; $command_class_name =~ s/^.+::([^:]+)$/$1/; my $command = $commandsub->($command_class_name,$command_class); $return{$command} = $command_class; } return %return; } sub command_args { my ($self,$metaclass) = @_; $metaclass ||= $self; my $parsed_argv = MooseX::App::ParsedArgv->instance; # Process options my @attributes_option = $self->command_usage_attributes($metaclass,'option'); my ($return,$errors) = $self->command_parse_options(\@attributes_option); my %raw_error; foreach my $option ($parsed_argv->available('option')) { my $key = $option->key; my $raw = $option->original; my $message; next if defined $raw_error{$raw}; if (length $key == 1 && $raw =~ m/^-(\w+)$/) { POSSIBLE_ATTRIBUTES: foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { foreach my $name ($attribute->cmd_name_possible) { # TODO fuzzy match if ($name eq $1) { $raw_error{$raw} = 1; $message = "Did you mean '--$name'?"; last POSSIBLE_ATTRIBUTES; } } } } my $error; if (defined $message) { $error = $self->command_message( header => "Unknown option '".$raw."'", # LOCALIZE body => $message, type => "error", ); } else { $error = $self->command_message( header => "Unknown option '".$option->key."'", # LOCALIZE type => "error", ); } unshift(@{$errors},$error); } # Process params my @attributes_parameter = $self->command_usage_attributes($metaclass,'parameter'); foreach my $attribute (@attributes_parameter) { my $element = $parsed_argv->consume('parameter'); last unless defined $element; my ($parameter_value,$parameter_errors) = $self->command_process_attribute($attribute,$element->key); push(@{$errors},@{$parameter_errors}); $return->{$attribute->name} = $parameter_value; } # Handle all unconsumed parameters and options if ($self->app_strict || $metaclass->command_strict) { foreach my $parameter ($parsed_argv->available('parameter')) { unshift(@{$errors}, $self->command_message( header => "Unknown parameter '".$parameter->key."'", # LOCALIZE type => "error", ) ); } } foreach my $attribute ($self->command_usage_attributes($metaclass,'all')) { next unless $attribute->can('has_cmd_env') && $attribute->has_cmd_env; my $cmd_env = $attribute->cmd_env; if (exists $ENV{$cmd_env} && ! defined $return->{$attribute->name}) { my $value = $ENV{$cmd_env}; if ($attribute->has_type_constraint) { my $type_constraint = $attribute->type_constraint; if ($attribute->should_coerce && $type_constraint->has_coercion) { my $coercion = $type_constraint->coercion; $value = $coercion->coerce($value) // $value; } } $return->{$attribute->name} = $value; my $error = $attribute->cmd_type_constraint_check($value); if ($error) { push(@{$errors}, $self->command_message( header => "Invalid environment value for '".$cmd_env."'", # LOCALIZE type => "error", body => $error, ) ); } } } return ($return,$errors); } sub command_proto { my ($self,$metaclass) = @_; $metaclass ||= $self; my @attributes; foreach my $attribute ($self->command_usage_attributes($metaclass,'proto')) { next unless $attribute->does('AppOption') && $attribute->has_cmd_type; push(@attributes,$attribute); } return $self->command_parse_options(\@attributes); } sub command_parse_options { my ($self,$attributes) = @_; # Build attribute lookup hash my %option_to_attribute; foreach my $attribute (@{$attributes}) { foreach my $name ($attribute->cmd_name_possible) { if (defined $option_to_attribute{$name} && $option_to_attribute{$name} != $attribute) { Moose->throw_error('Command line option conflict: '.$name); } $option_to_attribute{$name} = $attribute; } } my $match = {}; my $return = {}; my @errors; # Get ARGV my $parsed_argv = MooseX::App::ParsedArgv->instance; # Loop all exact matches foreach my $option ($parsed_argv->available('option')) { if (my $attribute = $option_to_attribute{$option->key}) { $match->{$attribute->name} = $option->full_value; $option->consume($attribute); } } # Process fuzzy matches if ($self->app_fuzzy) { # Loop all options (sorted by length) foreach my $option (sort { length($b->key) <=> length($a->key) } $parsed_argv->available('option')) { # No fuzzy matching for one-letter flags my $option_length = length($option->key); next if $option_length == 1; my ($match_attributes) = []; # Try to match attributes foreach my $name (keys %option_to_attribute) { next if ($option_length >= length($name)); my $name_short = lc(substr($name,0,$option_length)); # Partial match if (lc($option->key) eq $name_short) { my $attribute = $option_to_attribute{$name}; unless (grep { $attribute == $_ } @{$match_attributes}) { push(@{$match_attributes},$attribute); } } } given (scalar @{$match_attributes}) { # No match when(0) {} # One match when(1) { my $attribute = $match_attributes->[0]; $option->consume(); $match->{$attribute->name} ||= []; push(@{$match->{$attribute->name}},@{$option->full_value}); } # Multiple matches default { $option->consume(); push(@errors, $self->command_message( header => "Ambiguous option '".$option->key."'", # LOCALIZE type => "error", body => "Could be\n".MooseX::App::Utils::format_list( # LOCALIZE map { [ $_ ] } sort map { $_->cmd_name_primary } @{$match_attributes} ), ) ); } } } } # Check all attributes foreach my $attribute (@{$attributes}) { next unless exists $match->{$attribute->name}; my ($value,$errors) = $self->command_process_attribute($attribute,$match->{$attribute->name}); push(@errors,@{$errors}); $return->{$attribute->name} = $value; } return ($return,\@errors); } sub command_process_attribute { my ($self,$attribute,$raw) = @_; $raw = [$raw] unless ref($raw) eq 'ARRAY'; my @errors; my $value; # Attribute with split if ($attribute->has_cmd_split) { my @raw_unfolded; foreach (@{$raw}) { push(@raw_unfolded,split($attribute->cmd_split,$_)); } $raw = \@raw_unfolded; } # Attribute with counter if ($attribute->cmd_count) { $raw = [ scalar(@$raw) ]; } # Attribute with type constraint if ($attribute->has_type_constraint) { my $type_constraint = $attribute->type_constraint; if ($type_constraint->is_a_type_of('ArrayRef')) { $value = $raw; } elsif ($type_constraint->is_a_type_of('HashRef')) { $value = {}; foreach my $element (@{$raw}) { if ($element =~ m/^([^=]+)=(.+?)$/) { $value->{$1} ||= $2; } else { push(@errors, $self->command_message( header => "Invalid value for '".$attribute->cmd_name_primary."'", # LOCALIZE type => "error", body => "Value must be supplied as 'key=value' (not '$element')", # LOCALIZE ) ); } } } elsif ($type_constraint->is_a_type_of('Bool')) { $value = 1; # TODO or 0 if no! # if ($self->has_default # && ! $self->is_default_a_coderef # && $self->default == 1) { } elsif ($type_constraint->is_a_type_of('Int')) { $value = $raw->[-1]; } else { $value = $raw->[-1]; } unless(defined $value) { push(@errors, $self->command_message( header => "Missing value for '".$attribute->cmd_name_primary."'", # LOCALIZE type => "error", ) ); } else { if ($attribute->should_coerce && $type_constraint->has_coercion) { my $coercion = $type_constraint->coercion; $value = $coercion->coerce($value) // $value; } my $error = $attribute->cmd_type_constraint_check($value); if (defined $error) { push(@errors, $self->command_message( header => "Invalid value for '".$attribute->cmd_name_primary."'", # LOCALIZE type => "error", body => $error, ) ); } } } else { $value = $raw->[-1]; } return ($value,\@errors); } sub command_candidates { my ($self,$command) = @_; my $lc_command = lc($command); my $commands = $self->app_commands; my @candidates; my $candidate_length = length($command); # Compare all commands to find matching candidates foreach my $command_name (keys %$commands) { if ($command_name eq $lc_command) { return $command_name; } elsif ($lc_command eq substr($command_name,0,$candidate_length)) { push(@candidates,$command_name); } } return [ sort @candidates ]; } sub command_find { my ($self,$command) = @_; my $lc_command = lc($command); my $commands = $self->app_commands; # Exact match if (defined $commands->{$lc_command}) { return $lc_command; } else { my $candidate = $self->command_candidates($command); if (ref $candidate eq '') { return $candidate; } else { given (scalar @{$candidate}) { when (0) { return $self->command_message( header => "Unknown command '$command'", # LOCALIZE type => "error", ); } when (1) { if ($self->app_fuzzy) { return $candidate->[0]; } else { return $self->command_message( header => "Unknown command '$command'", # LOCALIZE type => "error", body => "Did you mean '".$candidate->[0]."'?", # LOCALIZE ); } } default { return $self->command_message( header => "Ambiguous command '$command'", # LOCALIZE type => "error", body => "Which command did you mean?\n". # LOCALIZE MooseX::App::Utils::format_list(map { [ $_ ] } sort @{$candidate}), ); } } } } } sub command_parser_hints { my ($self,$metaclass) = @_; $metaclass ||= $self; my %hints; my %names; foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { foreach my $name ($attribute->cmd_name_possible) { $names{$name} = { name => $attribute->name, novalue => $attribute->cmd_has_value }; $hints{$name} = $names{$name}; } } if ($self->app_fuzzy) { my $length = max(map { length($_) } keys %names) // 0; foreach my $l (reverse(2..$length)) { my %tmp; foreach my $name (keys %names) { next if length($name) < $l; my $short_name = substr($name,0,$l); next if defined $hints{$short_name}; $tmp{$short_name} ||= []; next if defined $tmp{$short_name}->[0] && $tmp{$short_name}->[0]->{name} eq $names{$name}->{name}; push(@{$tmp{$short_name}},$names{$name}) } foreach my $short_name (keys %tmp) { next if scalar @{$tmp{$short_name}} > 1; $hints{$short_name} = $tmp{$short_name}->[0]; } } } my @return; foreach my $name (keys %hints) { next if $hints{$name}->{novalue}; push(@return,$name); } return \@return; } sub command_message { my ($self,@args) = @_; my $messageclass = $self->app_messageclass; Class::Load::load_class($messageclass); return $messageclass->new(@args); } sub command_check_attributes { my ($self,$command_meta,$errors,$params) = @_; $command_meta ||= $self; # Check required values foreach my $attribute ($self->command_usage_attributes($command_meta,[qw(option proto parameter)])) { if ($attribute->is_required && ! exists $params->{$attribute->name} && ! $attribute->has_default) { push(@{$errors}, $self->command_message( header => "Required ".($attribute->cmd_type eq 'parameter' ? 'parameter':'option')." '".$attribute->cmd_name_primary."' missing", # LOCALIZE type => "error", ) ); } } return $errors; } sub command_usage_attributes { my ($self,$metaclass,$types) = @_; $metaclass ||= $self; $types ||= [qw(option proto)]; my @return; foreach my $attribute ($metaclass->get_all_attributes) { next unless $attribute->does('AppOption') && $attribute->has_cmd_type; next unless $types eq 'all' || $attribute->cmd_type ~~ $types; push(@return,$attribute); } return (sort { $a->cmd_position <=> $b->cmd_position } @return); } sub command_usage_options { my ($self,$metaclass,$headline) = @_; $headline ||= 'options:'; # LOCALIZE $metaclass ||= $self; my @options; foreach my $attribute ($self->command_usage_attributes($metaclass,[qw(option proto)])) { push(@options,[ $attribute->cmd_usage_name(), $attribute->cmd_usage_description() ]); } @options = sort { $a->[0] cmp $b->[0] } @options; return unless scalar @options > 0; return $self->command_message( header => $headline, body => MooseX::App::Utils::format_list(@options), ); } sub command_usage_parameters { my ($self,$metaclass,$headline) = @_; $headline ||= 'parameter:'; # LOCALIZE $metaclass ||= $self; my @parameters; foreach my $attribute ( sort { $a->cmd_position <=> $b->cmd_position } $self->command_usage_attributes($metaclass,'parameter') ) { push(@parameters,[ $attribute->cmd_usage_name(), $attribute->cmd_usage_description() ]); } return unless scalar @parameters > 0; return $self->command_message( header => $headline, body => MooseX::App::Utils::format_list(@parameters), ); } sub command_usage_header { my ($self,$command_meta_class) = @_; my $caller = $self->app_base; my ($command_name,$usage); if ($command_meta_class) { $command_name = $self->command_class_to_command($command_meta_class->name); } else { $command_name = ''; } $command_meta_class ||= $self; if ($command_meta_class->can('command_usage') && $command_meta_class->command_usage_predicate) { $usage = MooseX::App::Utils::format_text($command_meta_class->command_usage); } unless (defined $usage) { # LOCALIZE $usage = "$caller $command_name "; my @parameter= $self->command_usage_attributes($command_meta_class,'parameter'); foreach my $attribute (@parameter) { if ($attribute->is_required) { $usage .= "<".$attribute->cmd_usage_name.'> '; } else { $usage .= '['.$attribute->cmd_usage_name.'] '; } } $usage .= "[long options...] $caller help $caller $command_name --help"; $usage = MooseX::App::Utils::format_text($usage); } return $self->command_message( header => 'usage:', # LOCALIZE body => $usage, ); } sub command_usage_description { my ($self,$command_meta_class) = @_; $command_meta_class ||= $self; if ($command_meta_class->can('command_long_description') && $command_meta_class->command_long_description_predicate) { return $self->command_message( header => 'description:', # LOCALIZE body => MooseX::App::Utils::format_text($command_meta_class->command_long_description), ); } elsif ($command_meta_class->can('command_short_description') && $command_meta_class->command_short_description_predicate) { return $self->command_message( header => 'short description:', # LOCALIZE body => MooseX::App::Utils::format_text($command_meta_class->command_short_description), ); } return; } sub command_class_to_command { my ($self,$command_class) = @_; my $commands = $self->app_commands; foreach my $element (keys %$commands) { if ($command_class eq $commands->{$element}) { return $element; } } return; } sub command_usage_command { my ($self,$command_meta_class) = @_; $command_meta_class ||= $self; my $command_class = $command_meta_class->name; my $command_name = $self->command_class_to_command($command_class); my @usage; push(@usage,$self->command_usage_header($command_meta_class)); push(@usage,$self->command_usage_description($command_meta_class)); push(@usage,$self->command_usage_parameters($command_meta_class,'parameters:')); # LOCALIZE push(@usage,$self->command_usage_options($command_meta_class,'options:')); # LOCALIZE return @usage; } sub command_usage_global { my ($self) = @_; my @commands; push(@commands,['help','Prints this usage information']); # LOCALIZE my $commands = $self->app_commands; while (my ($command,$class) = each %$commands) { Class::Load::load_class($class); my $command_description; $command_description = $class->meta->command_short_description if $class->meta->can('command_short_description'); $command_description ||= ''; push(@commands,[$command,$command_description]); } @commands = sort { $a->[0] cmp $b->[0] } @commands; my @usage; push(@usage,$self->command_usage_header()); my $description = $self->command_usage_description($self); push(@usage,$description) if $description; push(@usage,$self->command_usage_parameters($self,'global parameters:')); # LOCALIZE push(@usage,$self->command_usage_options($self,'global options:')); # LOCALIZE push(@usage, $self->command_message( header => 'available commands:', # LOCALIZE body => MooseX::App::Utils::format_list(@commands), ) ); return @usage; } 1; __END__ =pod =encoding utf8 =head1 NAME MooseX::App::Meta::Role::Class::Base - Meta class role for application base class =head1 DESCRIPTION This meta class role will automatically be applied to the application base class. This documentation is only of interest if you intend to write plugins for MooseX-App. =head1 ACCESSORS =head2 app_messageclass Message class for generating error messages. Defaults to MooseX::App::Message::Block. The default can be overwritten by altering the C<_build_app_messageclass> method. Defaults to MooseX::App::Message::Block =head2 app_namespace Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed. =head2 app_base Usually MooseX::App will take the name of the calling wrapper script to construct the program name in various help messages. This name can be changed via the app_base accessor. Defaults to the base name of $0 =head2 app_fuzzy Boolean flag that controlls if command names and attributes should be matched exactly or fuzzy. Defaults to true. =head2 app_command_name Coderef attribute that controlls how package names are translated to command names and attributes. Defaults to &MooseX::App::Utils::class_to_command =head2 app_commands Hashref with command to command class map. =head2 app_strict Boolean flag that controls if an application with superfluous/unknown positional parameters should terminate with an error message or not. If disabled all extra parameters will be copied to the L command class attribute. =head2 app_prefer_commandline By default, arguments passed to new_with_command and new_with_options have a higher priority than the command line options. This boolean flag will give the command line an higher priority. =head1 METHODS =head2 command_register $self->command_register($command_moniker,$command_class); Registers an additional command =head2 command_get my $command_class = $self->command_register($command_moniker); Returns a command class for the given command moniker =head2 command_class_to_command my $command_moniker = $meta->command_class_to_command($command_class); Returns the command moniker for the given command class. =head2 command_message my $message = $meta->command_message( header => $header, type => 'error', body => $message ); Generates a message object (using the class from L) =head2 command_usage_attributes my @attributes = $meta->command_usage_attributes($metaclass); Returns a list of attributes/command options for the given meta class. =head2 command_usage_command my @messages = $meta->command_usage_command($command_metaclass); Returns a list of messages containing the documentation for a given command meta class. =head2 command_usage_description my $message = $meta->command_usage_description($command_metaclass); Returns a messages with the basic command description. =head2 command_usage_global my @messages = $meta->command_usage_global(); Returns a list of messages containing the documentation for the application. =head2 command_usage_header my $message = $meta->command_usage_header(); my $message = $meta->command_usage_header($command_meta_class); Returns a message containing the basic usage documentation =head2 command_find my @commands = $meta->command_find($user_command_input); Returns a list of command names matching the user input =head2 command_candidates my $commands = $meta->command_candidates($user_command_input); Returns either a single command or an arrayref of possibly matching commands. =head2 command_proto my ($result,$errors) = $meta->command_proto($command_meta_class); Returns all parsed options (as hashref) and erros (as arrayref) for the proto command. Is a wrapper around L. =head2 command_args my ($options,$errors) = $self->command_args($command_meta_class); Returns all parsed options (as hashref) and erros (as arrayref) for the main command. Is a wrapper around L. =head2 command_parse_options my ($options,$errors) = $self->command_parse_options(\@attribute_metaclasses); Tries to parse the selected attributes from @ARGV. =head2 command_scan_namespace my %namespaces = $self->command_scan_namespace($namespace); Scans a namespace for command classes. Returns a hash with command names as keys and package names as values. =head2 command_process_attribute my @attributes = $self->command_process_attributes($metaclass,[qw(option proto)]); my @attributes = $self->command_process_attributes($metaclass,'parameter'); Returns a list of all attributes with the given type =head2 command_usage_options my $usage = $self->command_usage_options($metaclass,$headline); Returns the options usage as a message object =head2 command_usage_parameters my $usage = $self->command_usage_parameters($metaclass,$headline); Returns the positional parameters usage as a message object =head2 command_check_attributes $errors = $self->command_check_attributes($command_meta,$errors,$params) Checks all attributes. Returns/alters the $errors arrayref =head2 command_parser_hints $self->command_parser_hints($self,$metaclass) Generates parser hints as required by L =cut MooseX-App-1.33/lib/MooseX/App/Meta/Role/Class/Command.pm000644 000765 000024 00000000372 12454262644 023137 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Command; # ============================================================================ use utf8; use 5.010; use Moose::Role; 1;MooseX-App-1.33/lib/MooseX/App/Meta/Role/Class/Documentation.pm000644 000765 000024 00000010717 12454262644 024376 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Documentation; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; use Pod::Elemental; use Pod::Elemental::Selectors qw(); use Pod::Elemental::Transformer::Pod5; use Pod::Elemental::Transformer::Nester; has 'command_short_description' => ( is => 'rw', isa => 'Maybe[Str]', lazy => 1, builder => '_build_command_short_description', ); has 'command_long_description' => ( is => 'rw', isa => 'Maybe[Str]', lazy => 1, builder => '_build_command_long_description', ); has 'command_usage' => ( is => 'rw', isa => 'Maybe[Str]', lazy => 1, builder => '_build_command_usage', ); has 'command_strict' => ( is => 'rw', isa => 'Bool', default => sub {0}, ); sub command_short_description_predicate { my ($self) = @_; return $self->_command_pod_predicate('command_short_description'); } sub _build_command_short_description { my ($self) = @_; my %pod = $self->_build_command_pod(); return $pod{'command_short_description'} if defined $pod{'command_short_description'}; return; } sub command_long_description_predicate { my ($self) = @_; return $self->_command_pod_predicate('command_long_description'); } sub _build_command_long_description { my ($self) = @_; my %pod = $self->_build_command_pod(); return $pod{'command_long_description'} if defined $pod{'command_long_description'}; return; } sub command_usage_predicate { my ($self) = @_; return $self->_command_pod_predicate('command_usage'); } sub _build_command_usage { my ($self) = @_; my %pod = $self->_build_command_pod(); return $pod{'command_usage'} if defined $pod{'command_usage'}; return; } sub _command_pod_predicate { my ($self,$field) = @_; my $attribute = $self->meta->find_attribute_by_name($field); unless ($attribute->has_value($self)) { $self->_build_command_pod($field); } my $value = $attribute->get_value($self); return (defined $value && $value ? 1:0); } sub _build_command_pod { my ($self) = @_; my %pod_raw = MooseX::App::Utils::parse_pod($self->name); my %pod = ( command_usage => ($pod_raw{SYNOPSIS} || $pod_raw{USAGE}), command_long_description => ($pod_raw{DESCRIPTION} || $pod_raw{OVERVIEW}), command_short_description => ($pod_raw{NAME} || $pod_raw{ABSTRACT}), ); while (my ($key,$value) = each %pod) { my $meta_attribute = $self->meta->find_attribute_by_name($key); next unless defined $meta_attribute; next if $meta_attribute->has_value($self); $meta_attribute->set_raw_value($self,$value); } return %pod; } #{ # package Moose::Meta::Class::Custom::Trait::AppCommand; # sub register_implementation { return 'MooseX::App::Meta::Role::Class::Documentation' } #} 1; __END__ =pod =encoding utf8 =head1 NAME MooseX::App::Meta::Role::Class::Documentation - Meta class role for command classes =head1 DESCRIPTION This meta class role will automatically be applied to all command classes. This documentation is only of interest if you intend to write plugins for MooseX-App. =head1 ACCESSORS =head2 command_short_description Read/set the short command description. Will be extracted from the Pod NAME or ABSTRACT section if not set. Alternative this will be taken from the DistZilla ABSTRACT tag. =head2 command_long_description Read/set the long command description. Will be extracted from the Pod DESCRIPTION or OVERVIEW section if not set. =head2 command_usage Read/set the long command usage. Will be extracted from the Pod SYNOPSIS or USAGE section if not set. If these Pod sections are not defined the usage will be autogenerated. =head2 command_strict Read/set the strict command flag. If strict is enabled the command will terminate with an error message if superfluous/unknown positional parameters are supplied. If disabled all extra parameters will be copied to the L attribute. The app_strict function in the app classes allows one to set this option globally. =head1 METHODS =head2 _build_command_pod Parses the Pod from the command class. =cutMooseX-App-1.33/lib/MooseX/App/Meta/Role/Class/Simple.pm000644 000765 000024 00000002217 12454262644 023012 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Simple; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; around 'command_usage_header' => sub { my ($orig,$self) = @_; my $caller = $self->app_base; my $usage; if ($self->can('command_usage') && $self->command_usage_predicate) { $usage = MooseX::App::Utils::format_text($self->command_usage); } unless ($usage) { my $command = $caller; my @parameter= $self->command_usage_attributes($self,'parameter'); foreach my $attribute (@parameter) { if ($attribute->is_required) { $command .= " <".$attribute->cmd_usage_name.'>'; } else { $command .= ' ['.$attribute->cmd_usage_name.']'; } } $usage = MooseX::App::Utils::format_text("$command [long options...] $caller --help") } return $self->command_message( header => 'usage:', body => $usage); # LOCALIZE }; 1;MooseX-App-1.33/lib/MooseX/App/Meta/Role/Attribute/Option.pm000644 000765 000024 00000026145 12465625117 023735 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Attribute::Option; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; has 'cmd_type' => ( is => 'rw', isa => 'MooseX::App::Types::CmdTypes', predicate => 'has_cmd_type', ); has 'cmd_tags' => ( is => 'rw', isa => 'ArrayRef[Str]', predicate => 'has_cmd_tags', ); has 'cmd_flag' => ( is => 'rw', isa => 'Str', predicate => 'has_cmd_flag', ); has 'cmd_aliases' => ( is => 'rw', isa => 'MooseX::App::Types::List', predicate => 'has_cmd_aliases', coerce => 1, ); has 'cmd_split' => ( is => 'rw', isa => Moose::Util::TypeConstraints::union([qw(Str RegexpRef)]), predicate => 'has_cmd_split', ); has 'cmd_count' => ( is => 'rw', isa => 'Bool', default => sub { 0 }, ); has 'cmd_env' => ( is => 'rw', isa => 'MooseX::App::Types::Env', predicate => 'has_cmd_env', ); has 'cmd_position' => ( is => 'rw', isa => 'Int', default => sub { 0 }, ); my $GLOBAL_COUNTER = 1; around 'new' => sub { my $orig = shift; my $class = shift; my $self = $class->$orig(@_); if ($self->has_cmd_type) { if ($self->cmd_position == 0) { $GLOBAL_COUNTER++; $self->cmd_position($GLOBAL_COUNTER); } } return $self; }; sub cmd_has_value { my ($self) = @_; if ($self->has_type_constraint && $self->type_constraint->is_a_type_of('Bool')) { # Bool and defaults to true #if ($self->has_default # && ! $self->is_default_a_coderef # && $self->default == 1) { # return 0; ## Bool and is required #} elsif (! $self->has_default # && $self->is_required) { # return 0; #} # Ordinary bool return 0; } if ($self->cmd_count) { return 0; } return 1; } sub cmd_type_constraint_description { my ($self,$type_constraint,$singular) = @_; $type_constraint //= $self->type_constraint; $singular //= 1; if ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) { return 'one of these values: '.join(', ',@{$type_constraint->values}); } elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { my $from = $type_constraint->parameterized_from; if ($from->is_a_type_of('ArrayRef')) { return $self->cmd_type_constraint_description($type_constraint->type_parameter); } elsif ($from->is_a_type_of('HashRef')) { return 'key-value pairs of '.$self->cmd_type_constraint_description($type_constraint->type_parameter,0); } # TODO union } elsif ($type_constraint->equals('Int')) { return $singular ? 'an integer':'integers'; # LOCALIZE } elsif ($type_constraint->equals('Num')) { return $singular ? 'a number':'numbers'; # LOCALIZE } elsif ($type_constraint->equals('Str')) { return $singular ? 'a string':'strings'; } elsif ($type_constraint->equals('HashRef')) { return 'key-value pairs'; # LOCALIZE } if ($type_constraint->has_parent) { return $self->cmd_type_constraint_description($type_constraint->parent); } return; } sub cmd_type_constraint_check { my ($self,$value) = @_; return unless ($self->has_type_constraint); my $type_constraint = $self->type_constraint; # Check type constraints unless ($type_constraint->check($value)) { if (ref($value) eq 'ARRAY') { $value = join(', ',@$value); } elsif (ref($value) eq 'HASH') { $value = join(', ',map { $_.'='.$value->{$_} } keys %$value) } # We have a custom message if ($type_constraint->has_message) { return $type_constraint->get_message($value); # No message } else { my $message_human = $self->cmd_type_constraint_description($type_constraint); if (defined $message_human) { return "Value must be ". $message_human ." (not '$value')"; } else { return $type_constraint->get_message($value); } } } return; } sub cmd_usage_description { my ($self) = @_; my $description = ($self->has_documentation) ? $self->documentation : ''; my @tags = $self->cmd_tags_list(); if (scalar @tags) { $description .= ' ' if $description; $description .= '['.join('; ',@tags).']'; } return $description } sub cmd_usage_name { my ($self) = @_; if ($self->cmd_type eq 'parameter') { return $self->cmd_name_primary; } else { return join(' ', map { (length($_) == 1) ? "-$_":"--$_" } $self->cmd_name_possible); } } sub cmd_name_primary { my ($self) = @_; if ($self->has_cmd_flag) { return $self->cmd_flag; } else { return $self->name; } } sub cmd_name_possible { my ($self) = @_; my @names = ($self->cmd_name_primary); if ($self->has_cmd_aliases) { push(@names, @{$self->cmd_aliases}); } return @names; } sub cmd_tags_list { my ($self) = @_; my @tags; if ($self->is_required && ! $self->is_lazy_build && ! $self->has_default) { push(@tags,'Required') } if ($self->has_default && ! $self->is_default_a_coderef) { if ($self->has_type_constraint && $self->type_constraint->is_a_type_of('Bool')) { # if ($attribute->default) { # push(@tags,'Default:Enabled'); # } else { # push(@tags,'Default:Disabled'); # } } else { push(@tags,'Default:"'.$self->default.'"'); } } if ($self->has_type_constraint) { my $type_constraint = $self->type_constraint; if ($type_constraint->is_subtype_of('ArrayRef')) { if ($self->has_cmd_split) { my $split = $self->cmd_split; if (ref($split) eq 'Regexp') { $split = "$split"; $split =~ s/^\(\?\^\w*:(.+)\)$/$1/x; } push(@tags,'Multiple','Split by "'.$split.'"'); } else { push(@tags,'Multiple'); } } elsif ($type_constraint->is_a_type_of('HashRef')) { push(@tags,'Key-Value'); } unless ($self->should_coerce) { if ($type_constraint->is_a_type_of('Int')) { push(@tags,'Integer'); } elsif ($type_constraint->is_a_type_of('Num')) { push(@tags ,'Number'); } elsif ($type_constraint->is_a_type_of('Bool')) { push(@tags ,'Flag'); } elsif ($type_constraint->isa('Moose::Meta::TypeConstraint::Enum')) { push(@tags ,'Possible values: '.join(', ',@{$type_constraint->values})); } } } if ($self->can('has_cmd_env') && $self->has_cmd_env) { push(@tags,'Env: '.$self->cmd_env) } if ($self->can('cmd_tags') && $self->can('cmd_tags') && $self->has_cmd_tags) { push(@tags,@{$self->cmd_tags}); } return @tags; } { package Moose::Meta::Attribute::Custom::Trait::AppOption; use strict; use warnings; sub register_implementation { return 'MooseX::App::Meta::Role::Attribute::Option' } } 1; =pod =encoding utf8 =head1 NAME MooseX::App::Meta::Role::Attribute::Option - Meta attribute role for options =head1 DESCRIPTION This meta attribute role will automatically be applied to all attributes that should be used as options. =head1 ACCESSORS In your app and command classes you can use the following attributes in option or parameter definitions. option 'myoption' => ( is => 'rw', isa => 'ArrayRef[Str]', documentation => 'My special option', cmd_flag => 'myopt', cmd_aliases => [qw(mopt localopt)], cmd_tags => [qw(Important!)], cmd_env => 'MY_OPTION', cmd_position => 1, cmd_split => qr/,/, ); =head2 cmd_flag Use this name instead of the attribute name as the option name =head2 cmd_type Option to mark if this attribute should be used as an option or parameter value. Allowed values are: =over =item * option - Command line option =item * proto - Command line option that should be processed prior to other options (eg. a config-file option that sets other attribues) Usually only used for plugin developmemt =item * parameter - Positional parameter command line value =back =head2 cmd_env Environment variable name (only uppercase letters, numeric and underscores allowed). If variable was not specified otherwise the value will be taken from %ENV. =head2 cmd_aliases Arrayref of alternative option names =head2 cmd_tags Extra option tags displayed in the usage information (in brackets) =head2 cmd_position Override the order of the parameters in the usage message. =head2 cmd_split Splits multiple values at the given separator string or regular expression. Only works in conjunction with an 'ArrayRef[*]' type constraint (isa). ie. '--myattr value1,value2' with cmd_split set to ',' would produce an arrayref with to elements. =head2 cmd_count Similar to the Getopt::Long '+' modifier, cmd_count turns the attribute into a counter. Every occurence of the attribute in @ARGV (without any value) would increment the resulting value by one =head1 METHODS These methods are only of interest to plugin authors. =head2 cmd_name_possible my @names = $attribute->cmd_name_possible(); Returns a list of all possible option names. =head2 cmd_name_primary my $name = $attribute->cmd_name_primary(); Returns the primary option name =head2 cmd_usage_name my $name = $attribute->cmd_usage_name(); Returns the name as used by the usage text =head2 cmd_usage_description my $name = $attribute->cmd_usage_description(); Returns the description as used by the usage text =head2 cmd_tags_list my @tags = $attribute->cmd_tags_list(); Returns a list of tags =head2 cmd_has_value my $has_value = $attribute->cmd_has_value(); Indicates if an commandline attribute has a value. Usually attributes with a boolean type constraint or counters don't have values. =over =item * undef: Does not have a boolean type constraint =item * true: Has a boolean type constraint =item * false: Has a boolean type constraint, and a true default value =back =head2 cmd_type_constraint_check $attribute->cmd_type_constraint_check($value) Checks the type constraint. Returns an error message if the check fails =head2 cmd_type_constraint_description $attribute->cmd_type_constraint_description($type_constraint,$singular) Creates a description of the selected type constraint. =cut MooseX-App-1.33/lib/MooseX/App/Message/Block.pm000644 000765 000024 00000002573 12454262644 021350 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Message::Block; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Utils; use overload '""' => "stringify"; has 'header' => ( is => 'ro', isa => 'MooseX::App::Types::MessageString', predicate => 'has_header', ); has 'type' => ( is => 'ro', isa => 'Str', default => sub {'default'}, ); has 'body' => ( is => 'ro', isa => 'MooseX::App::Types::MessageString', predicate => 'has_body', ); sub stringify { my ($self) = @_; my $message = ''; $message .= $self->header."\n" if $self->has_header; $message .= $self->body."\n\n" if $self->has_body; return $message; } __PACKAGE__->meta->make_immutable; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Message::Block - Message block =head1 DESCRIPTION A simple message block with a header and body =head1 METHODS =head2 header Read/set a header string =head2 has_header Check if a header is set =head2 body Read/set a body string =head2 has_body Check if a body is set =head2 type Read/set an arbitrary block type. Defaults to 'default' =head2 stringify Stringify a message blockMooseX-App-1.33/lib/MooseX/App/Message/BlockColor.pm000644 000765 000024 00000002673 12454262644 022350 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Message::BlockColor; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; extends qw(MooseX::App::Message::Block); no if $] >= 5.018000, warnings => qw(experimental::smartmatch); use Term::ANSIColor qw(); use IO::Interactive qw(is_interactive); BEGIN { if ($^O eq 'MSWin32') { Class::Load::try_load_class('Win32::Console::ANSI'); } }; sub stringify { my ($self) = @_; my $header_color; my $body_color; given ($self->type) { when('error') { $header_color = 'bright_red bold'; $body_color = 'bright_red'; } when('default') { $header_color = 'bold'; } default { $header_color = $_; } } my $message = ''; if ($self->has_header) { $message .= $self->_wrap_color($header_color,$self->header)."\n"; } if ($self->has_body) { $message .= $self->_wrap_color($body_color,$self->body)."\n\n"; } return $message; } sub _wrap_color { my ($self,$color,$string) = @_; return $string unless is_interactive() && defined $color; return Term::ANSIColor::color($color) .$string .Term::ANSIColor::color('reset'); } __PACKAGE__->meta->make_immutable; 1;MooseX-App-1.33/lib/MooseX/App/Message/Envelope.pm000644 000765 000024 00000007713 12503334741 022065 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Message::Envelope; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Message::Block; use overload '""' => "overload"; has 'blocks' => ( is => 'ro', isa => 'ArrayRef[MooseX::App::Message::Block]', traits => ['Array'], handles => { add_block => 'push', list_blocks => 'elements', }, ); has 'exitcode' => ( is => 'ro', isa => 'Int', predicate => 'has_exitcode', ); around 'BUILDARGS' => sub { my $orig = shift; my $self = shift; my @args = @_; my $params; if (scalar @args == 1 && ref($args[0]) eq 'HASH') { $params = $args[0]; } else { $params = { blocks => [], }; my @blocks; foreach my $element (@args) { next unless defined $element; if (blessed $element && $element->isa('MooseX::App::Message::Block')) { push(@{$params->{blocks}},$element); } elsif ($element =~ /^\d+$/ && $element <= 255 && $element >= 0) { $params->{exitcode} = $element; } else { push(@{$params->{blocks}},MooseX::App::Message::Block->new( header => $element, )); } } } return $self->$orig($params); }; sub overload { my ($self) = @_; if ($self->has_exitcode) { my $exitcode = $self->exitcode; if ($exitcode == 0) { print $self->stringify; } else { print STDERR $self->stringify; } exit $exitcode; } else { print $self->stringify; } return; } sub stringify { my ($self) = @_; my $message = ''; foreach my $block ($self->list_blocks) { $message .= $block->stringify; } return $message; } sub AUTOLOAD { my ($self) = @_; $self->overload; return $MooseX::App::Null::NULL; } { package MooseX::App::Null; use strict; use warnings; use overload 'bool' => sub { 0 }, '""' => sub { '' }, '0+' => sub { 0 }; our $NULL = bless {}, __PACKAGE__; sub AUTOLOAD { return $NULL } } __PACKAGE__->meta->make_immutable; 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Message::Envelope - Message presented to the user =head1 DESCRIPTION Whenever MooseX::App needs to pass a message to the user, it does so by generating a MooseX::App::Message::Envelope object. The object usually contains one or more blocks (L) and can be easily stringified. Usually a MooseX::App::Message::Envelope object is generated and returned by the L if there is an error or if the user requests help. To avoid useless object type checks when working with this method, MooseX::App::Message::Envelope follows the Null-class pattern. So you can do this, no matter if new_with_command fails or not: MyApp->new_with_command->some_method->only_called_if_successful; If =head1 METHODS =head2 stringify Stringifies the messages =head2 overload This method is called whenever the object is stringified via overload. In this case it prints the message on either STDERR or STDOUT, and exits the process with the given exitcode (if any). =head2 add_block Adds a new message block. Param must be a L =head2 list_blocks Returns a list on message blocks. =head2 blocks Message block accessor. =head2 exitcode Exitcode accessor. =head2 has_exitcode Check if exitcode is set. =head2 OVERLOAD Stringification of this object is overloaded. =head2 AUTOLOAD You can call any method on the message class. MooseX-App-1.33/inc/Module/000755 000765 000024 00000000000 12514113027 015646 5ustar00marosstaff000000 000000 MooseX-App-1.33/inc/Module/Install/000755 000765 000024 00000000000 12514113027 017254 5ustar00marosstaff000000 000000 MooseX-App-1.33/inc/Module/Install.pm000644 000765 000024 00000030111 12514112766 017617 0ustar00marosstaff000000 000000 #line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } use 5.006; use strict 'vars'; use Cwd (); use File::Find (); use File::Path (); use vars qw{$VERSION $MAIN}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '1.10'; # Storage for the pseudo-singleton $MAIN = undef; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; #------------------------------------------------------------- # all of the following checks should be included in import(), # to allow "eval 'require Module::Install; 1' to test # installation of Module::Install. (RT #51267) #------------------------------------------------------------- # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # This reportedly fixes a rare Win32 UTC file time issue, but # as this is a non-cross-platform XS module not in the core, # we shouldn't really depend on it. See RT #24194 for detail. # (Also, this module only supports Perl 5.6 and above). eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006; # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 ) { my $s = (stat($0))[9]; # If the modification time is only slightly in the future, # sleep briefly to remove the problem. my $a = $s - time; if ( $a > 0 and $a < 5 ) { sleep 5 } # Too far in the future, throw an error. my $t = time; if ( $s > $t ) { die <<"END_DIE" } Your installer $0 has a modification time in the future ($s > $t). This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE } # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE #------------------------------------------------------------- # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); #------------------------------------------------------------- unless ( -f $self->{file} ) { foreach my $key (keys %INC) { delete $INC{$key} if $key =~ /Module\/Install/; } local $^W; require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } local $^W; *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{'inc/Module/Install.pm'}; delete $INC{'Module/Install.pm'}; # Save to the singleton $MAIN = $self; return 1; } sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::getcwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::getcwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; } unless ($$sym =~ s/([^:]+)$//) { # XXX: it looks like we can't retrieve the missing function # via $$sym (usually $main::AUTOLOAD) in this case. # I'm still wondering if we should slurp Makefile.PL to # get some context or not ... my ($package, $file, $line) = caller; die <<"EOT"; Unknown function is found at $file line $line. Execution of $file aborted due to runtime errors. If you're a contributor to a project, you may need to install some Module::Install extensions from CPAN (or other repository). If you're a user of a module, please contact the author. EOT } my $method = $1; if ( uc($method) eq $method ) { # Do nothing return; } elsif ( $method =~ /^_/ and $self->can($method) ) { # Dispatch to the root M:I class return $self->$method(@_); } # Dispatch to the appropriate plugin unshift @_, ( $self, $1 ); goto &{$self->can('call')}; }; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { @exts = $self->{admin}->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { local $^W; *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; delete $INC{'FindBin.pm'}; { # to suppress the redefine warning local $SIG{__WARN__} = sub {}; require FindBin; } # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; my $should_reload = 0; unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; $should_reload = 1; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { local $^W; require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = $should_reload ? delete $INC{$file} : $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split /\n/, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Common Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _read { local *FH; open( FH, '<', $_[0] ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_NEW sub _read { local *FH; open( FH, "< $_[0]" ) or die "open($_[0]): $!"; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_OLD sub _readperl { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; return $string; } sub _readpod { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; return $string if $_[0] =~ /\.pod\z/; $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; $string =~ s/^\n+//s; return $string; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _write { local *FH; open( FH, '>', $_[0] ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_NEW sub _write { local *FH; open( FH, "> $_[0]" ) or die "open($_[0]): $!"; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { # Normalise multipart versions $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; } $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } sub _cmp { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS sub _CLASS { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s ) ? $_[0] : undef; } 1; __END__ #line 485 MooseX-App-1.33/inc/Module/Install/AuthorRequires.pm000644 000765 000024 00000001131 12514112766 022601 0ustar00marosstaff000000 000000 #line 1 use strict; use warnings; package Module::Install::AuthorRequires; use base 'Module::Install::Base'; # cargo cult BEGIN { our $VERSION = '0.02'; our $ISCORE = 1; } sub author_requires { my $self = shift; return $self->{values}->{author_requires} unless @_; my @added; while (@_) { my $mod = shift or last; my $version = shift || 0; push @added, [$mod => $version]; } push @{ $self->{values}->{author_requires} }, @added; $self->admin->author_requires(@added); return map { @$_ } @added; } 1; __END__ #line 92 MooseX-App-1.33/inc/Module/Install/Base.pm000644 000765 000024 00000002147 12514112766 020501 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.10'; } # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } #line 42 sub new { my $class = shift; unless ( defined &{"${class}::call"} ) { *{"${class}::call"} = sub { shift->_top->call(@_) }; } unless ( defined &{"${class}::load"} ) { *{"${class}::load"} = sub { shift->_top->load(@_) }; } bless { @_ }, $class; } #line 61 sub AUTOLOAD { local $@; my $func = eval { shift->_top->autoload } or return; goto &$func; } #line 75 sub _top { $_[0]->{_top}; } #line 90 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 106 sub is_admin { ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); } sub DESTROY {} package Module::Install::Base::FakeAdmin; use vars qw{$VERSION}; BEGIN { $VERSION = $Module::Install::Base::VERSION; } my $fake; sub new { $fake ||= bless(\@_, $_[0]); } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 159 MooseX-App-1.33/inc/Module/Install/Can.pm000644 000765 000024 00000006157 12514112766 020335 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Can; use strict; use Config (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # Check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; require File::Spec; my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # Can our C compiler environment build XS files sub can_xs { my $self = shift; # Ensure we have the CBuilder module $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); # Do we have the configure_requires checker? local $@; eval "require ExtUtils::CBuilder;"; if ( $@ ) { # They don't obey configure_requires, so it is # someone old and delicate. Try to avoid hurting # them by falling back to an older simpler test. return $self->can_cc(); } # Do we have a working C compiler my $builder = ExtUtils::CBuilder->new( quiet => 1, ); unless ( $builder->have_compiler ) { # No working C compiler return 0; } # Write a C file representative of what XS becomes require File::Temp; my ( $FH, $tmpfile ) = File::Temp::tempfile( "compilexs-XXXXX", SUFFIX => '.c', ); binmode $FH; print $FH <<'END_C'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int main(int argc, char **argv) { return 0; } int boot_sanexs() { return 1; } END_C close $FH; # Can the C compiler access the same headers XS does my @libs = (); my $object = undef; eval { local $^W = 0; $object = $builder->compile( source => $tmpfile, ); @libs = $builder->link( objects => $object, module_name => 'sanexs', ); }; my $result = $@ ? 0 : 1; # Clean up all the build files foreach ( $tmpfile, $object, @libs ) { next unless defined $_; 1 while unlink; } return $result; } # Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 236 MooseX-App-1.33/inc/Module/Install/Fetch.pm000644 000765 000024 00000004653 12514112767 020665 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; __END__ #line 109 MooseX-App-1.33/inc/Module/Install/Makefile.pm000644 000765 000024 00000027437 12514112766 021355 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Makefile; use strict 'vars'; use ExtUtils::MakeMaker (); use Module::Install::Base (); use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing or non-interactive session, always use defaults if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } # Store a cleaned up version of the MakeMaker version, # since we need to behave differently in a variety of # ways based on the MM version. my $makemaker = eval $ExtUtils::MakeMaker::VERSION; # If we are passed a param, do a "newer than" comparison. # Otherwise, just return the MakeMaker version. sub makemaker { ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0 } # Ripped from ExtUtils::MakeMaker 6.56, and slightly modified # as we only need to know here whether the attribute is an array # or a hash or something else (which may or may not be appendable). my %makemaker_argtype = ( C => 'ARRAY', CONFIG => 'ARRAY', # CONFIGURE => 'CODE', # ignore DIR => 'ARRAY', DL_FUNCS => 'HASH', DL_VARS => 'ARRAY', EXCLUDE_EXT => 'ARRAY', EXE_FILES => 'ARRAY', FUNCLIST => 'ARRAY', H => 'ARRAY', IMPORTS => 'HASH', INCLUDE_EXT => 'ARRAY', LIBS => 'ARRAY', # ignore '' MAN1PODS => 'HASH', MAN3PODS => 'HASH', META_ADD => 'HASH', META_MERGE => 'HASH', PL_FILES => 'HASH', PM => 'HASH', PMLIBDIRS => 'ARRAY', PMLIBPARENTDIRS => 'ARRAY', PREREQ_PM => 'HASH', CONFIGURE_REQUIRES => 'HASH', SKIP => 'ARRAY', TYPEMAPS => 'ARRAY', XS => 'HASH', # VERSION => ['version',''], # ignore # _KEEP_AFTER_FLUSH => '', clean => 'HASH', depend => 'HASH', dist => 'HASH', dynamic_lib=> 'HASH', linkext => 'HASH', macro => 'HASH', postamble => 'HASH', realclean => 'HASH', test => 'HASH', tool_autosplit => 'HASH', # special cases where you can use makemaker_append CCFLAGS => 'APPENDABLE', DEFINE => 'APPENDABLE', INC => 'APPENDABLE', LDDLFLAGS => 'APPENDABLE', LDFROM => 'APPENDABLE', ); sub makemaker_args { my ($self, %new_args) = @_; my $args = ( $self->{makemaker_args} ||= {} ); foreach my $key (keys %new_args) { if ($makemaker_argtype{$key}) { if ($makemaker_argtype{$key} eq 'ARRAY') { $args->{$key} = [] unless defined $args->{$key}; unless (ref $args->{$key} eq 'ARRAY') { $args->{$key} = [$args->{$key}] } push @{$args->{$key}}, ref $new_args{$key} eq 'ARRAY' ? @{$new_args{$key}} : $new_args{$key}; } elsif ($makemaker_argtype{$key} eq 'HASH') { $args->{$key} = {} unless defined $args->{$key}; foreach my $skey (keys %{ $new_args{$key} }) { $args->{$key}{$skey} = $new_args{$key}{$skey}; } } elsif ($makemaker_argtype{$key} eq 'APPENDABLE') { $self->makemaker_append($key => $new_args{$key}); } } else { if (defined $args->{$key}) { warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n}; } $args->{$key} = $new_args{$key}; } } return $args; } # For mm args that take multiple space-separated args, # append an argument to the current list. sub makemaker_append { my $self = shift; my $name = shift; my $args = $self->makemaker_args; $args->{$name} = defined $args->{$name} ? join( ' ', $args->{$name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } sub _wanted_t { } sub tests_recursive { my $self = shift; my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } my %tests = map { $_ => 1 } split / /, ($self->tests || ''); require File::Find; File::Find::find( sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 }, $dir ); $self->tests( join ' ', sort keys %tests ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Check the current Perl version my $perl_version = $self->perl_version; if ( $perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } # Make sure we have a new enough MakeMaker require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { # This previous attempted to inherit the version of # ExtUtils::MakeMaker in use by the module author, but this # was found to be untenable as some authors build releases # using future dev versions of EU:MM that nobody else has. # Instead, #toolchain suggests we use 6.59 which is the most # stable version on CPAN at time of writing and is, to quote # ribasushi, "not terminally fucked, > and tested enough". # TODO: We will now need to maintain this over time to push # the version up as new versions are released. $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{NAME} =~ s/-/::/g; $args->{VERSION} = $self->version or die <<'EOT'; ERROR: Can't determine distribution version. Please specify it explicitly via 'version' in Makefile.PL, or set a valid $VERSION in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; $args->{test} = { TESTS => (join ' ', grep {!$seen{$_}++} @tests), }; } elsif ( $Module::Install::ExtraTests::use_extratests ) { # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness. # So, just ignore our xt tests here. } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) { $args->{test} = { TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ), }; } if ( $] >= 5.005 ) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = join ', ', @{$self->author || []}; } if ( $self->makemaker(6.10) ) { $args->{NO_META} = 1; #$args->{NO_MYMETA} = 1; } if ( $self->makemaker(6.17) and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } if ( $self->makemaker(6.31) and $self->license ) { $args->{LICENSE} = $self->license; } my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # Merge both kinds of requires into BUILD_REQUIRES my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); %$build_prereq = ( %$build_prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->configure_requires, $self->build_requires) ); # Remove any reference to perl, BUILD_REQUIRES doesn't support it delete $args->{BUILD_REQUIRES}->{perl}; # Delete bundled dists from prereq_pm, add it to Makefile DIR my $subdirs = ($args->{DIR} || []); if ($self->bundles) { my %processed; foreach my $bundle (@{ $self->bundles }) { my ($mod_name, $dist_dir) = @$bundle; delete $prereq->{$mod_name}; $dist_dir = File::Basename::basename($dist_dir); # dir for building this module if (not exists $processed{$dist_dir}) { if (-d $dist_dir) { # List as sub-directory to be processed by make push @$subdirs, $dist_dir; } # Else do nothing: the module is already present on the system $processed{$dist_dir} = undef; } } } unless ( $self->makemaker('6.55_03') ) { %$prereq = (%$prereq,%$build_prereq); delete $args->{BUILD_REQUIRES}; } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; if ( $self->makemaker(6.48) ) { $args->{MIN_PERL_VERSION} = $perl_version; } } if ($self->installdirs) { warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS}; $args->{INSTALLDIRS} = $self->installdirs; } my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_} ) } keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if ( my $preop = $self->admin->preop($user_preop) ) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; eval { flock MAKEFILE, LOCK_EX }; my $makefile = do { local $/; }; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; seek MAKEFILE, 0, SEEK_SET; truncate MAKEFILE, 0; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 544 MooseX-App-1.33/inc/Module/Install/Metadata.pm000644 000765 000024 00000047322 12514112766 021353 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } my @boolean_keys = qw{ sign }; my @scalar_keys = qw{ name module_name abstract version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; my @array_keys = qw{ keywords author }; *authors = \&author; sub Meta { shift } sub Meta_BooleanKeys { @boolean_keys } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } sub Meta_ArrayKeys { @array_keys } foreach my $key ( @boolean_keys ) { *$key = sub { my $self = shift; if ( defined wantarray and not @_ ) { return $self->{values}->{$key}; } $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); return $self; }; } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} = shift; return $self; }; } foreach my $key ( @array_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} ||= []; push @{$self->{values}->{$key}}, @_; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}->{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}->{resources} }; } return $self->{values}->{resources}->{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { *$key = sub { my $self = shift; return $self->{values}->{$key} unless @_; my @added; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @added, [ $module, $version ]; } push @{ $self->{values}->{$key} }, @added; return map {@$_} @added; }; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}->{resources} ||= []; push @{ $self->{values}->{resources} }, [ $name, $value ]; } $self->{values}->{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { my $self = shift; my $value = @_ ? shift : 1; if ( $self->{values}->{dynamic_config} ) { # Once dynamic we never change to static, for safety return 0; } $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } # Convenience command sub static_config { shift->dynamic_config(0); } sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Normalize the version $version = $self->_perl_version($version); # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}->{perl_version} = $version; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } $self->{values}{all_from} = $file; # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless @{$self->author || []}; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}->{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}->{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}->{features} ? @{ $self->{values}->{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; return $self->{values}->{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); # for version integrity check $self->makemaker_args( VERSION_FROM => $file ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) [\s|;]* /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub _extract_perl_version { if ( $_[0] =~ m/ ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; return $perl_version; } else { return; } } sub perl_version_from { my $self = shift; my $perl_version=_extract_perl_version(Module::Install::_read($_[0])); if ($perl_version) { $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; # XXX: ugly but should work anyway... if (eval "require Pod::Escapes; 1") { # Pod::Escapes has a mapping table. # It's in core of perl >= 5.9.3, and should be installed # as one of the Pod::Simple's prereqs, which is a prereq # of Pod::Text 3.x (see also below). $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $Pod::Escapes::Name2character_number{$1} ? chr($Pod::Escapes::Name2character_number{$1}) : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) { # Pod::Text < 3.0 has yet another mapping table, # though the table name of 2.x and 1.x are different. # (1.x is in core of Perl < 5.6, 2.x is in core of # Perl < 5.9.3) my $mapping = ($Pod::Text::VERSION < 2) ? \%Pod::Text::HTML_Escapes : \%Pod::Text::ESCAPES; $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $mapping->{$1} ? $mapping->{$1} : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } else { $author =~ s{E}{<}g; $author =~ s{E}{>}g; } $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } #Stolen from M::B my %license_urls = ( open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ## from Software-License - should we be using S-L instead ? # duplicates commeted out, see hack above ^^ # open_source => 'http://www.gnu.org/licenses/agpl-3.0.txt', # apache => 'http://www.apache.org/licenses/LICENSE-1.1', apache => 'http://www.apache.org/licenses/LICENSE-2.0.txt', artistic => 'http://www.perlfoundation.org/artistic_license_1_0', artistic_2 => 'http://www.perlfoundation.org/artistic_license_2_0', bsd => 'http://opensource.org/licenses/BSD-3-Clause', # unrestricted => 'http://creativecommons.org/publicdomain/zero/1.0/', # open_source => 'http://www.freebsd.org/copyright/freebsd-license.html', # open_source => 'http://www.gnu.org/licenses/fdl-1.2.txt', # open_source => 'http://www.gnu.org/licenses/fdl-1.3.txt', # gpl => 'http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt', # gpl => 'http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt', gpl => 'http://www.gnu.org/licenses/gpl-3.0.txt', # lgpl => 'http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt', lgpl => 'http://www.gnu.org/licenses/lgpl-3.0.txt', mit => 'http://www.opensource.org/licenses/mit-license.php', # mozilla => 'http://www.mozilla.org/MPL/MPL-1.0.txt', # mozilla => 'http://www.mozilla.org/MPL/MPL-1.1.txt', mozilla => 'http://www.mozilla.org/MPL/2.0/index.txt', # restrictive => '', # open_source => 'http://www.openssl.org/source/license.html', perl => 'http://dev.perl.org/licenses/', # open_source => 'http://www.opensource.org/licenses/postgresql', # open_source => 'http://trolltech.com/products/qt/licenses/licensing/qpl', # unrestricted => 'http://h71000.www7.hp.com/doc/83final/BA554_90007/apcs02.html', # open_source => 'http://www.openoffice.org/licenses/sissl_license.html', # open_source => 'http://www.zlib.net/zlib_license.html', ); sub license { my $self = shift; return $self->{values}->{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $license = __extract_license($license) || lc $license; $self->{values}->{license} = $license; # Automatically fill in license URLs if ( $license_urls{$license} ) { $self->resources( license => $license_urls{$license} ); } return 1; } sub _extract_license { my $pod = shift; my $matched; return __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /xms ) || __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /xms ); } sub __extract_license { my $license_text = shift or return; my @phrases = ( '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1, '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1, # the following are relied on by the test system even if they are wrong :( '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'LGPL' => 'lgpl', 1, 'MIT' => 'mit', 1, ## from Software-License 'The GNU Affero General Public License, Version 3, November 2007' => 'open_source', 1, 'The Apache Software License, Version 1.1' => 'apache', 1, 'The Apache License, Version 2.0, January 2004' => 'apache', 1, 'The Artistic License 1.0' => 'artistic', 1, 'The Artistic License 2.0 (GPL Compatible)' => 'artistic_2', 1, 'The (three-clause) BSD License' => 'bsd', 1, 'CC0 License' => 'unrestricted', 1, 'The (two-clause) FreeBSD License' => 'open_source', 1, 'GNU Free Documentation License v1.2' => 'open_source', 1, 'GNU Free Documentation License v1.3' => 'open_source', 1, 'The GNU General Public License, Version 1, February 1989' => 'gpl', 1, 'The GNU General Public License, Version 2, June 1991' => 'gpl', 1, 'The GNU General Public License, Version 3, June 2007' => 'gpl', 1, 'The GNU Lesser General Public License, Version 2.1, February 1999' => 'lgpl', 1, 'The GNU Lesser General Public License, Version 3, June 2007' => 'lgpl', 1, 'The MIT (X11) License' => 'mit', 1, 'The Mozilla Public License 1.0' => 'mozilla', 1, 'The Mozilla Public License 1.1' => 'mozilla', 1, 'Mozilla Public License Version 2.0' => 'mozilla', 1, '"No License" License' => 'restrictive', 1, 'OpenSSL License' => 'open_source', 1, 'the same terms as the perl 5 programming language system itself' => 'perl', 1, 'The PostgreSQL License' => 'open_source', 1, 'The Q Public License, Version 1.0' => 'open_source', 1, 'Original SSLeay License' => 'unrestricted', 1, 'Sun Internet Standards Source License (SISSL)' => 'open_source', 1, 'The zlib License' => 'open_source', 1, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s#\s+#\\s+#gs; if ( $license_text =~ /\b$pattern\b/i ) { return $license; } } return ''; } sub license_from { my $self = shift; if (my $license=_extract_license(Module::Install::_read($_[0]))) { $self->license($license); } else { warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } } sub _extract_bugtracker { my @links = $_[0] =~ m#L<( https?\Q://rt.cpan.org/\E[^>]+| https?\Q://github.com/\E[\w_]+/[\w_]+/issues| https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @links=keys %links; return @links; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = _extract_bugtracker($content); unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than one bugtracker link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->requires( $module => $version ); } } sub test_requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->test_requires( $module => $version ); } } # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). # Also, convert double-part versions (eg, 5.8) sub _perl_version { my $v = $_[-1]; $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; $v =~ s/(\.\d\d\d)000$/$1/; $v =~ s/_.+$//; if ( ref($v) ) { # Numify $v = $v + 0; } return $v; } sub add_metadata { my $self = shift; my %hash = @_; for my $key (keys %hash) { warn "add_metadata: $key is not prefixed with 'x_'.\n" . "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/; $self->{values}->{$key} = $hash{$key}; } } ###################################################################### # MYMETA Support sub WriteMyMeta { die "WriteMyMeta has been deprecated"; } sub write_mymeta_yaml { my $self = shift; # We need YAML::Tiny to write the MYMETA.yml file unless ( eval { require YAML::Tiny; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.yml\n"; YAML::Tiny::DumpFile('MYMETA.yml', $meta); } sub write_mymeta_json { my $self = shift; # We need JSON to write the MYMETA.json file unless ( eval { require JSON; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.json\n"; Module::Install::_write( 'MYMETA.json', JSON->new->pretty(1)->canonical->encode($meta), ); } sub _write_mymeta_data { my $self = shift; # If there's no existing META.yml there is nothing we can do return undef unless -f 'META.yml'; # We need Parse::CPAN::Meta to load the file unless ( eval { require Parse::CPAN::Meta; 1; } ) { return undef; } # Merge the perl version into the dependencies my $val = $self->Meta->{values}; my $perl = delete $val->{perl_version}; if ( $perl ) { $val->{requires} ||= []; my $requires = $val->{requires}; # Canonize to three-dot version after Perl 5.6 if ( $perl >= 5.006 ) { $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e } unshift @$requires, [ perl => $perl ]; } # Load the advisory META.yml file my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; # Overwrite the non-configure dependency hashes delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; if ( exists $val->{requires} ) { $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; } if ( exists $val->{build_requires} ) { $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; } return $meta; } 1; __END__ #line 766 MooseX-App-1.33/inc/Module/Install/ReadmeFromPod.pm000644 000765 000024 00000006311 12514112766 022310 0ustar00marosstaff000000 000000 #line 1 package Module::Install::ReadmeFromPod; use 5.006; use strict; use warnings; use base qw(Module::Install::Base); use vars qw($VERSION); $VERSION = '0.22'; sub readme_from { my $self = shift; return unless $self->is_admin; # Input file my $in_file = shift || $self->_all_from or die "Can't determine file to make readme_from"; # Get optional arguments my ($clean, $format, $out_file, $options); my $args = shift; if ( ref $args ) { # Arguments are in a hashref if ( ref($args) ne 'HASH' ) { die "Expected a hashref but got a ".ref($args)."\n"; } else { $clean = $args->{'clean'}; $format = $args->{'format'}; $out_file = $args->{'output_file'}; $options = $args->{'options'}; } } else { # Arguments are in a list $clean = $args; $format = shift; $out_file = shift; $options = \@_; } # Default values; $clean ||= 0; $format ||= 'txt'; # Generate README print "readme_from $in_file to $format\n"; if ($format =~ m/te?xt/) { $out_file = $self->_readme_txt($in_file, $out_file, $options); } elsif ($format =~ m/html?/) { $out_file = $self->_readme_htm($in_file, $out_file, $options); } elsif ($format eq 'man') { $out_file = $self->_readme_man($in_file, $out_file, $options); } elsif ($format eq 'pdf') { $out_file = $self->_readme_pdf($in_file, $out_file, $options); } if ($clean) { $self->clean_files($out_file); } return 1; } sub _readme_txt { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README'; require Pod::Text; my $parser = Pod::Text->new( @$options ); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; $parser->output_fh( *$out_fh ); $parser->parse_file( $in_file ); close $out_fh; return $out_file; } sub _readme_htm { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.htm'; require Pod::Html; Pod::Html::pod2html( "--infile=$in_file", "--outfile=$out_file", @$options, ); # Remove temporary files if needed for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') { if (-e $file) { unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n"; } } return $out_file; } sub _readme_man { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.1'; require Pod::Man; my $parser = Pod::Man->new( @$options ); $parser->parse_from_file($in_file, $out_file); return $out_file; } sub _readme_pdf { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.pdf'; eval { require App::pod2pdf; } or die "Could not generate $out_file because pod2pdf could not be found\n"; my $parser = App::pod2pdf->new( @$options ); $parser->parse_from_file($in_file); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; select $out_fh; $parser->output; select STDOUT; close $out_fh; return $out_file; } sub _all_from { my $self = shift; return unless $self->admin->{extensions}; my ($metadata) = grep { ref($_) eq 'Module::Install::Metadata'; } @{$self->admin->{extensions}}; return unless $metadata; return $metadata->{values}{all_from} || ''; } 'Readme!'; __END__ #line 254 MooseX-App-1.33/inc/Module/Install/Win32.pm000644 000765 000024 00000003426 12514112767 020533 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; __END__ #line 80 MooseX-App-1.33/inc/Module/Install/WriteAll.pm000644 000765 000024 00000002421 12514112767 021346 0ustar00marosstaff000000 000000 #line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.10'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { # XXX: This still may be a bit over-defensive... unless ($self->makemaker(6.25)) { $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; } } # Until ExtUtils::MakeMaker support MYMETA.yml, make sure # we clean it up properly ourself. $self->realclean_files('MYMETA.yml'); if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } # The Makefile write process adds a couple of dependencies, # so write the META.yml files after the Makefile. if ( $args{meta} ) { $self->Meta->write; } # Experimental support for MYMETA if ( $ENV{X_MYMETA} ) { if ( $ENV{X_MYMETA} eq 'JSON' ) { $self->Meta->write_mymeta_json; } else { $self->Meta->write_mymeta_yaml; } } return 1; } 1; __END__ #line 79