MooseX-App-1.22/000755 000765 000024 00000000000 12147660746 013667 5ustar00marosstaff000000 000000 MooseX-App-1.22/Changes000644 000765 000024 00000006741 12147657211 015163 0ustar00marosstaff000000 000000 Changes for MooseX-App 1.22 Fri, May 24, 2013 - Silence experimental::smartmatch warnings on 5.18 (Mike Doherty) 1.21 Sat, Apr 13, 2013 - Fix option sorting - Fix parsing of positional parameters 1.20 Mon, Apr 8, 2013 - Add cmd_split and cmd_position option - Fixed parameter position (Yanick Champoux) - app_strict option to set if app should termiate when unknown parameters or options are supplied 1.19 Thu, Mar 28, 2013 - Fixed failing tests - Fixed bug that was triggered by Moose 2.0800 - Fixed on MSWin 1.18 Sun, Mar 24, 2013 - 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 Wed, Mar 6, 2013 - Fix failing tests 1.16 Wed, Feb 27, 2012 - Better license parsing - Fix failing tests - Use Class::Load instead of Class::MOP to load classes - Remove MooseX::Getopt depedency. 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 Fri, Jan 18, 2012 - Fix wrong attribute initalization order 1.14 Tue, Jan 15, 2012 - Fix failing test - Update documentation - Optional usage information from POD (Yanick Champoux) - app_fuzzy now defaults to true - Version plugin prints license and copyright 1.13 Fri, Jan 11, 2012 - Fix failing test - Update documentation 1.12 Thu, Jan 10, 2012 - Fix failing test - Fix pod (Andrew Jones) 1.11 Tue, Jan 8, 2012 - Parse DistZilla ABSTRACT for documentation - Improve tutorial and fix typo (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 Mon, Jan 7, 2013 - Fix bash completion plugin (Steve Nolte) 1.09 Thu, Nov 22, 2012 - Fix failing load test 1.08 Sat, Nov 17, 2012 - Refactor object initialization - Fix missing bash-completion prefix (Steve Nolte) - Require latest MooseX::Getopt (Steve Nolte) - Fix Plugin::Version docs RT81186 (Michael G) - Update documentation 1.07 Wed, Aug 22, 2012 - Fix failing load tests 1.06 Mon, Aug 20, 2012 - Single command interface (MooseX::App::Simple) - Fuzzy command matching plugin - Only lowercase command names - Environment plugin - Version plugin - Various cleanups 1.05 Mon, Jun 4, 2012 - Fix broken load tests - Join M::A::Meta::Attribute::Base and M::A::Meta::Attribute::Option 1.04 Sat, Jun 2, 2012 - Fix bugs in BashCompletion plugin - Remove code duplication - Fix --help flag in command classes - Fix pod to text conversion 1.03 Sat, Jun 2, 2012 - 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 Sun, Apr 15, 2012 - Fix command usage generation bug - Automatically apply MooseX-Getopt attribute traits - Rename command_tag to cmd_tag attribute 1.01 Thu, Apr 12, 2012 - Fix text failures - Fix Pod - Add missing tutorials to manifest 1.00 Sat, Apr 7, 2012 - Initial version MooseX-App-1.22/LICENCE000644 000765 000024 00000050101 11014620472 014631 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.22/MANIFEST000644 000765 000024 00000005130 12147660631 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/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/Env.pm lib/MooseX/App/Plugin/Env/Meta/Attribute.pm lib/MooseX/App/Plugin/Env/Meta/Class.pm lib/MooseX/App/Plugin/Fuzzy.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 MYMETA.json MYMETA.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_plugin_env.t t/07_single.t t/08_plugin_various.t t/09_classes.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/testlib/Test01.pm t/testlib/Test01/CommandA.pm t/testlib/Test01/CommandB.pm t/testlib/Test01/CommandC1.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/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/Test04.pm t/testlib/Test04Base.pm t/testlib/Test05.pm t/testlib/Test06.pm t/testlib/Test06/CommandA.pm t/testlib/Test06/CommandB.pm TODO xt/perlcritic.t xt/pod.t xt/podcoverage.t xt/podstyle.t MooseX-App-1.22/META.yml000644 000765 000024 00000001607 12147660606 015137 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.06' 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 Term::ANSIColor: 0 Text::WagnerFischer: 0 requires: Config::Any: 0 IO::Interactive: 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.22 MooseX-App-1.22/MYMETA.json000644 000765 000024 00000002417 12147660606 015555 0ustar00marosstaff000000 000000 { "abstract" : "Write user-friendly command line apps with even less suffering", "author" : [ "MaroÅ¡ Kollár" ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.130880", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-App", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "6.59", "Test::Most" : "0", "Test::NoWarnings" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Config::Any" : "0", "IO::Interactive" : "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.010" } } }, "release_status" : "stable", "version" : "1.22" } MooseX-App-1.22/MYMETA.yml000644 000765 000024 00000001333 12147660606 015401 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: 0 dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.130880' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-App no_index: directory: - t - inc requires: Config::Any: 0 IO::Interactive: 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.010 version: 1.22 MooseX-App-1.22/Makefile.PL000644 000765 000024 00000002450 12125106277 015630 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; requires 'IO::Interactive' => 0; recommends 'Term::ANSIColor' => 0; recommends 'File::HomeDir' => 0; recommends 'Text::WagnerFischer' => 0; 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.22/README000644 000765 000024 00000020226 12147660605 014543 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(Config 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 extends qw(MyApp); # purely optional, only if you want to use global options from base class parameter 'some_parameter' => ( is => 'rw', isa => 'Str', required => 1, documentation => q[Some parameter that you need to supply], ); # Positional parameter option 'some_option' => ( is => 'rw', isa => 'Int', required => 1, documentation => q[Very important option!], ); # Option sub run { my ($self) = @_; # Do something } And then in some simple wrapper script: #!/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 customizeable 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. MooseX-App will then take care of * Finding, loading and initializing the command classes * Creating automated help and documentation from pod and attributes * Reading, encoding and validating the command line options and positional parameters entered by the user * Providing helpful error messages if user input cannot be validated 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'], cmd_type => 'option', ); 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', ); 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 method reads the command line arguments from the user and tries to create a command object. If it fails it retuns a MooseX::App::Message::Envelope object holding an error message. You can pass a hash of default params to new_with_command MyApp->new_with_command(%default); initialize_command_class my $myapp_command = MyApp->initialize_command_class($command_name,%default); Helper method to initialize the command class for the given command. GLOBAL OPTIONS app_base app_base 'my_script'; Usually MooseX::App will take the name of the calling wrapper script to construct the programm name in various help messages. This name can be changed via the app_base function. app_namespace app_namespace 'MyApp::Commands'; Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed. 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 programm 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. app_command_name app_command_name { my ($package) = shift; # munge package name; return $command_name }; This sub can be used to control how package names should be translated to command names. GLOBAL ATTRIBUTES All MooseX::App classes will have two extra attributes/accessors extra_argv Carries all parameters from @ARGV that were not consumed. help_flag Help flag option ATTRIBUTE OPTIONS * cmd_tags - Extra tags * cmd_flag - Override option name * cmd_aliases - Alternative option names * cmd_split - Split values * cmd_position - Option/Parameter order Refer to MooseX::App::Meta::Role::Attribute::Option for detailed documentation. PLUGINS The behaviour of MooseX-App can be customized with plugins. To load a plugin just pass a list of plugin names after the "use MooseX-App" statement. use MooseX::App qw(PluginA PluginB); Read the Writing MooseX-App Plugins documentation on how to create your own plugins. 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 your MooseX::App applications * MooseX::App::Plugin::ConfigHome Config files in users home directory * MooseX::App::Plugin::Env Read options from environment * MooseX::App::Plugin::Typo Handle typos in command names * MooseX::App::Plugin::Version Adds a command to display the version and license of your application 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 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 In no particular order: Andrew Jones, George Hartzell, Steve Nolte, Michael G, Thomas Klausner, Yanick Champoux, Edward Baudrez COPYRIGHT MooseX::App is Copyright (c) 2012 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.22/TODO000644 000765 000024 00000000040 12130503632 014327 0ustar00marosstaff000000 000000 * Make messages translatable * MooseX-App-1.22/inc/000755 000765 000024 00000000000 12147660746 014440 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/000755 000765 000024 00000000000 12147660746 014435 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/000755 000765 000024 00000000000 12147660746 014132 5ustar00marosstaff000000 000000 MooseX-App-1.22/xt/000755 000765 000024 00000000000 12147660746 014322 5ustar00marosstaff000000 000000 MooseX-App-1.22/xt/perlcritic.t000644 000765 000024 00000001010 11763711152 016626 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.22/xt/pod.t000644 000765 000024 00000000336 11003046630 015247 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.22/xt/podcoverage.t000644 000765 000024 00000000365 11003046630 016765 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.22/xt/podstyle.t000644 000765 000024 00000001735 11451766000 016343 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.22/t/00_load.t000755 000765 000024 00000004275 12123770101 015525 0ustar00marosstaff000000 000000 # -*- perl -*- # t/00_load.t - check module loading and create testing directory use Test::Most tests => 33; 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::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::Env' ); use_ok( 'MooseX::App::Plugin::Env::Meta::Class'); use_ok( 'MooseX::App::Plugin::Env::Meta::Attribute'); 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::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::ANSIColor'); 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 is 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.22/t/01_basic.t000755 000765 000024 00000012373 12123560032 015666 0ustar00marosstaff000000 000000 # -*- perl -*- # t/01_basic.t - Basic tests use Test::Most tests => 11+1; use Test::NoWarnings; use FindBin qw(); use lib 't/testlib'; use Test01; subtest 'Excact command with option' => sub { explain(); local @ARGV = qw(command_a --global 10); my $test01 = Test01->new_with_command({ global => 5 }); isa_ok($test01,'Test01::CommandA'); is($test01->global,'10','Param is set'); }; subtest 'Fuzzy command with option' => sub { local @ARGV = qw(Command_A --global 10); my $test02 = Test01->new_with_command( global => 5 ); isa_ok($test02,'Test01::CommandA'); is($test02->global,'10','Param is set'); }; subtest 'Wrong command' => sub { local @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->[2]->header,"global options:",'Global options set'); is($test03->blocks->[2]->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->[3]->header,"available commands:",'Available commands set'); is($test03->blocks->[3]->body," command_a Command A! command_b Test class command B for test 01 command_c1 Test C1 help Prints this usage information",'Available commands body set'); }; subtest 'Help for command' => sub { local @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; Important; Env: LOCAL1] --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 { local @ARGV = qw(Command_b --global 10); my $test02 = Test01->new_with_command( 'param_b' => 'bbb', 'global' => 20, 'private'=>5 ); isa_ok($test02,'Test01::CommandB'); is($test02->global,10,'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 { local @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 { local @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 { local @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 { local @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 { local @ARGV = qw(); my $test10 = Test01->new_with_command; isa_ok($test10,'MooseX::App::Message::Envelope'); is($test10->blocks->[0]->header,'Missing command','Error message ok'); }; MooseX-App-1.22/t/02_meta.t000644 000765 000024 00000005756 12132202372 015540 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; is($meta->app_namespace,'Test01','Command namespace ok'); my $commands = $meta->app_commands; is(join(',',sort keys %{$commands}),'command_a,command_b,command_c1','Commands found'); is(join(',',sort values %{$commands}),'Test01::CommandA,Test01::CommandB,Test01::CommandC1','Commands found'); is($meta->app_namespace,'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},3,'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 A,B and C1 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'); MooseX-App-1.22/t/03_utils.t000755 000765 000024 00000007200 12132202372 015740 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.22/t/04_plugin_config.t000644 000765 000024 00000002637 12075344666 017455 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 { local @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 { local @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 { local @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 { local @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.22/t/05_extended.t000755 000765 000024 00000020436 12132203775 016420 0ustar00marosstaff000000 000000 # -*- perl -*- # t/05_extended.t - Extended tests use Test::Most tests => 21+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 { local @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 { local @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 { local @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 { local @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 { local @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 { local @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] --roleattr [Role] --some_option Very important option!","Message ok"); }; subtest 'Test wrapper script error' => sub { my $output = `$^X $FindBin::Bin/example/test03.pl some`; like($output,qr/equired option 'another' missing/,'Output is 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 { local @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 { local @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 { local @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 { local @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 { local @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); 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"); cmp_deeply($test09->split,[qw(a b c)],'Split ok'); }; subtest 'Test ambiguous options' => sub { local @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 { local @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 { local @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,0,'Bool2 flag is unset'); is($test11->bool3,1,'Bool3 flag is set'); is($test11->value,'baer','Value is set'); }; subtest 'Test positional params' => sub { local @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 { local @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 { local @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 { local @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 { local @ARGV = qw(extra --value baer); my $test13 = Test03->new_with_command; isa_ok($test13,'MooseX::App::Message::Envelope'); is($test13->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 { local @ARGV = qw(extra p1 22 33 marder dachs --value 44 --flag luchs --flagg fuchs -- baer --hase); my $test14 = Test03->new_with_command; isa_ok($test14,'Test03::ExtraCommand'); is($test14->extra1,'p1','Param 1 ok'); is($test14->extra2,'22','Param 2 ok'); is($test14->alpha,'33','Param 3 ok'); is($test14->extra_argv->[0],'marder','Uncomsumed parameter ok'); is($test14->extra_argv->[1],'dachs','Uncomsumed parameter ok'); is($test14->extra_argv->[2],'luchs','Uncomsumed option ok'); is($test14->extra_argv->[3],'fuchs','Uncomsumed option ok'); is($test14->extra_argv->[4],'baer','Uncomsumed option ok'); is($test14->extra_argv->[5],'--hase','Uncomsumed option ok'); }; MooseX-App-1.22/t/06_plugin_env.t000644 000765 000024 00000002351 12113460743 016757 0ustar00marosstaff000000 000000 # -*- perl -*- # t/06_plugin_env.t - Test env plugin use Test::Most tests => 4+1; use Test::NoWarnings; use lib 't/testlib'; use Test01; subtest 'Command with argv' => sub { local @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 { local @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 { local @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 { local @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 value for 'command_local1'","Message ok"); };MooseX-App-1.22/t/07_single.t000644 000765 000024 00000001310 12113460743 016065 0ustar00marosstaff000000 000000 # -*- perl -*- # t/07_single.t- Test MooseX::App::Single use Test::Most tests => 2+1; use Test::NoWarnings; use lib 't/testlib'; use Test05; subtest 'Single command' => sub { local @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 { local @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'); }; MooseX-App-1.22/t/08_plugin_various.t000644 000765 000024 00000002007 12113460743 017657 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 { local @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 { local @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.22/t/09_classes.t000644 000765 000024 00000003455 12127616665 016272 0ustar00marosstaff000000 000000 # -*- perl -*- # t/09_classes.t - Test classes use Test::Most tests => 5+1; use Test::NoWarnings; use lib 't/testlib'; use Test04; use Test03; subtest 'Extend base class' => sub { local @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 { local @ARGV = qw(broken --conflict a); throws_ok { Test03->new_with_command; } qr/Command line option conflict/, 'Conflict detected'; }; subtest 'Attributes from role ' => sub { local @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 { local @ARGV = qw(somecommand a1 b2 c3 --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,'c3','Third from role'); }; MooseX-App-1.22/t/config.pl000644 000765 000024 00000000232 11762214012 015710 0ustar00marosstaff000000 000000 { global => { global => 123, }, command_a => { global => 234, command_local1 => 22, }, }MooseX-App-1.22/t/example/000755 000765 000024 00000000000 12147660746 015565 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/000755 000765 000024 00000000000 12147660746 015600 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test01/000755 000765 000024 00000000000 12147660746 016660 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test01.pm000644 000765 000024 00000000506 12123556767 017220 0ustar00marosstaff000000 000000 package Test01; use Moose; use MooseX::App qw(Config Env); option 'global' => ( isa => 'Int', is => 'rw', required => 1, documentation => q[test], cmd_tags => ['Important!'], ); has 'private' => ( isa => 'Int', is => 'rw', ); 1;MooseX-App-1.22/t/testlib/Test02/000755 000765 000024 00000000000 12147660746 016661 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test02.pm000644 000765 000024 00000000611 12110162144 017170 0ustar00marosstaff000000 000000 package Test02; use Moose; use MooseX::App qw(BashCompletion ConfigHome Color Version Env Typo); our $VERSION = 1.01; app_namespace "Test02::Command"; #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.22/t/testlib/Test03/000755 000765 000024 00000000000 12147660746 016662 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test03.pm000644 000765 000024 00000001101 12130504066 017171 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.22/t/testlib/Test04.pm000644 000765 000024 00000000264 12123556074 017213 0ustar00marosstaff000000 000000 package Test04; #use Moose; use MooseX::App; extends qw(Test04Base); option 'test1' => ( is => 'rw', isa => 'Int', ); option '+test2' => (); 1;MooseX-App-1.22/t/testlib/Test04Base.pm000644 000765 000024 00000000465 12113460743 020005 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.22/t/testlib/Test05.pm000644 000765 000024 00000000751 12110162125 017177 0ustar00marosstaff000000 000000 package Test05; #use Moose; use MooseX::App::Simple qw(Config Env); 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;MooseX-App-1.22/t/testlib/Test06/000755 000765 000024 00000000000 12147660746 016665 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test06.pm000644 000765 000024 00000000542 12110162133 017175 0ustar00marosstaff000000 000000 package Test06; use MooseX::App qw(Config Env); app_fuzzy(1); app_command_name { my @parts = split( /[_\s]+|\b|(? ( is => 'rw', isa => 'Bool', documentation => q[Enable this to do fancy stuff], ); 1;MooseX-App-1.22/t/testlib/Test06/CommandA.pm000644 000765 000024 00000001261 12113460743 020666 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.22/t/testlib/Test06/CommandB.pm000644 000765 000024 00000000325 12042256202 020661 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.22/t/testlib/Test03/AnotherCommand.pm000644 000765 000024 00000002025 12130461043 022073 0ustar00marosstaff000000 000000 package Test03::AnotherCommand; use MooseX::App::Command; 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 ['extra1','extra2'] => ( is => 'rw', ); sub run { my ($self) = @_; } 1;MooseX-App-1.22/t/testlib/Test03/BrokenCommand.pm000644 000765 000024 00000000541 12113460743 021723 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.22/t/testlib/Test03/ExtraCommand.pm000644 000765 000024 00000001531 12132202372 021557 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.22/t/testlib/Test03/Role/000755 000765 000024 00000000000 12147660746 017563 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test03/SomeCommand.pm000644 000765 000024 00000001426 12127616665 021424 0ustar00marosstaff000000 000000 package Test03::SomeCommand; use MooseX::App::Command; extends qw(Test03); with qw(Test03::Role::TestRole); parameter 'param_a' => ( is => 'rw', isa => 'Str', ); parameter 'param_b' => ( is => 'rw', isa => 'Str', ); 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'], ); has 'private' => ( is => 'rw', isa => 'Str', ); sub run { my ($self) = @_; print "RUN:".($self->some_option||'').":".($self->another_option||''); } 1;MooseX-App-1.22/t/testlib/Test03/YetAnotherCommand.pm000644 000765 000024 00000001315 12113460743 022565 0ustar00marosstaff000000 000000 package Test03::YetAnotherCommand; use MooseX::App::Command; 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.22/t/testlib/Test03/Role/TestRole.pm000644 000765 000024 00000000710 12127616665 021657 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.22/t/testlib/Test02/Command/000755 000765 000024 00000000000 12147660746 020237 5ustar00marosstaff000000 000000 MooseX-App-1.22/t/testlib/Test02/Command/Error.pm000644 000765 000024 00000000477 12075527342 021670 0ustar00marosstaff000000 000000 package Test02::Command::Error; use Moose; use MooseX::App::Command; extends qw(Test02); sub BUILD { die('XXX'); } sub run { die('YYY'); } 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.22/t/testlib/Test02/Command/Record.pm000644 000765 000024 00000000137 12056145645 022007 0ustar00marosstaff000000 000000 package Test02::Command::Record; use Moose; use MooseX::App::Command; extends qw(Test02); 1;MooseX-App-1.22/t/testlib/Test02/Command/Required.pm000644 000765 000024 00000000475 12031634445 022350 0ustar00marosstaff000000 000000 package Test02::Command::Required; use Moose; use MooseX::App::Command; extends qw(Test02); option 'local1' => ( isa => 'Int', is => 'rw', required => 1, ); option 'local2' => ( isa => 'Bool', is => 'rw', default => 1, ); 1;MooseX-App-1.22/t/testlib/Test01/CommandA.pm000644 000765 000024 00000001765 12107762601 020673 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.22/t/testlib/Test01/CommandB.pm000644 000765 000024 00000001454 12075345573 020700 0ustar00marosstaff000000 000000 package Test01::CommandB; use Moose; use MooseX::App::Command; extends qw(Test01); has 'param_a' => ( isa => 'Str', is => 'rw', ); option 'param_b' => ( isa => 'Str', 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.22/t/testlib/Test01/CommandC1.pm000644 000765 000024 00000000401 12113460743 020737 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.22/t/example/test01.pl000755 000765 000024 00000000254 12075527062 017237 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.22/t/example/test02.pl000755 000765 000024 00000000235 12074052212 017224 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.22/t/example/test03.pl000755 000765 000024 00000000235 12074052212 017225 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.22/t/example/test04.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 Test04; Test04->new_with_command->run;MooseX-App-1.22/t/example/test05.pl000755 000765 000024 00000000235 12074052271 017234 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.22/t/example/test06.pl000755 000765 000024 00000000235 12074052241 017232 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.22/lib/MooseX/000755 000765 000024 00000000000 12147660746 015647 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/000755 000765 000024 00000000000 12147660746 016367 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App.pm000644 000765 000024 00000026553 12147323626 016731 0ustar00marosstaff000000 000000 # ============================================================================« package MooseX::App; # ============================================================================« use 5.010; use utf8; use strict; use warnings; our $AUTHORITY = 'cpan:MAROS'; our $VERSION = '1.22'; use MooseX::App::Meta::Role::Attribute::Option; use MooseX::App::Exporter qw(app_base app_fuzzy app_strict 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_namespace app_base app_fuzzy app_command_name 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'], 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_namespace($) { my ( $meta, $name ) = @_; return $meta->app_namespace($name); } 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; Moose->throw_error('new_with_command may only be called from the application base package') if $meta->meta->does_role('MooseX::App::Meta::Role::Class::Command'); # 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->new(); my $first_argv = $parsed_argv->first_argv; # No args if (! defined $first_argv || $first_argv =~ m/^\s*$/) { return MooseX::App::Message::Envelope->new( $meta->command_message( header => "Missing command", # LOCALIZE type => "error", ), $meta->command_usage_global(), ); # Requested help } elsif (lc($first_argv) =~ m/^(help|h|\?|usage)$/) { return MooseX::App::Message::Envelope->new( $meta->command_usage_global(), ); # 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(), ); # 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(Config 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 extends qw(MyApp); # purely optional, only if you want to use global options from base class parameter 'some_parameter' => ( is => 'rw', isa => 'Str', required => 1, documentation => q[Some parameter that you need to supply], ); # Positional parameter option 'some_option' => ( is => 'rw', isa => 'Int', required => 1, documentation => q[Very important option!], ); # Option sub run { my ($self) = @_; # Do something } And then in some simple wrapper script: #!/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 customizeable 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. MooseX-App will then take care of =over =item * Finding, loading and initializing the command classes =item * Creating automated help and documentation from pod and attributes =item * Reading, encoding and validating the command line options and positional parameters entered by the user =item * Providing helpful error messages if user input cannot be validated =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'], cmd_type => 'option', ); 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', ); 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 method reads the command line arguments from the user and tries to create a command object. If it fails it retuns a L object holding an error message. You can pass a hash of default params to new_with_command MyApp->new_with_command(%default); =head2 initialize_command_class my $myapp_command = MyApp->initialize_command_class($command_name,%default); Helper method to initialize the command class for the given command. =head1 GLOBAL OPTIONS =head2 app_base app_base 'my_script'; Usually MooseX::App will take the name of the calling wrapper script to construct the programm name in various help messages. This name can be changed via the app_base function. =head2 app_namespace app_namespace 'MyApp::Commands'; Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed. =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 programm 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. =head2 app_command_name app_command_name { my ($package) = shift; # munge package name; return $command_name }; This sub can be used to control how package names should be translated to command names. =head1 GLOBAL ATTRIBUTES All MooseX::App classes will have two extra attributes/accessors =head2 extra_argv Carries all parameters from @ARGV that were not consumed. =head2 help_flag Help flag option =head1 ATTRIBUTE OPTIONS =over =item * cmd_tags - Extra tags =item * cmd_flag - Override option name =item * cmd_aliases - Alternative option names =item * cmd_split - Split values =item * cmd_position - Option/Parameter order =back Refer to L for detailed documentation. =head1 PLUGINS The behaviour of MooseX-App can be customized with plugins. To load a plugin just pass a list of plugin names after the C statement. use MooseX::App qw(PluginA PluginB); Read the L documentation on how to create your own plugins. 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 your MooseX::App applications =item * L Config files in users home directory =item * L Read options from environment =item * L Handle typos in command names =item * L Adds a command to display the version and license of your application =back =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 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 In no particular order: Andrew Jones, George Hartzell, Steve Nolte, Michael G, Thomas Klausner, Yanick Champoux, Edward Baudrez =head1 COPYRIGHT MooseX::App is Copyright (c) 2012 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.22/lib/MooseX/App/Command.pm000644 000765 000024 00000005233 12147322150 020266 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); use Moose::Exporter; Moose::Exporter->setup_import_methods( with_meta => [qw(command_short_description command_long_description 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::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 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. =cut 1; MooseX-App-1.22/lib/MooseX/App/Exporter.pm000644 000765 000024 00000011337 12147657426 020543 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); our %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_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); } 1; MooseX-App-1.22/lib/MooseX/App/Message/000755 000765 000024 00000000000 12147660746 017753 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Meta/000755 000765 000024 00000000000 12147660746 017255 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/ParsedArgv/000755 000765 000024 00000000000 12147660746 020425 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/ParsedArgv.pm000644 000765 000024 00000015305 12147657426 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 => 'rw', isa => 'ArrayRef[Str]', lazy_build => 1, ); has 'fuzzy' => ( is => 'rw', isa => 'Bool', ); has 'hints' => ( is => 'rw', isa => 'ArrayRef[Str]', default => sub { [] }, ); has 'elements' => ( is => 'rw', isa => 'ArrayRef[MooseX::App::ParsedArgv::Element]', lazy_build => 1, 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' ); push(@elements,$options{$flag}); } $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' ); push(@elements,$options{$key}); } $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' ); push(@elements,$options{$key}); } $lastkey = $options{$key}; } # Extra values when ('--') { undef $lastkey; $stopprocessing = 1; } # Value default { if (defined $lastkey) { # Is boolean # TODO handle fuzzy if ($lastkey->key ~~ $self->hints) { push(@elements,MooseX::App::ParsedArgv::Element->new( key => $element, type => 'parameter' )); # Not a boolean field } 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 _build_argv { 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; } 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 should not need to interact with this class. =head1 METHODS =head2 new Create a new MooseX::App::ParsedArgv instance. =head2 instance Get the current MooseX::App::ParsedArgv instance. If there is no instance a new one will be created. =head2 argv Get/set the original @ARGV. Also available via C =head2 hints Sets fuzzy hin Also available via C =head2 first_argv Shifts the 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.22/lib/MooseX/App/Plugin/000755 000765 000024 00000000000 12147660746 017625 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Role/000755 000765 000024 00000000000 12147660746 017270 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Role.pm000644 000765 000024 00000002545 12147322150 017614 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'], cmd_type => 'option', cmd_tags => [qw(Important! Nice))], ); =cutMooseX-App-1.22/lib/MooseX/App/Simple.pm000644 000765 000024 00000010341 12147322150 020135 0ustar00marosstaff000000 000000 package MooseX::App::Simple; # ============================================================================« use 5.010; use utf8; use strict; use warnings; use Moose::Exporter; use MooseX::App::Exporter qw(app_base app_fuzzy app_strict option parameter command_short_description command_long_description command_usage); use MooseX::App::Meta::Role::Attribute::Option; use MooseX::App::Message::Envelope; use Scalar::Util qw(blessed); our $VERSION = '1.15'; my ($IMPORT,$UNIMPORT,$INIT_META) = Moose::Exporter->build_import_methods( with_meta => [ qw(app_base app_fuzzy app_strict option parameter command_short_description command_long_description command_usage) ], 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::Command' ], 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'); } # Get ARGV my $parsed_argv = MooseX::App::ParsedArgv->new( argv => \@ARGV, fuzzy => $class->meta->app_fuzzy, ); 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 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.22/lib/MooseX/App/Tutorial.pod000644 000765 000024 00000014712 12147322150 020663 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 =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. package MyApp; use MooseX::App qw(Config); # Loads the Config 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. =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. All command classes must load 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 section will become the short description and the DESCRIPTION or OVERVIEW section the long description. If your class has no POD, MooseX-App will look for the DistZilla abstract tag. 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. 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 header): 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 [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. (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. 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(); MooseX-App-1.22/lib/MooseX/App/Utils.pm000644 000765 000024 00000013551 12147657426 020033 0ustar00marosstaff000000 000000 package MooseX::App::Utils; use 5.010; use utf8; use strict; use warnings; no if $] >= 5.018000, warnings => qw/ experimental::smartmatch /; use List::Util qw(max); our $SCREEN_WIDTH = 78; our $INDENT = 4; 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); } 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; } sub parse_pod { 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; # 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); $content =~ s/^$package(\s-)?\s//; chomp($content); $pod{NAME} = $content; } else { my $content = _pod_node_to_text($element->children); chomp($content); $pod{uc($element->content)} = $content; } } } return %pod; } 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.22/lib/MooseX/App/WritingPlugins.pod000644 000765 000024 00000003315 12147660470 022054 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.22/lib/MooseX/App/Role/Base.pm000644 000765 000024 00000005271 12147322150 020465 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Role::Base; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; #has ARGV => ( # is => 'rw', # isa => 'ArrayRef', #); 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 = ( %args, # configs passed to new %{ $proto_result }, # config params %{ $result }, # params from CLI ); # Check required values foreach my $attribute ($meta->command_usage_attributes($command_meta,[qw(option proto parameter)])) { if ($attribute->is_required && ! exists $params{$attribute->name} && ! $attribute->has_default) { push(@errors, $meta->command_message( header => "Required ".($attribute->cmd_type eq 'parameter' ? 'parameter':'option')." '".$attribute->cmd_name_primary."' missing", # LOCALIZE type => "error", ) ); } } if (scalar @errors) { return MooseX::App::Message::Envelope->new( @errors, $meta->command_usage_command($command_meta), ); } 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), ); } return $command_object; } 1;MooseX-App-1.22/lib/MooseX/App/Role/Common.pm000644 000765 000024 00000001216 12147322150 021036 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 ?) ], cmd_type => 'proto', cmd_position => 99999, documentation => 'Prints this usage information.', # LOCALIZE ); 1;MooseX-App-1.22/lib/MooseX/App/Plugin/BashCompletion/000755 000765 000024 00000000000 12147660746 022534 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/BashCompletion.pm000644 000765 000024 00000002273 12147322150 023056 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.22/lib/MooseX/App/Plugin/Color/000755 000765 000024 00000000000 12147660746 020703 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Color.pm000644 000765 000024 00000001245 12147322150 021223 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.22/lib/MooseX/App/Plugin/Config/000755 000765 000024 00000000000 12147660746 021032 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Config.pm000644 000765 000024 00000003456 12147322150 021360 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.22/lib/MooseX/App/Plugin/ConfigHome/000755 000765 000024 00000000000 12147660746 021643 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/ConfigHome.pm000644 000765 000024 00000001633 12147322150 022164 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.22/lib/MooseX/App/Plugin/Env/000755 000765 000024 00000000000 12147660746 020355 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Env.pm000644 000765 000024 00000002476 12147322150 020704 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Env; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; sub plugin_metaroles { my ($self,$class) = @_; return { class => ['MooseX::App::Plugin::Env::Meta::Class'], attribute => ['MooseX::App::Plugin::Env::Meta::Attribute'], } } 1; __END__ =encoding utf8 =head1 NAME MooseX::App::Plugin::BashCompletion - Read options from environment =head1 SYNOPSIS In your base class: package MyApp; use MooseX::App qw(Env); In your command class: package MyApp::SomeCommand; use MooseX::App::Command; option 'some_option' => ( is => 'rw', isa => 'Str', cmd_env => 'SOME_OPTION', ); sub run { my ($self) = @_; say "Some option is ".$self->some_option; } In your shell bash$ export SOME_OPTION=test bash$ myapp some_command Some option is test bash$ SOME_OPTION=test bash$ myapp some_command --some_option override Some option is override =head1 DESCRIPTION This plugin can read options from the shell environment. Just add 'cmd_env' and a name (all uppercase and no spaces) to the options you wish to read from the environment. =cutMooseX-App-1.22/lib/MooseX/App/Plugin/Fuzzy.pm000644 000765 000024 00000000617 12147322150 021276 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.22/lib/MooseX/App/Plugin/Typo/000755 000765 000024 00000000000 12147660746 020560 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Typo.pm000644 000765 000024 00000001375 12147322150 021104 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.22/lib/MooseX/App/Plugin/Version/000755 000765 000024 00000000000 12147660746 021252 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Version.pm000644 000765 000024 00000002556 12147322150 021600 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 and COPYRIGHT sections =cut MooseX-App-1.22/lib/MooseX/App/Plugin/Version/Command.pm000644 000765 000024 00000002434 12147322150 023151 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.22/lib/MooseX/App/Plugin/Version/Meta/000755 000765 000024 00000000000 12147660746 022140 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Version/Meta/Class.pm000644 000765 000024 00000001166 12147322150 023527 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'; #$self->command_register('bash_completion','MooseX::App::Plugin::Version::Command'); return $return; }; 1;MooseX-App-1.22/lib/MooseX/App/Plugin/Typo/Meta/000755 000765 000024 00000000000 12147660746 021446 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Typo/Meta/Class.pm000644 000765 000024 00000002005 12147322150 023026 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.22/lib/MooseX/App/Plugin/Env/Meta/000755 000765 000024 00000000000 12147660746 021243 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Env/Meta/Attribute.pm000644 000765 000024 00000001754 12147322150 023533 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Env::Meta::Attribute; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; use Moose::Util::TypeConstraints; subtype 'MooseX::App::Types::Env', as 'Str', where { m/^[A-Z0-9_]+$/ }; no Moose::Util::TypeConstraints; has 'cmd_env' => ( is => 'rw', isa => 'MooseX::App::Types::Env', predicate => 'has_cmd_env', ); around 'cmd_tags_list' => sub { my $orig = shift; my ($self) = @_; my @tags = $self->$orig(); push(@tags,'Env: '.$self->cmd_env) if $self->can('has_cmd_env') && $self->has_cmd_env; return @tags; }; { package Moose::Meta::Attribute::Custom::Trait::AppEnv; use strict; use warnings; sub register_implementation { return 'MooseX::App::Plugin::Env::Meta::Attribute' } } 1;MooseX-App-1.22/lib/MooseX/App/Plugin/Env/Meta/Class.pm000644 000765 000024 00000002011 12147322150 022620 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Plugin::Env::Meta::Class; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose::Role; around 'command_proto' => sub { my ($orig,$self,$command_meta,$processed_argv) = @_; my ($result,$errors) = $self->$orig($command_meta,$processed_argv); foreach my $attribute ($self->command_usage_attributes($command_meta)) { next unless $attribute->can('has_cmd_env') && $attribute->has_cmd_env; my $cmd_env = $attribute->cmd_env; if (exists $ENV{$cmd_env} && ! defined $result->{$attribute->name}) { $result->{$attribute->name} = $ENV{$cmd_env}; my $error = $self->command_check_attribute($attribute,$ENV{$cmd_env}); push(@{$errors},$error) if $error; } } return ($result,$errors); }; 1;MooseX-App-1.22/lib/MooseX/App/Plugin/ConfigHome/Meta/000755 000765 000024 00000000000 12147660746 022531 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/ConfigHome/Meta/Class.pm000644 000765 000024 00000001624 12147322150 024117 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.22/lib/MooseX/App/Plugin/Config/Meta/000755 000765 000024 00000000000 12147660746 021720 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Config/Meta/Class.pm000644 000765 000024 00000004327 12147322150 023311 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,$processed_argv) = @_; my ($result,$errors) = $self->$orig($metaclass,$processed_argv); 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)) { 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.22/lib/MooseX/App/Plugin/Color/Meta/000755 000765 000024 00000000000 12147660746 021571 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/Color/Meta/Class.pm000644 000765 000024 00000000627 12147322150 023161 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.22/lib/MooseX/App/Plugin/BashCompletion/Command.pm000644 000765 000024 00000005066 12147322150 024437 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.22/lib/MooseX/App/Plugin/BashCompletion/Meta/000755 000765 000024 00000000000 12147660746 023422 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Plugin/BashCompletion/Meta/Class.pm000644 000765 000024 00000001232 12147322150 025003 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'; #$self->command_register('bash_completion','MooseX::App::Plugin::BashCompletion::Command'); return $return; }; 1;MooseX-App-1.22/lib/MooseX/App/ParsedArgv/Element.pm000644 000765 000024 00000004125 12147660015 022343 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 => 'rw', isa => 'ArrayRef[Str]', traits => ['Array'], default => sub { [] }, handles => { add_value => 'push', has_values => 'count', get_value => 'get', } ); has 'consumed' => ( is => 'rw', isa => 'Bool', default => 0, ); has 'type' => ( is => 'rw', isa => 'Str', required => 1, ); 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 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 element from @ARGV =head1 METHODS =head2 key Parameter value or option key =head2 value Arrayref of values =head2 type Type of element. Can be 'option', 'parameter' or 'extra' =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)MooseX-App-1.22/lib/MooseX/App/Meta/Role/000755 000765 000024 00000000000 12147660746 020156 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Meta/Role/Attribute/000755 000765 000024 00000000000 12147660746 022121 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Meta/Role/Class/000755 000765 000024 00000000000 12147660746 021223 5ustar00marosstaff000000 000000 MooseX-App-1.22/lib/MooseX/App/Meta/Role/Class/Base.pm000644 000765 000024 00000064332 12147657426 022444 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Base; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; use MooseX::App::Utils; use Path::Class; use Module::Pluggable::Object; use List::Util qw(max); no if $] >= 5.018000, warnings => qw(experimental::smartmatch); has 'app_messageclass' => ( is => 'rw', isa => 'ClassName', lazy_build => 1, ); has 'app_namespace' => ( is => 'rw', isa => 'Str', lazy_build => 1, ); has 'app_base' => ( is => 'rw', isa => 'Str', default => sub { Path::Class::File->new($0)->basename }, ); has 'app_strict' => ( is => 'rw', isa => 'Bool', default => 0, ); has 'app_fuzzy' => ( is => 'rw', isa => 'Bool', default => 1, ); has 'app_command_name' => ( is => 'rw', isa => 'CodeRef', default => sub { \&MooseX::App::Utils::class_to_command }, ); has 'app_commands' => ( is => 'rw', isa => 'HashRef[Str]', traits => ['Hash'], handles => { command_register => 'set', command_get => 'get', }, lazy_build => 1, ); 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 $mpo = Module::Pluggable::Object->new( search_path => [ $self->app_namespace ], ); my $namespace = $self->app_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); foreach my $option ($parsed_argv->available('option')) { unshift(@{$errors}, $self->command_message( header => "Unknown option '".$option->key."'", # LOCALIZE type => "error", ) ); } # Process params my @attributes_parameter = $self->command_usage_attributes($metaclass,'parameter'); foreach my $attribute (@attributes_parameter) { my $value = $parsed_argv->consume('parameter'); last unless defined $value; my ($parameter_value,$parameter_errors) = $self->command_process_attribute($attribute,$value->key); push(@{$errors},@{$parameter_errors}); $return->{$attribute->name} = $parameter_value; } # Handle all unconsumed parameters and options if ($self->app_strict) { foreach my $parameter ($parsed_argv->available('parameter')) { unshift(@{$errors}, $self->command_message( header => "Unknown parameter '".$parameter->key."'", # LOCALIZE type => "error", ) ); } } return ($return,$errors); } sub command_proto { my ($self,$metaclass) = @_; $metaclass ||= $self; my @attributes; foreach my $attribute ($self->command_usage_attributes($metaclass)) { next unless $attribute->does('AppOption') && $attribute->has_cmd_type && $attribute->cmd_type eq 'proto'; 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->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->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 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 = $attribute->cmd_is_bool; # TODO or 0 if no! } 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 = $self->command_check_attribute($attribute,$value); push(@errors,$error) if $error; } } else { $value = $raw->[-1]; } return ($value,\@errors); } sub command_check_attribute { my ($self,$attribute,$value) = @_; return unless ($attribute->has_type_constraint); my $type_constraint = $attribute->type_constraint; # Check type constraints unless ($type_constraint->check($value)) { my $message; # We have a custom message if ($type_constraint->has_message) { $message = $type_constraint->get_message($value); # No message } else { my $type_human = $self->command_type_constraint_description($type_constraint->name); if (defined $type_human) { $message = "Value must be "; # LOCALIZE if ($type_human =~ /^[aeiouy]/) { $message .= "an $type_human"; } else { $message .= "a $type_human"; } $message .= " (not '$value')"; } else { $message = $type_constraint->get_message($value); } } return $self->command_message( header => "Invalid value for '".$attribute->cmd_name_primary."'", # LOCALIZE type => "error", body => $message, ); } return; } sub command_type_constraint_description { my ($self,$type_constraint_name) = @_; given ($type_constraint_name) { when ('Int') { return 'integer'; # LOCALIZE } when ('Num') { return 'number'; # LOCALIZE } when (/^ArrayRef\[(.*)\]$/) { return $self->command_type_constraint_description($1); } when ('HashRef') { return 'key-value pairs'; # LOCALIZE } when (/^HashRef\[(.+)\]$/) { return 'key-value pairs with '.$self->command_type_constraint_description($1).' values'; # LOCALIZE } when ('Str') { return 'string'; # LOCALIZE } } return; } 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, bool => $attribute->cmd_is_bool }; $hints{$name} = $names{$name}; } } if ($self->app_fuzzy) { my $length = max(map { length($_) } keys %names); foreach my $l (reverse(1..$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 unless defined $hints{$name}->{bool}; 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_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 && $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); if ($command_meta_class->can('command_usage') && $command_meta_class->command_usage_predicate) { $usage = MooseX::App::Utils::format_text($command_meta_class->command_usage); } } else { $command_name = ''; } unless (defined $usage) { # LOCALIZE $usage = "$caller $command_name "; my @parameter= $self->command_usage_attributes($command_meta_class||$self,'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 $description; $description = $class->meta->command_short_description if $class->meta->can('command_short_description'); $description ||= ''; push(@commands,[$command,$description]); } @commands = sort { $a->[0] cmp $b->[0] } @commands; my @usage; push (@usage,$self->command_usage_header()); 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 intent 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 programm 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 attribute 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. =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_check_attribute my ($error) = $self->command_check_attribute($attribute_meta_class,$value); Checks if a value is valid for the given attribute. Returns a message object if a validation error occurs. =head2 command_type_constraint_description my ($description) = $self->command_type_constraint_description($type_constraint); Returns a human-readable type constraint description. =head2 command_process_attributes 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 =cut MooseX-App-1.22/lib/MooseX/App/Meta/Role/Class/Command.pm000644 000765 000024 00000007551 12147322150 023127 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Class::Command; # ============================================================================ 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_build => 1, ); has 'command_long_description' => ( is => 'rw', isa => 'Maybe[Str]', lazy_build => 1, ); has 'command_usage' => ( is => 'rw', isa => 'Maybe[Str]', lazy_build => 1, ); sub command_short_description_predicate { my ($self) = @_; return $self->_command_description_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_description_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_description_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_description_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) { next unless defined $value; my $meta_attribute = $self->meta->find_attribute_by_name($key); next unless defined $meta_attribute; $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::Command' } #} 1; __END__ =pod =encoding utf8 =head1 NAME MooseX::App::Meta::Role::Class::Command - 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 intent 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 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. =head1 METHODS =head2 _build_command_pod Parses the Pod from the command class. =cutMooseX-App-1.22/lib/MooseX/App/Meta/Role/Class/Simple.pm000644 000765 000024 00000001061 12147322150 022770 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; return $self->command_message( header => 'usage:', body => MooseX::App::Utils::format_text("$caller [long options...] $caller --help")); # LOCALIZE }; 1;MooseX-App-1.22/lib/MooseX/App/Meta/Role/Attribute/Option.pm000644 000765 000024 00000016017 12147322150 023714 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Meta::Role::Attribute::Option; # ============================================================================ use utf8; use 5.010; use namespace::autoclean; use Moose::Role; use Moose::Util::TypeConstraints; subtype 'MooseX::App::Types::CmdAliases' => as 'ArrayRef'; coerce 'MooseX::App::Types::CmdAliases' => from 'Str' => via { [$_] }; subtype 'MooseX::App::Types::CmdTypes' => as enum([qw(proto option parameter)]); 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::CmdAliases', predicate => 'has_cmd_aliases', coerce => 1, ); has 'cmd_split' => ( is => 'rw', isa => union([qw(Str RegexpRef)]), predicate => 'has_cmd_split', ); has 'cmd_position' => ( is => 'rw', isa => 'Int', default => 0, ); no Moose::Util::TypeConstraints; 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_is_bool { 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 1; } return undef } 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'); } } } 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. This documentation is only of interest if you intent to write plugins for MooseX-App. =head1 ACCESSORS =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 first (eg. a config-file option that sets other attribues) =item * parameter - Positional parameter command line value =back =head2 cmd_aliases Arrayref of alternative option names =head2 cmd_tags Extra option tags displayed in the usage information (in brackets) =head2 cmd_position Indicates the order of the parameters =head2 cmd_split Splits the value using the given separator or expression. =head1 METHODS =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_is_bool my $bool = $attribute->cmd_is_bool(); Returns true, false or undef depending on the type constraint and default of the attribute: =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 =cut MooseX-App-1.22/lib/MooseX/App/Message/Block.pm000644 000765 000024 00000003133 12147322150 021323 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Message::Block; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Utils; use Moose::Util::TypeConstraints; subtype 'MooseX::App::Types::MessageString' => as 'Str'; coerce 'MooseX::App::Types::MessageString' => from 'ArrayRef' => via { sprintf(@{$_}) }; no Moose::Util::TypeConstraints; use overload '""' => "stringify"; has 'header' => ( is => 'rw', isa => 'MooseX::App::Types::MessageString', predicate => 'has_header', ); has 'type' => ( is => 'rw', isa => 'Str', default => 'default', ); has 'body' => ( is => 'rw', 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.22/lib/MooseX/App/Message/BlockColor.pm000644 000765 000024 00000002520 12147657426 022342 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); 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.22/lib/MooseX/App/Message/Envelope.pm000644 000765 000024 00000005376 12147322150 022061 0ustar00marosstaff000000 000000 # ============================================================================ package MooseX::App::Message::Envelope; # ============================================================================ use 5.010; use utf8; use namespace::autoclean; use Moose; use MooseX::App::Message::Block; use overload '""' => "stringify"; has 'blocks' => ( is => 'rw', isa => 'ArrayRef[MooseX::App::Message::Block]', traits => ['Array'], handles => { add_block => 'push', list_blocks => 'elements', }, ); around 'BUILDARGS' => sub { my $orig = shift; my $self = shift; my @args = @_; my @blocks; foreach my $element (@args) { if (blessed $element && $element->isa('MooseX::App::Message::Block')) { push(@blocks,$element); } else { push(@blocks,MooseX::App::Message::Block->new( header => $element, )); } } return $self->$orig({ blocks => \@blocks, }); }; sub stringify { my ($self) = @_; my $message = ''; foreach my $block ($self->list_blocks) { $message .= $block->stringify; } return $message; } sub AUTOLOAD { my ($self) = @_; print $self->stringify; 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: MyApp->new_with_command->some_method->only_called_if_successful; =head1 METHODS =head2 stringify Stringifies the messages =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 OVERLOAD Stringification of this object is overloaded. =head2 AUTOLOAD You can call any method on the message class. MooseX-App-1.22/inc/Module/000755 000765 000024 00000000000 12147660746 015665 5ustar00marosstaff000000 000000 MooseX-App-1.22/inc/Module/Install/000755 000765 000024 00000000000 12147660746 017273 5ustar00marosstaff000000 000000 MooseX-App-1.22/inc/Module/Install.pm000644 000765 000024 00000030135 12147660605 017625 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.005; 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.06'; # 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::cwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::cwd(); 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::cwd()) 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 //, $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; # Copyright 2008 - 2012 Adam Kennedy. MooseX-App-1.22/inc/Module/Install/AuthorRequires.pm000644 000765 000024 00000001131 12147660606 022602 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.22/inc/Module/Install/Base.pm000644 000765 000024 00000002147 12147660605 020501 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.06'; } # 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.22/inc/Module/Install/Can.pm000644 000765 000024 00000006157 12147660606 020336 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.06'; @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.22/inc/Module/Install/Fetch.pm000644 000765 000024 00000004627 12147660606 020666 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @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; MooseX-App-1.22/inc/Module/Install/Makefile.pm000644 000765 000024 00000027437 12147660605 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.06'; @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-seperated 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.22/inc/Module/Install/Metadata.pm000644 000765 000024 00000043277 12147660605 021360 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @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 = ( perl => 'http://dev.perl.org/licenses/', apache => 'http://apache.org/licenses/LICENSE-2.0', apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', artistic => 'http://opensource.org/licenses/artistic-license.php', artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', lgpl => 'http://opensource.org/licenses/lgpl-license.php', lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', bsd => 'http://opensource.org/licenses/bsd-license.php', gpl => 'http://opensource.org/licenses/gpl-license.php', gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', mit => 'http://opensource.org/licenses/mit-license.php', mozilla => 'http://opensource.org/licenses/mozilla1.1.php', open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ); 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, 'Artistic and GPL' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'Mozilla Public License' => 'mozilla', 1, 'Q Public License' => 'open_source', 1, 'OpenSSL License' => 'unrestricted', 1, 'SSLeay License' => 'unrestricted', 1, 'zlib License' => 'open_source', 1, 'proprietary' => 'proprietary', 0, ); 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 hashs 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; MooseX-App-1.22/inc/Module/Install/ReadmeFromPod.pm000644 000765 000024 00000006311 12147660605 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.20'; 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.22/inc/Module/Install/Win32.pm000644 000765 000024 00000003403 12147660606 020526 0ustar00marosstaff000000 000000 #line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @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; MooseX-App-1.22/inc/Module/Install/WriteAll.pm000644 000765 000024 00000002376 12147660606 021357 0ustar00marosstaff000000 000000 #line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.06'; @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;