PPIx-Utils-0.003000755001750001750 013460615105 13434 5ustar00grinnzgrinnz000000000000README100644001750001750 353013460615105 14376 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003NAME PPIx::Utils - Utility functions for PPI SYNOPSIS use PPIx::Utils qw(:classification :language :traversal); DESCRIPTION PPIx::Utils is a collection of utility functions for working with PPI documents. The functions are organized into submodules, and may be imported from the appropriate submodule or via this module. These functions were originally from Perl::Critic::Utils and related modules, and have been split off to this distribution for use outside of Perl::Critic. MODULES The import tag :all will import the functions from all modules listed below. PPIx::Utils::Classification Functions related to classification of PPI elements. All functions from this module can be imported with the import tag :classification. PPIx::Utils::Language Functions related to the Perl language. All functions from this module can be imported with the import tag :language. PPIx::Utils::Traversal Functions related to traversal of PPI documents. All functions from this module can be imported with the import tag :traversal. BUGS Report any issues on the public bugtracker. AUTHOR Dan Book Code originally from Perl::Critic::Utils by Jeffrey Ryan Thalhammer , Perl::Critic::Utils::PPI + Perl::Critic::Utils::Perl + PPIx::Utilities::Node by Elliot Shank , and PPIx::Utilities::Statement by Thomas R. Wyant, III COPYRIGHT AND LICENSE This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2009-2010 Thomas R. Wyant, III, 2017 Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. SEE ALSO PPI, Perl::Critic::Utils, PPIx::Utilities Changes100644001750001750 42413460615105 14770 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.0030.003 2019-04-26 10:48:35 EDT - Fix test for corrected parsing in PPI 1.248 (#2) 0.002 2018-08-23 13:32:07 EDT - Add tests and support a special case in get_constant_name_elements_from_declaring_statement (#1) 0.001 2017-06-04 04:13:19 EDT - First release LICENSE100644001750001750 4364113460615105 14552 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003This software is copyright (c) 2017 by Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2017 by Dan Book. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2017 by Dan Book. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End INSTALL100644001750001750 431613460615105 14552 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003This is the Perl distribution PPIx-Utils. Installing PPIx-Utils is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm PPIx::Utils If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan PPIx::Utils ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation PPIx-Utils documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc PPIx::Utils For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html cpanfile100644001750001750 35013460615105 15177 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003requires 'perl' => '5.006'; requires 'B::Keywords' => '1.09'; requires 'Exporter'; requires 'PPI' => '1.250'; requires 'Scalar::Util'; test_requires 'Test::More' => '0.88'; test_requires 'Data::Dumper'; test_requires 'PPI::Dumper'; dist.ini100644001750001750 33413460615105 15141 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003name = PPIx-Utils author = Dan Book license = Perl_5 copyright_holder = Dan Book copyright_year = 2017 [@Author::DBOOK] :version = 0.032 pod_tests = 1 MetaNoIndex.package[] = PPIx::Utils::_Common META.yml100644001750001750 2764113460615105 15020 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003--- abstract: 'Utility functions for PPI' author: - 'Dan Book ' build_requires: Data::Dumper: '0' ExtUtils::MakeMaker: '0' File::Spec: '0' PPI::Dumper: '0' Test::More: '0.88' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: PPIx-Utils no_index: directory: - eg - examples - inc - share - t - xt package: - PPIx::Utils::_Common provides: PPIx::Utils: file: lib/PPIx/Utils.pm version: '0.003' PPIx::Utils::Classification: file: lib/PPIx/Utils/Classification.pm version: '0.003' PPIx::Utils::Language: file: lib/PPIx/Utils/Language.pm version: '0.003' PPIx::Utils::Traversal: file: lib/PPIx/Utils/Traversal.pm version: '0.003' requires: B::Keywords: '1.09' Exporter: '0' PPI: '1.250' Scalar::Util: '0' perl: '5.006' resources: bugtracker: https://github.com/Grinnz/PPIx-Utils/issues homepage: https://github.com/Grinnz/PPIx-Utils repository: https://github.com/Grinnz/PPIx-Utils.git version: '0.003' x_Dist_Zilla: perl: version: '5.028002' plugins: - class: Dist::Zilla::Plugin::GithubMeta name: '@Author::DBOOK/GithubMeta' version: '0.58' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/Readme_Github' version: '0.163250' - class: Dist::Zilla::Plugin::GenerateFile name: '@Author::DBOOK/Generate_Contrib' version: '6.012' - class: Dist::Zilla::Plugin::MetaConfig name: '@Author::DBOOK/MetaConfig' version: '6.012' - class: Dist::Zilla::Plugin::MetaProvides::Package config: Dist::Zilla::Plugin::MetaProvides::Package: finder_objects: - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' include_underscores: 0 Dist::Zilla::Role::MetaProvider::Provider: $Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004' inherit_missing: '1' inherit_version: '1' meta_noindex: '1' Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.006' name: '@Author::DBOOK/MetaProvides::Package' version: '2.004003' - class: Dist::Zilla::Plugin::Prereqs::FromCPANfile name: '@Author::DBOOK/Prereqs::FromCPANfile' version: '0.08' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: git_version: 2.20.1 include_authors: 0 include_releaser: 1 order_by: name paths: [] name: '@Author::DBOOK/Git::Contributors' version: '0.035' - class: Dist::Zilla::Plugin::MetaNoIndex name: '@Author::DBOOK/MetaNoIndex' version: '6.012' - class: Dist::Zilla::Plugin::CheckChangesHasContent name: '@Author::DBOOK/CheckChangesHasContent' version: '0.011' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . name: '@Author::DBOOK/Git::Check' version: '2.046' - class: Dist::Zilla::Plugin::RewriteVersion config: Dist::Zilla::Plugin::RewriteVersion: add_tarball_name: 0 finders: - ':ExecFiles' - ':InstallModules' global: 0 skip_version_provider: 0 name: '@Author::DBOOK/RewriteVersion' version: '0.018' - class: Dist::Zilla::Plugin::NextRelease name: '@Author::DBOOK/NextRelease' version: '6.012' - class: Dist::Zilla::Plugin::CopyFilesFromRelease config: Dist::Zilla::Plugin::CopyFilesFromRelease: filename: - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL match: [] name: '@Author::DBOOK/CopyFilesFromRelease' version: '0.006' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: - / commit_msg: '%v%n%n%c' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - CONTRIBUTING.md - Changes - INSTALL - LICENSE - META.json - Makefile.PL - README.pod - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Commit' version: '2.046' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '0.003' tag_format: '%v' tag_message: '%v' Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Git::Tag' version: '2.046' - class: Dist::Zilla::Plugin::BumpVersionAfterRelease config: Dist::Zilla::Plugin::BumpVersionAfterRelease: finders: - ':ExecFiles' - ':InstallModules' global: 0 munge_makefile_pl: 0 name: '@Author::DBOOK/BumpVersionAfterRelease' version: '0.018' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: 'Bump version' Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: - (?^:^) changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Author::DBOOK/Commit_Version_Bump' version: '2.046' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.20.1 repo_root: . name: '@Author::DBOOK/Git::Push' version: '2.046' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@Author::DBOOK/PodSyntaxTests' version: '6.012' - class: Dist::Zilla::Plugin::PodCoverageTests name: '@Author::DBOOK/PodCoverageTests' version: '6.012' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@Author::DBOOK/Test::ReportPrereqs' version: '0.027' - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - Build.PL - CONTRIBUTING.md - INSTALL - LICENSE - META.json - Makefile.PL - Makefile.PL exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@Author::DBOOK/Git::GatherDir' version: '2.046' - class: Dist::Zilla::Plugin::Regenerate::AfterReleasers config: Dist::Zilla::Plugin::Regenerate::AfterReleasers: plugins: - '@Author::DBOOK/Readme_Github' - '@Author::DBOOK/CopyFilesFromRelease' Dist::Zilla::Role::Regenerator: $Dist::Zilla::Role::Regenerator::VERSION: '0.001001' name: '@Author::DBOOK/Regenerate::AfterReleasers' version: '0.001001' - class: Dist::Zilla::Plugin::PruneCruft name: '@Author::DBOOK/PruneCruft' version: '6.012' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Author::DBOOK/ManifestSkip' version: '6.012' - class: Dist::Zilla::Plugin::MetaYAML name: '@Author::DBOOK/MetaYAML' version: '6.012' - class: Dist::Zilla::Plugin::MetaJSON name: '@Author::DBOOK/MetaJSON' version: '6.012' - class: Dist::Zilla::Plugin::License name: '@Author::DBOOK/License' version: '6.012' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: '@Author::DBOOK/ReadmeAnyFromPod' version: '0.163250' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ExecDir' version: '6.012' - class: Dist::Zilla::Plugin::ShareDir name: '@Author::DBOOK/ShareDir' version: '6.012' - class: Dist::Zilla::Plugin::ExecDir name: '@Author::DBOOK/ScriptDir' version: '6.012' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/MakeMaker' version: '6.012' - class: Dist::Zilla::Plugin::RunExtraTests config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Author::DBOOK/RunExtraTests' version: '0.029' - class: Dist::Zilla::Plugin::InstallGuide config: Dist::Zilla::Role::ModuleMetadata: Module::Metadata: '1.000033' version: '0.006' name: '@Author::DBOOK/InstallGuide' version: '1.200013' - class: Dist::Zilla::Plugin::Manifest name: '@Author::DBOOK/Manifest' version: '6.012' - class: Dist::Zilla::Plugin::TestRelease name: '@Author::DBOOK/TestRelease' version: '6.012' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Author::DBOOK/ConfirmRelease' version: '6.012' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Author::DBOOK/UploadToCPAN' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.012' - class: Dist::Zilla::Plugin::FinderCode name: '@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM' version: '6.012' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '6.012' x_contributors: - 'Dan Book ' - 'Dan Book ' - 'Kang-min Liu ' x_generated_by_perl: v5.28.2 x_serialization_backend: 'YAML::Tiny version 1.73' MANIFEST100644001750001750 77313460615105 14635 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. CONTRIBUTING.md Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/PPIx/Utils.pm lib/PPIx/Utils/Classification.pm lib/PPIx/Utils/Language.pm lib/PPIx/Utils/Traversal.pm lib/PPIx/Utils/_Common.pm t/00-report-prereqs.dd t/00-report-prereqs.t t/split_ppi_node_by_namespace.t t/utils_classification.t t/utils_language.t t/utils_traversal.t xt/author/pod-coverage.t xt/author/pod-syntax.t META.json100644001750001750 4460413460615105 15166 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003{ "abstract" : "Utility functions for PPI", "author" : [ "Dan Book " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "PPIx-Utils", "no_index" : { "directory" : [ "eg", "examples", "inc", "share", "t", "xt" ], "package" : [ "PPIx::Utils::_Common" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Pod::Coverage::TrustPod" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08" } }, "runtime" : { "requires" : { "B::Keywords" : "1.09", "Exporter" : "0", "PPI" : "1.250", "Scalar::Util" : "0", "perl" : "5.006" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "Data::Dumper" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "PPI::Dumper" : "0", "Test::More" : "0.88" } } }, "provides" : { "PPIx::Utils" : { "file" : "lib/PPIx/Utils.pm", "version" : "0.003" }, "PPIx::Utils::Classification" : { "file" : "lib/PPIx/Utils/Classification.pm", "version" : "0.003" }, "PPIx::Utils::Language" : { "file" : "lib/PPIx/Utils/Language.pm", "version" : "0.003" }, "PPIx::Utils::Traversal" : { "file" : "lib/PPIx/Utils/Traversal.pm", "version" : "0.003" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/Grinnz/PPIx-Utils/issues" }, "homepage" : "https://github.com/Grinnz/PPIx-Utils", "repository" : { "type" : "git", "url" : "https://github.com/Grinnz/PPIx-Utils.git", "web" : "https://github.com/Grinnz/PPIx-Utils" } }, "version" : "0.003", "x_Dist_Zilla" : { "perl" : { "version" : "5.028002" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@Author::DBOOK/GithubMeta", "version" : "0.58" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/Readme_Github", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::GenerateFile", "name" : "@Author::DBOOK/Generate_Contrib", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@Author::DBOOK/MetaConfig", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaProvides::Package", "config" : { "Dist::Zilla::Plugin::MetaProvides::Package" : { "finder_objects" : [ { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "include_underscores" : 0 }, "Dist::Zilla::Role::MetaProvider::Provider" : { "$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004", "inherit_missing" : 1, "inherit_version" : 1, "meta_noindex" : 1 }, "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.006" } }, "name" : "@Author::DBOOK/MetaProvides::Package", "version" : "2.004003" }, { "class" : "Dist::Zilla::Plugin::Prereqs::FromCPANfile", "name" : "@Author::DBOOK/Prereqs::FromCPANfile", "version" : "0.08" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "git_version" : "2.20.1", "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [] } }, "name" : "@Author::DBOOK/Git::Contributors", "version" : "0.035" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "@Author::DBOOK/MetaNoIndex", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CheckChangesHasContent", "name" : "@Author::DBOOK/CheckChangesHasContent", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Check", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::RewriteVersion", "config" : { "Dist::Zilla::Plugin::RewriteVersion" : { "add_tarball_name" : 0, "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "skip_version_provider" : 0 } }, "name" : "@Author::DBOOK/RewriteVersion", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@Author::DBOOK/NextRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromRelease", "config" : { "Dist::Zilla::Plugin::CopyFilesFromRelease" : { "filename" : [ "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL" ], "match" : [] } }, "name" : "@Author::DBOOK/CopyFilesFromRelease", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [ "/" ], "commit_msg" : "%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "CONTRIBUTING.md", "Changes", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "README.pod", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Commit", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "0.003", "tag_format" : "%v", "tag_message" : "%v" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Git::Tag", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::BumpVersionAfterRelease", "config" : { "Dist::Zilla::Plugin::BumpVersionAfterRelease" : { "finders" : [ ":ExecFiles", ":InstallModules" ], "global" : 0, "munge_makefile_pl" : 0 } }, "name" : "@Author::DBOOK/BumpVersionAfterRelease", "version" : "0.018" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "Bump version" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [ "(?^:^)" ], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Author::DBOOK/Commit_Version_Bump", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.20.1", "repo_root" : "." } }, "name" : "@Author::DBOOK/Git::Push", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@Author::DBOOK/PodSyntaxTests", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::PodCoverageTests", "name" : "@Author::DBOOK/PodCoverageTests", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@Author::DBOOK/Test::ReportPrereqs", "version" : "0.027" }, { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "Build.PL", "CONTRIBUTING.md", "INSTALL", "LICENSE", "META.json", "Makefile.PL", "Makefile.PL" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@Author::DBOOK/Git::GatherDir", "version" : "2.046" }, { "class" : "Dist::Zilla::Plugin::Regenerate::AfterReleasers", "config" : { "Dist::Zilla::Plugin::Regenerate::AfterReleasers" : { "plugins" : [ "@Author::DBOOK/Readme_Github", "@Author::DBOOK/CopyFilesFromRelease" ] }, "Dist::Zilla::Role::Regenerator" : { "$Dist::Zilla::Role::Regenerator::VERSION" : "0.001001" } }, "name" : "@Author::DBOOK/Regenerate::AfterReleasers", "version" : "0.001001" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Author::DBOOK/PruneCruft", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Author::DBOOK/ManifestSkip", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Author::DBOOK/MetaYAML", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@Author::DBOOK/MetaJSON", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Author::DBOOK/License", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "@Author::DBOOK/ReadmeAnyFromPod", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ExecDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Author::DBOOK/ShareDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Author::DBOOK/ScriptDir", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/MakeMaker", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::RunExtraTests", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Author::DBOOK/RunExtraTests", "version" : "0.029" }, { "class" : "Dist::Zilla::Plugin::InstallGuide", "config" : { "Dist::Zilla::Role::ModuleMetadata" : { "Module::Metadata" : "1.000033", "version" : "0.006" } }, "name" : "@Author::DBOOK/InstallGuide", "version" : "1.200013" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Author::DBOOK/Manifest", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Author::DBOOK/TestRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Author::DBOOK/ConfirmRelease", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Author::DBOOK/UploadToCPAN", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.012" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : "@Author::DBOOK/MetaProvides::Package/AUTOVIV/:InstallModulesPM", "version" : "6.012" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.012" } }, "x_contributors" : [ "Dan Book ", "Dan Book ", "Kang-min Liu " ], "x_generated_by_perl" : "v5.28.2", "x_serialization_backend" : "Cpanel::JSON::XS version 4.11" } Makefile.PL100644001750001750 253013460615105 15467 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "Utility functions for PPI", "AUTHOR" => "Dan Book ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "PPIx-Utils", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.006", "NAME" => "PPIx::Utils", "PREREQ_PM" => { "B::Keywords" => "1.09", "Exporter" => 0, "PPI" => "1.250", "Scalar::Util" => 0 }, "TEST_REQUIRES" => { "Data::Dumper" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "PPI::Dumper" => 0, "Test::More" => "0.88" }, "VERSION" => "0.003", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "B::Keywords" => "1.09", "Data::Dumper" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "PPI" => "1.250", "PPI::Dumper" => 0, "Scalar::Util" => 0, "Test::More" => "0.88" ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); CONTRIBUTING.md100644001750001750 1051613460615105 15771 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003# HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla). This means that many of the usual files you might expect are not in the repository, but are generated at release time. Some generated files are kept in the repository as a convenience (e.g. Build.PL/Makefile.PL and META.json). Generally, **you do not need Dist::Zilla to contribute patches**. You may need Dist::Zilla to create a tarball. See below for guidance. ## Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use [cpanm](https://metacpan.org/pod/cpanm) to satisfy dependencies like this: $ cpanm --installdeps --with-develop . You can also run this command (or any other cpanm command) without installing App::cpanminus first, using the fatpacked `cpanm` script via curl or wget: $ curl -L https://cpanmin.us | perl - --installdeps --with-develop . $ wget -qO - https://cpanmin.us | perl - --installdeps --with-develop . Otherwise, look for either a `cpanfile` or `META.json` file for a list of dependencies to satisfy. ## Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ## Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. ## Installing and using Dist::Zilla [Dist::Zilla](https://metacpan.org/pod/Dist::Zilla) is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ dzil authordeps --missing | cpanm You can use Dist::Zilla to install the distribution's dependencies if you haven't already installed them with cpanm: $ dzil listdeps --missing --develop | cpanm You can instead combine these two steps into one command by installing Dist::Zilla::App::Command::installdeps then running: $ dzil installdeps Once everything is installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil regenerate You can learn more about Dist::Zilla at http://dzil.org/ ## Other notes This distribution maintains the generated `META.json` and either `Makefile.PL` or `Build.PL` in the repository. This allows two things: [Travis CI](https://travis-ci.org/) can build and test the distribution without requiring Dist::Zilla, and the distribution can be installed directly from Github or a local git repository using `cpanm` for testing (again, not requiring Dist::Zilla). $ cpanm git://github.com/Author/Distribution-Name.git $ cd Distribution-Name; cpanm . Contributions are preferred in the form of a Github pull request. See [Using pull requests](https://help.github.com/articles/using-pull-requests/) for further information. You can use the Github issue tracker to report issues without an accompanying patch. # CREDITS This file was adapted from an initial `CONTRIBUTING.mkdn` file from David Golden under the terms of the [CC0](https://creativecommons.org/share-your-work/public-domain/cc0/), with inspiration from the contributing documents from [Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING](https://metacpan.org/pod/Dist::Zilla::Plugin::Author::KENTNL::CONTRIBUTING) and [Dist::Zilla::PluginBundle::Author::ETHER](https://metacpan.org/pod/Dist::Zilla::PluginBundle::Author::ETHER). PPIx000755001750001750 013460615105 14743 5ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/libUtils.pm100644001750001750 471313460615105 16546 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIxpackage PPIx::Utils; use strict; use warnings; use Exporter 'import'; use PPIx::Utils::Classification ':all'; use PPIx::Utils::Language ':all'; use PPIx::Utils::Traversal ':all'; our $VERSION = '0.003'; our @EXPORT_OK = ( @PPIx::Utils::Classification::EXPORT_OK, @PPIx::Utils::Language::EXPORT_OK, @PPIx::Utils::Traversal::EXPORT_OK, ); our %EXPORT_TAGS = ( all => [@EXPORT_OK], classification => [@PPIx::Utils::Classification::EXPORT_OK], language => [@PPIx::Utils::Language::EXPORT_OK], traversal => [@PPIx::Utils::Traversal::EXPORT_OK], ); 1; =head1 NAME PPIx::Utils - Utility functions for PPI =head1 SYNOPSIS use PPIx::Utils qw(:classification :language :traversal); =head1 DESCRIPTION C is a collection of utility functions for working with L documents. The functions are organized into submodules, and may be imported from the appropriate submodule or via this module. These functions were originally from L and related modules, and have been split off to this distribution for use outside of L. =head1 MODULES The import tag C<:all> will import the functions from all modules listed below. =head2 L Functions related to classification of L elements. All functions from this module can be imported with the import tag C<:classification>. =head2 L Functions related to the Perl language. All functions from this module can be imported with the import tag C<:language>. =head2 L Functions related to traversal of L documents. All functions from this module can be imported with the import tag C<:traversal>. =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book Code originally from L by Jeffrey Ryan Thalhammer , L + L + L by Elliot Shank , and L by Thomas R. Wyant, III =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2009-2010 Thomas R. Wyant, III, 2017 Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 SEE ALSO L, L, L t000755001750001750 013460615105 13620 5ustar00grinnzgrinnz000000000000PPIx-Utils-0.003utils_language.t100644001750001750 173613460615105 17157 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/t# Tests from Perl::Critic::Utils t/05_utils.t use strict; use warnings; use PPI::Document; use PPIx::Utils::Language ':all'; use Test::More; test_precedence_of(); sub make_doc { my $code = shift; return PPI::Document->new(ref $code ? $code : \$code); } sub test_precedence_of { cmp_ok( precedence_of(q<*>), q[<], precedence_of(q<+>), 'Precedence' ); my $code1 = '8 + 5'; my $doc1 = make_doc($code1); my $op1 = $doc1->find_first('Token::Operator'); my $code2 = '7 * 5'; my $doc2 = make_doc($code2); my $op2 = $doc2->find_first('Token::Operator'); cmp_ok( precedence_of($op2), '<', precedence_of($op1), 'Precedence (PPI)' ); return; } # Tests from Perl::Critic::Utils::Perl t/05_utils_perl.t { foreach my $sigil ( q<>, qw< $ @ % * & > ) { my $symbol = "${sigil}foo"; is( symbol_without_sigil($symbol), 'foo', "symbol_without_sigil($symbol)", ); } } done_testing; utils_traversal.t100644001750001750 443713460615105 17400 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/t# Tests from Perl::Critic::Utils t/05_utils.t use strict; use warnings; use PPI::Document; use PPIx::Utils::Traversal ':all'; use Test::More; test_first_arg(); test_parse_arg_list(); test_get_constant_name_elements_from_declaring_statement(); sub test_first_arg { my @tests = ( q{eval { some_code() };} => q{{ some_code() }}, q{eval( {some_code() } );} => q{{some_code() }}, q{eval();} => undef, ); for (my $i = 0; $i < @tests; $i += 2) { my $code = $tests[$i]; my $expect = $tests[$i+1]; my $doc = PPI::Document->new(\$code); my $got = first_arg($doc->first_token()); is($got ? "$got" : undef, $expect, 'first_arg - '.$code); } return; } sub test_parse_arg_list { my @tests = ( [ q/foo($bar, 'baz', 1)/ => [ [ q<$bar> ], [ q<'baz'> ], [ q<1> ], ] ], [ q/foo( { bar => 1 }, { bar => 1 }, 'blah' )/ => [ [ '{ bar => 1 }' ], [ '{ bar => 1 }' ], [ q<'blah'> ], ], ], [ q/foo( { bar() }, {}, 'blah' )/ => [ [ q<{ bar() }> ], [ qw< {} > ], [ q<'blah'> ], ], ], ); foreach my $test (@tests) { my ($code, $expected) = @{ $test }; my $document = PPI::Document->new( \$code ); my @got = parse_arg_list( $document->first_token() ); is_deeply( \@got, $expected, "parse_arg_list: $code" ); } return; } sub test_get_constant_name_elements_from_declaring_statement { my @tests = ( ['use constant FOO => 1;', ['FOO']], ['use constant { FOO => 1 };', ['FOO']], ['use constant { FOO => 1, BAR => 2 };', ['FOO', 'BAR']], ['use constant +{ FOO => 1, BAR => 2 };', ['FOO', 'BAR']], ); foreach my $test (@tests) { my ($code, $expected) = @{ $test }; my $document = PPI::Document->new( \$code ); my $st = $document->find_first('PPI::Statement::Include'); my @got = get_constant_name_elements_from_declaring_statement( $st ); is_deeply( \@got, $expected, "get_constant_name_elements_from_declaring_statement: $code" ); } return; } done_testing; 00-report-prereqs.t100644001750001750 1342613460615105 17402 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: author000755001750001750 013460615105 15312 5ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/xtpod-syntax.t100644001750001750 25213460615105 17724 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644001750001750 274413460615105 17507 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Pod::Coverage::TrustPod' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08' } }, 'runtime' => { 'requires' => { 'B::Keywords' => '1.09', 'Exporter' => '0', 'PPI' => '1.250', 'Scalar::Util' => '0', 'perl' => '5.006' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'Data::Dumper' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'PPI::Dumper' => '0', 'Test::More' => '0.88' } } }; $x; }pod-coverage.t100644001750001750 33413460615105 20172 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); utils_classification.t100644001750001750 4254413460615105 20411 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/t# Tests from Perl::Critic::Utils t/05_utils.t use strict; use warnings; use Carp 'confess'; use PPI::Document; use PPIx::Utils::Classification ':all'; use Test::More; test_is_assignment_operator(); test_is_hash_key(); test_is_perl_builtin(); test_is_perl_global(); test_is_subroutine_name(); test_is_function_call(); test_is_unchecked_call(); sub make_doc { my $code = shift; return PPI::Document->new(ref $code ? $code : \$code); } sub test_is_assignment_operator { for ( qw( = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //= ) ) { is( is_assignment_operator($_), 1, "$_ is an assignment operator" ); } for ( qw( == != =~ >= <= + - * / % x bogus= ) ) { is( !!is_assignment_operator($_), q{}, "$_ is not an assignment operator" ); } return; } sub test_is_hash_key { my $code = 'sub foo { return $h1{bar}, $h2->{baz}, $h3->{ nuts() } }'; my $doc = PPI::Document->new(\$code); my @words = @{$doc->find('PPI::Token::Word')}; my @expect = ( ['sub', undef], ['foo', undef], ['return', undef], ['bar', 1], ['baz', 1], ['nuts', undef], ); is(scalar @words, scalar @expect, 'is_hash_key count'); for my $i (0 .. $#expect) { is($words[$i], $expect[$i][0], 'is_hash_key word'); is( !!is_hash_key($words[$i]), !!$expect[$i][1], 'is_hash_key boolean' ); } return; } sub test_is_perl_builtin { ok( is_perl_builtin('print'), 'Is perl builtin function' ); ok( !is_perl_builtin('foobar'), 'Is not perl builtin function' ); my $code = 'sub print {}'; my $doc = make_doc( $code ); my $sub = $doc->find_first('Statement::Sub'); ok( is_perl_builtin($sub), 'Is perl builtin function (PPI)' ); $code = 'sub foobar {}'; $doc = make_doc( $code ); $sub = $doc->find_first('Statement::Sub'); ok( !is_perl_builtin($sub), 'Is not perl builtin function (PPI)' ); return; } sub test_is_perl_global { ok( is_perl_global('$OSNAME'), '$OSNAME is a perl global var' ); ok( is_perl_global('*STDOUT'), '*STDOUT is a perl global var' ); ok( !is_perl_global('%FOOBAR'), '%FOOBAR is a not perl global var' ); my $code = '$OSNAME'; my $doc = make_doc($code); my $var = $doc->find_first('Token::Symbol'); ok( is_perl_global($var), '$OSNAME is perl a global var (PPI)' ); $code = '*STDOUT'; $doc = make_doc($code); $var = $doc->find_first('Token::Symbol'); ok( is_perl_global($var), '*STDOUT is perl a global var (PPI)' ); $code = '%FOOBAR'; $doc = make_doc($code); $var = $doc->find_first('Token::Symbol'); ok( !is_perl_global($var), '%FOOBAR is not a perl global var (PPI)' ); $code = q[$\\]; $doc = make_doc($code); $var = $doc->find_first('Token::Symbol'); ok( is_perl_global($var), "$code is a perl global var (PPI)" ); return; } sub test_is_subroutine_name { my $code = 'sub foo {}'; my $doc = make_doc( $code ); my $word = $doc->find_first( sub { $_[1] eq 'foo' } ); ok( is_subroutine_name( $word ), 'Is a subroutine name'); $code = '$bar = foo()'; $doc = make_doc( $code ); $word = $doc->find_first( sub { $_[1] eq 'foo' } ); ok( !is_subroutine_name( $word ), 'Is not a subroutine name'); return; } sub test_is_function_call { my $code = 'sub foo{}'; my $doc = PPI::Document->new( \$code ); my $words = $doc->find('PPI::Token::Word'); is(scalar @{$words}, 2, 'count PPI::Token::Words'); is((scalar grep {is_function_call($_)} @{$words}), 0, 'is_function_call'); return; } sub test_is_unchecked_call { my @trials = ( # just an obvious failure to check the return value { code => q[ open( $fh, $mode, $filename ); ], pass => 1, }, # check the value with a trailing conditional { code => q[ open( $fh, $mode, $filename ) or confess 'unable to open'; ], pass => 0, }, # assign the return value to a variable (and assume that it's checked later) { code => q[ my $error = open( $fh, $mode, $filename ); ], pass => 0, }, # the system call is in a conditional { code => q[ return $EMPTY if not open my $fh, '<', $file; ], pass => 0, }, # open call in list context, checked with 'not' { code => q[ return $EMPTY if not ( open my $fh, '<', $file ); ], pass => 0, }, # just putting the system call in a list context doesn't mean the return value is checked { code => q[ ( open my $fh, '<', $file ); ], pass => 1, }, # Check Fatal. { code => q[ use Fatal qw< open >; open( $fh, $mode, $filename ); ], pass => 0, }, { code => q[ use Fatal qw< open >; ( open my $fh, '<', $file ); ], pass => 0, }, # Check Fatal::Exception. { code => q[ use Fatal::Exception 'Exception::System' => qw< open close >; open( $fh, $mode, $filename ); ], pass => 0, }, { code => q[ use Fatal::Exception 'Exception::System' => qw< open close >; ( open my $fh, '<', $file ); ], pass => 0, }, # Check autodie. { code => q[ use autodie; open( $fh, $mode, $filename ); ], pass => 0, }, { code => q[ use autodie qw< :io >; open( $fh, $mode, $filename ); ], pass => 0, }, { code => q[ use autodie qw< :system >; ( open my $fh, '<', $file ); ], pass => 1, }, { code => q[ use autodie qw< :system :file >; ( open my $fh, '<', $file ); ], pass => 0, }, ); foreach my $trial ( @trials ) { my $code = $trial->{'code'}; my $doc = make_doc( $code ); my $statement = $doc->find_first( sub { $_[1] eq 'open' } ); if ( $trial->{'pass'} ) { ok( is_unchecked_call( $statement ), qq ); } else { ok( ! is_unchecked_call( $statement ), qq ); } } return; } # Tests from Perl::Critic::Utils::PPI t/05_utils_ppi.t use PPI::Document qw< >; use PPI::Statement::Break qw< >; use PPI::Statement::Compound qw< >; use PPI::Statement::Data qw< >; use PPI::Statement::End qw< >; use PPI::Statement::Expression qw< >; use PPI::Statement::Include qw< >; use PPI::Statement::Null qw< >; use PPI::Statement::Package qw< >; use PPI::Statement::Scheduled qw< >; use PPI::Statement::Sub qw< >; use PPI::Statement::Unknown qw< >; use PPI::Statement::UnmatchedBrace qw< >; use PPI::Statement::Variable qw< >; use PPI::Statement qw< >; use PPI::Token::Word qw< >; my @ppi_statement_classes = qw{ PPI::Statement PPI::Statement::Package PPI::Statement::Include PPI::Statement::Sub PPI::Statement::Scheduled PPI::Statement::Compound PPI::Statement::Break PPI::Statement::Data PPI::Statement::End PPI::Statement::Expression PPI::Statement::Variable PPI::Statement::Null PPI::Statement::UnmatchedBrace PPI::Statement::Unknown }; my %instances = map { $_ => $_->new() } @ppi_statement_classes; $instances{'PPI::Token::Word'} = PPI::Token::Word->new('foo'); #----------------------------------------------------------------------------- # is_ppi_expression_or_generic_statement tests { ok( ! is_ppi_expression_or_generic_statement( undef ), 'is_ppi_expression_or_generic_statement( undef )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Token::Word'} ), 'is_ppi_expression_or_generic_statement( PPI::Token::Word )', ); ok( is_ppi_expression_or_generic_statement( $instances{'PPI::Statement'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Package'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Package )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Include'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Include )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Sub'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Sub )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Scheduled'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Scheduled )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Compound'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Compound )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Break'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Break )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Data'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Data )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::End'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::End )', ); ok( is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Expression'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Expression )', ); ok( is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Variable'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Variable )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Null'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Null )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::UnmatchedBrace'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::UnmatchedBrace )', ); ok( ! is_ppi_expression_or_generic_statement( $instances{'PPI::Statement::Unknown'} ), 'is_ppi_expression_or_generic_statement( PPI::Statement::Unknown )', ); } #----------------------------------------------------------------------------- # is_ppi_generic_statement tests { ok( ! is_ppi_generic_statement( undef ), 'is_ppi_generic_statement( undef )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Token::Word'} ), 'is_ppi_generic_statement( PPI::Token::Word )', ); ok( is_ppi_generic_statement( $instances{'PPI::Statement'} ), 'is_ppi_generic_statement( PPI::Statement )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Package'} ), 'is_ppi_generic_statement( PPI::Statement::Package )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Include'} ), 'is_ppi_generic_statement( PPI::Statement::Include )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Sub'} ), 'is_ppi_generic_statement( PPI::Statement::Sub )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Scheduled'} ), 'is_ppi_generic_statement( PPI::Statement::Scheduled )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Compound'} ), 'is_ppi_generic_statement( PPI::Statement::Compound )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Break'} ), 'is_ppi_generic_statement( PPI::Statement::Break )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Data'} ), 'is_ppi_generic_statement( PPI::Statement::Data )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::End'} ), 'is_ppi_generic_statement( PPI::Statement::End )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Expression'} ), 'is_ppi_generic_statement( PPI::Statement::Expression )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Variable'} ), 'is_ppi_generic_statement( PPI::Statement::Variable )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Null'} ), 'is_ppi_generic_statement( PPI::Statement::Null )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::UnmatchedBrace'} ), 'is_ppi_generic_statement( PPI::Statement::UnmatchedBrace )', ); ok( ! is_ppi_generic_statement( $instances{'PPI::Statement::Unknown'} ), 'is_ppi_generic_statement( PPI::Statement::Unknown )', ); } #----------------------------------------------------------------------------- # is_ppi_statement_subclass tests { ok( ! is_ppi_statement_subclass( undef ), 'is_ppi_statement_subclass( undef )', ); ok( ! is_ppi_statement_subclass( $instances{'PPI::Token::Word'} ), 'is_ppi_statement_subclass( PPI::Token::Word )', ); ok( ! is_ppi_statement_subclass( $instances{'PPI::Statement'} ), 'is_ppi_statement_subclass( PPI::Statement )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Package'} ), 'is_ppi_statement_subclass( PPI::Statement::Package )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Include'} ), 'is_ppi_statement_subclass( PPI::Statement::Include )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Sub'} ), 'is_ppi_statement_subclass( PPI::Statement::Sub )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Scheduled'} ), 'is_ppi_statement_subclass( PPI::Statement::Scheduled )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Compound'} ), 'is_ppi_statement_subclass( PPI::Statement::Compound )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Break'} ), 'is_ppi_statement_subclass( PPI::Statement::Break )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Data'} ), 'is_ppi_statement_subclass( PPI::Statement::Data )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::End'} ), 'is_ppi_statement_subclass( PPI::Statement::End )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Expression'} ), 'is_ppi_statement_subclass( PPI::Statement::Expression )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Variable'} ), 'is_ppi_statement_subclass( PPI::Statement::Variable )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Null'} ), 'is_ppi_statement_subclass( PPI::Statement::Null )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::UnmatchedBrace'} ), 'is_ppi_statement_subclass( PPI::Statement::UnmatchedBrace )', ); ok( is_ppi_statement_subclass( $instances{'PPI::Statement::Unknown'} ), 'is_ppi_statement_subclass( PPI::Statement::Unknown )', ); } #----------------------------------------------------------------------------- # is_subroutine_declaration() tests { my $test = sub { my ($code, $result) = @_; my $doc; my $input; if (defined $code) { $doc = PPI::Document->new(\$code, readonly => 1); } if (defined $doc) { $input = $doc->first_element(); } my $name = defined $code ? $code : ''; local $Test::Builder::Level = $Test::Builder::Level + 1; is( ! ! is_subroutine_declaration( $input ), ! ! $result, "is_subroutine_declaration(): $name" ); return; }; $test->('sub {};' => 1); $test->('sub {}' => 1); $test->('{}' => 0); $test->(undef, 0); $test->('{ sub foo {} }' => 0); $test->('sub foo;' => 1); } #----------------------------------------------------------------------------- # is_in_subroutine() tests { my $test = sub { my ($code, $transform, $result) = @_; my $doc; my $input; if (defined $code) { $doc = PPI::Document->new(\$code, readonly => 1); } if (defined $doc) { $input = $transform->($doc); } my $name = defined $code ? $code : ''; local $Test::Builder::Level = $Test::Builder::Level + 1; is( ! ! is_in_subroutine( $input ), ! ! $result, "is_in_subroutine(): $name" ); return; }; $test->(undef, sub {}, 0); $test->('my $foo = 42', sub {}, 0); $test->( 'sub foo { my $foo = 42 }', sub { my ($doc) = @_; $doc->find_first('PPI::Statement::Variable'); }, 1, ); $test->( 'sub { my $foo = 42 };', sub { my ($doc) = @_; $doc->find_first('PPI::Statement::Variable'); }, 1, ); $test->( '{ my $foo = 42 };', sub { my ($doc) = @_; $doc->find_first('PPI::Statement::Variable'); }, 0, ); } done_testing; Utils000755001750001750 013460615105 16043 5ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIx_Common.pm100644001750001750 230113460615105 20124 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIx/Utilspackage PPIx::Utils::_Common; # See the README of this distribution for copyright and license information. use strict; use warnings; use Exporter 'import'; use Scalar::Util 'blessed'; our $VERSION = '0.003'; our @EXPORT_OK = qw( is_ppi_expression_or_generic_statement is_ppi_simple_statement ); our %EXPORT_TAGS = (all => [@EXPORT_OK]); # From Perl::Critic::Utils::PPI sub is_ppi_expression_or_generic_statement { my $element = shift; return undef if not $element; return undef if not $element->isa('PPI::Statement'); return 1 if $element->isa('PPI::Statement::Expression'); my $element_class = blessed($element); return undef if not $element_class; return $element_class eq 'PPI::Statement'; } my %SIMPLE_STATEMENT_CLASS = map { $_ => 1 } qw< PPI::Statement PPI::Statement::Break PPI::Statement::Include PPI::Statement::Null PPI::Statement::Package PPI::Statement::Variable >; sub is_ppi_simple_statement { my $element = shift or return undef; my $element_class = blessed( $element ) or return undef; return $SIMPLE_STATEMENT_CLASS{ $element_class }; } # End from Perl::Critic::Utils::PPI 1; =for Pod::Coverage *EVERYTHING* =cut Language.pm100644001750001750 725213460615105 20272 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIx/Utilspackage PPIx::Utils::Language; use strict; use warnings; use Exporter 'import'; our $VERSION = '0.003'; our @EXPORT_OK = qw(precedence_of symbol_without_sigil); our %EXPORT_TAGS = (all => [@EXPORT_OK]); # From Perl::Critic::Utils my %PRECEDENCE_OF = ( '->' => 1, '++' => 2, '--' => 2, '**' => 3, '!' => 4, '~' => 4, '\\' => 4, '=~' => 5, '!~' => 5, '*' => 6, '/' => 6, '%' => 6, 'x' => 6, '+' => 7, '-' => 7, '.' => 7, '<<' => 8, '>>' => 8, '-R' => 9, '-W' => 9, '-X' => 9, '-r' => 9, '-w' => 9, '-x' => 9, '-e' => 9, '-O' => 9, '-o' => 9, '-z' => 9, '-s' => 9, '-M' => 9, '-A' => 9, '-C' => 9, '-S' => 9, '-c' => 9, '-b' => 9, '-f' => 9, '-d' => 9, '-p' => 9, '-l' => 9, '-u' => 9, '-g' => 9, '-k' => 9, '-t' => 9, '-T' => 9, '-B' => 9, '<' => 10, '>' => 10, '<=' => 10, '>=' => 10, 'lt' => 10, 'gt' => 10, 'le' => 10, 'ge' => 10, '==' => 11, '!=' => 11, '<=>' => 11, 'eq' => 11, 'ne' => 11, 'cmp' => 11, '~~' => 11, '&' => 12, '|' => 13, '^' => 13, '&&' => 14, '//' => 15, '||' => 15, '..' => 16, '...' => 17, '?' => 18, ':' => 18, '=' => 19, '+=' => 19, '-=' => 19, '*=' => 19, '/=' => 19, '%=' => 19, '||=' => 19, '&&=' => 19, '|=' => 19, '&=' => 19, '**=' => 19, 'x=' => 19, '.=' => 19, '^=' => 19, '<<=' => 19, '>>=' => 19, '//=' => 19, ',' => 20, '=>' => 20, 'not' => 22, 'and' => 23, 'or' => 24, 'xor' => 24, ); sub precedence_of { my $elem = shift; return undef if !$elem; return $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem }; } # End from Perl::Critic::Utils # From Perl::Critic::Utils::Perl sub symbol_without_sigil { my ($symbol) = @_; (my $without_sigil = $symbol) =~ s< \A [\$@%*&] ><>x; return $without_sigil; } # End from Perl::Critic::Utils::Perl 1; =head1 NAME PPIx::Utils::Language - Utility functions for PPI related to the Perl language =head1 SYNOPSIS use PPIx::Utils::Language ':all'; =head1 DESCRIPTION This package is a component of L that contains functions related to aspects of the Perl language. =head1 FUNCTIONS All functions can be imported by name, or with the tag C<:all>. =head2 precedence_of my $precedence = precedence_of($element); Given a L or a string, returns the precedence of the operator, where 1 is the highest precedence. Returns undef if the precedence can't be determined (which is usually because it is not an operator). =head2 symbol_without_sigil my $name = symbol_without_sigil($symbol); Returns the name of the specified symbol with any sigil at the front. The parameter can be a vanilla Perl string or a L. =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book Code originally from L by Jeffrey Ryan Thalhammer and L by Elliot Shank =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2017 Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 SEE ALSO L, L Traversal.pm100644001750001750 4304013460615105 20525 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIx/Utilspackage PPIx::Utils::Traversal; use strict; use warnings; use Exporter 'import'; use PPI::Token::Quote::Single; use PPI::Document::Fragment; use Scalar::Util 'refaddr'; use PPIx::Utils::Language qw(precedence_of); use PPIx::Utils::_Common qw( is_ppi_expression_or_generic_statement is_ppi_simple_statement ); our $VERSION = '0.003'; our @EXPORT_OK = qw( first_arg parse_arg_list split_nodes_on_comma get_next_element_in_same_simple_statement get_previous_module_used_on_same_line get_constant_name_elements_from_declaring_statement split_ppi_node_by_namespace ); our %EXPORT_TAGS = (all => [@EXPORT_OK]); # From Perl::Critic::Utils my $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST = precedence_of( 'not' ); sub first_arg { my $elem = shift; my $sib = $elem->snext_sibling(); return undef if !$sib; if ( $sib->isa('PPI::Structure::List') ) { my $expr = $sib->schild(0); return undef if !$expr; return $expr->isa('PPI::Statement') ? $expr->schild(0) : $expr; } return $sib; } sub parse_arg_list { my $elem = shift; my $sib = $elem->snext_sibling(); return() if !$sib; if ( $sib->isa('PPI::Structure::List') ) { #Pull siblings from list my @list_contents = $sib->schildren(); return() if not @list_contents; my @list_expressions; foreach my $item (@list_contents) { if ( is_ppi_expression_or_generic_statement($item) ) { push @list_expressions, split_nodes_on_comma( $item->schildren() ); } else { push @list_expressions, $item; } } return @list_expressions; } else { #Gather up remaining nodes in the statement my $iter = $elem; my @arg_list = (); while ($iter = $iter->snext_sibling() ) { last if $iter->isa('PPI::Token::Structure') and $iter eq ';'; last if $iter->isa('PPI::Token::Operator') and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= precedence_of( $iter ); push @arg_list, $iter; } return split_nodes_on_comma( @arg_list ); } } sub split_nodes_on_comma { my @nodes = @_; my $i = 0; my @node_stacks; for my $node (@nodes) { if ( $node->isa('PPI::Token::Operator') and ($node eq ',' or $node eq '=>') ) { if (@node_stacks) { $i++; #Move forward to next 'node stack' } next; } elsif ( $node->isa('PPI::Token::QuoteLike::Words' )) { my $section = $node->{sections}->[0]; my @words = split ' ', substr $node->content, $section->{position}, $section->{size}; my $loc = $node->location; for my $word (@words) { my $token = PPI::Token::Quote::Single->new(q{'} . $word . q{'}); $token->{_location} = $loc; push @{ $node_stacks[$i++] }, $token; } next; } push @{ $node_stacks[$i] }, $node; } return @node_stacks; } # From Perl::Critic::Utils::PPI sub get_next_element_in_same_simple_statement { my $element = shift or return undef; while ( $element and ( not is_ppi_simple_statement( $element ) or $element->parent() and $element->parent()->isa( 'PPI::Structure::List' ) ) ) { my $next; $next = $element->snext_sibling() and return $next; $element = $element->parent(); } return undef; } sub get_previous_module_used_on_same_line { my $element = shift or return undef; my ( $line ) = @{ $element->location() || []}; while (not is_ppi_simple_statement( $element )) { $element = $element->parent() or return undef; } while ( $element = $element->sprevious_sibling() ) { ( @{ $element->location() || []} )[0] == $line or return undef; $element->isa( 'PPI::Statement::Include' ) and return $element->schild( 1 ); } return undef; } # End from Perl::Critic::Utils # From PPIx::Utilities::Statement my %IS_COMMA = ( q[,] => 1, q[=>] => 1 ); sub get_constant_name_elements_from_declaring_statement { my ($element) = @_; return() if not $element; return() if not $element->isa('PPI::Statement'); if ( $element->isa('PPI::Statement::Include') ) { my $pragma; if ( $pragma = $element->pragma() and $pragma eq 'constant' ) { return _get_constant_names_from_constant_pragma($element); } } elsif ( not $element->specialized() and $element->schildren() > 2 ) { my $supposed_constant_function = $element->schild(0)->content(); my $declaring_scope = $element->schild(1)->content(); if ( ( $supposed_constant_function eq 'const' or $supposed_constant_function =~ m< \A Readonly \b >x ) and ($declaring_scope eq 'our' or $declaring_scope eq 'my') ) { return ($element->schild(2)); } } return(); } sub _get_constant_names_from_constant_pragma { my ($include) = @_; my @arguments = $include->arguments() or return(); my $follower = $arguments[0]; return() if not defined $follower; if ($follower->isa('PPI::Token::Operator') && $follower->content eq '+') { $follower = $arguments[1]; return() if not defined $follower; } # We test for a 'PPI::Structure::Block' in the following because some # versions of PPI parse the last element of 'use constant { ONE => 1, TWO # => 2 }' as a block rather than a constructor. As of PPI 1.206, PPI # handles the above correctly, but still blows it on 'use constant 1.16 { # ONE => 1, TWO => 2 }'. if ( $follower->isa( 'PPI::Structure::Constructor' ) or $follower->isa( 'PPI::Structure::Block' ) ) { my $statement = $follower->schild( 0 ) or return(); $statement->isa( 'PPI::Statement' ) or return(); my @elements; my $inx = 0; foreach my $child ( $statement->schildren() ) { if (not $inx % 2) { push @{ $elements[ $inx ] ||= [] }, $child; } if ( $IS_COMMA{ $child->content() } ) { $inx++; } } return map { ( $_ and @{$_} == 2 and '=>' eq $_->[1]->content() and $_->[0]->isa( 'PPI::Token::Word' ) ) ? $_->[0] : () } @elements; } else { return ($follower); } return ($follower); } # End from PPIx::Utilities::Statement # From PPIx::Utilities::Node sub split_ppi_node_by_namespace { my ($node) = @_; # Ensure we don't screw up the original. $node = $node->clone(); # We want to make sure that we have locations prior to things being split # up, if we can, but don't worry about it if we don't. eval { $node->location(); }; if ( my $single_namespace = _split_ppi_node_by_namespace_single($node) ) { return $single_namespace; } my %nodes_by_namespace; _split_ppi_node_by_namespace_in_lexical_scope( $node, 'main', undef, \%nodes_by_namespace, ); return \%nodes_by_namespace; } # Handle the case where there's only one. sub _split_ppi_node_by_namespace_single { my ($node) = @_; my $package_statements = $node->find('PPI::Statement::Package'); if ( not $package_statements or not @{$package_statements} ) { return { main => [$node] }; } if (@{$package_statements} == 1) { my $package_statement = $package_statements->[0]; my $package_address = refaddr $package_statement; # Yes, child and not schild. my $first_child = $node->child(0); if ( $package_address == refaddr $node or $first_child and $package_address == refaddr $first_child ) { return { $package_statement->namespace() => [$node] }; } } return undef; } sub _split_ppi_node_by_namespace_in_lexical_scope { my ($node, $initial_namespace, $initial_fragment, $nodes_by_namespace) = @_; my %scope_fragments_by_namespace; # I certainly hope a value isn't going to exist at address 0. my $initial_fragment_address = refaddr $initial_fragment || 0; my ($namespace, $fragment) = ($initial_namespace, $initial_fragment); if ($initial_fragment) { $scope_fragments_by_namespace{$namespace} = $initial_fragment; } foreach my $child ( $node->children() ) { if ( $child->isa('PPI::Statement::Package') ) { if ($fragment) { _push_fragment($nodes_by_namespace, $namespace, $fragment); undef $fragment; } $namespace = $child->namespace(); } elsif ( $child->isa('PPI::Statement::Compound') or $child->isa('PPI::Statement::Given') or $child->isa('PPI::Statement::When') ) { my $block; my @components = $child->children(); while (not $block and my $component = shift @components) { if ( $component->isa('PPI::Structure::Block') ) { $block = $component; } } if ($block) { if (not $fragment) { $fragment = _get_fragment_for_split_ppi_node( $nodes_by_namespace, \%scope_fragments_by_namespace, $namespace, ); } _split_ppi_node_by_namespace_in_lexical_scope( $block, $namespace, $fragment, $nodes_by_namespace, ); } } $fragment = _get_fragment_for_split_ppi_node( $nodes_by_namespace, \%scope_fragments_by_namespace, $namespace, ); if ($initial_fragment_address != refaddr $fragment) { # Need to fix these to use exceptions. Thankfully the P::C tests # will insist that this happens. $child->remove() or die 'Could not remove child from parent.'; $fragment->add_element($child) or die 'Could not add child to fragment.'; } } return; } sub _get_fragment_for_split_ppi_node { my ($nodes_by_namespace, $scope_fragments_by_namespace, $namespace) = @_; my $fragment; if ( not $fragment = $scope_fragments_by_namespace->{$namespace} ) { $fragment = PPI::Document::Fragment->new(); $scope_fragments_by_namespace->{$namespace} = $fragment; _push_fragment($nodes_by_namespace, $namespace, $fragment); } return $fragment; } # Due to $fragment being passed into recursive calls to # _split_ppi_node_by_namespace_in_lexical_scope(), we can end up attempting to # put the same fragment into a namespace's nodes multiple times. sub _push_fragment { my ($nodes_by_namespace, $namespace, $fragment) = @_; my $nodes = $nodes_by_namespace->{$namespace} ||= []; if (not @{$nodes} or refaddr $nodes->[-1] != refaddr $fragment) { push @{$nodes}, $fragment; } return; } # End from PPIx::Utilities::Node 1; =head1 NAME PPIx::Utils::Traversal - Utility functions for traversing PPI documents =head1 SYNOPSIS use PPIx::Utils::Traversal ':all'; =head1 DESCRIPTION This package is a component of L that contains functions for traversal of L documents. =head1 FUNCTIONS All functions can be imported by name, or with the tag C<:all>. =head2 first_arg my $first_arg = first_arg($element); Given a L that is presumed to be a function call (which is usually a L), return the first argument. This is similar of L and follows the same logic. Note that for the code: int($x + 0.5) this function will return just the C<$x>, not the whole expression. This is different from the behavior of L. Another caveat is: int(($x + $y) + 0.5) which returns C<($x + $y)> as a L instance. =head2 parse_arg_list my @args = parse_arg_list($element); Given a L that is presumed to be a function call (which is usually a L), splits the argument expressions into arrays of tokens. Returns a list containing references to each of those arrays. This is useful because parentheses are optional when calling a function, and PPI parses them very differently. So this method is a poor-man's parse tree of PPI nodes. It's not bullet-proof because it doesn't respect precedence. In general, I don't like the way this function works, so don't count on it to be stable (or even present). =head2 split_nodes_on_comma my @args = split_nodes_on_comma(@nodes); This has the same return type as L but expects to be passed the nodes that represent the interior of a list, like: 'foo', 1, 2, 'bar' =head2 get_next_element_in_same_simple_statement my $element = get_next_element_in_same_simple_statement($element); Given a L, this subroutine returns the next element in the same simple statement as defined by L. If no next element can be found, this subroutine simply returns C. If the $element is undefined or unblessed, we simply return C. If the $element satisfies L, we return C, B it has a parent which is a L. If the $element is the last significant element in its L, we replace it with its parent and iterate again. Otherwise, we return C<< $element->snext_sibling() >>. =head2 get_previous_module_used_on_same_line my $element = get_previous_module_used_on_same_line($element); Given a L, returns the L representing the name of the module included by the previous C or C on the same line as the $element. If none is found, simply returns C. For example, with the line use version; our $VERSION = ...; given the L instance for C<$VERSION>, this will return "version". If the given element is in a C or , the return is from the previous C or C on the line, if any. =head2 get_constant_name_elements_from_declaring_statement my @constants = get_constant_name_elements_from_declaring_statement($statement); Given a L, if the statement is a L, L, or L declaration statement or a C, returns the names of the things being defined. Given use constant 1.16 FOO => 'bar'; this will return the L containing C<'FOO'>. Given use constant 1.16 { FOO => 'bar', 'BAZ' => 'burfle' }; this will return a list of the Ls containing C<'FOO'> and C<'BAZ'>. Similarly, given Readonly::Hash my %FOO => ( bar => 'baz' ); or const my %FOO => ( bar => 'baz' ); this will return the L containing C<'%FOO'>. =head2 split_ppi_node_by_namespace my $subtrees = split_ppi_node_by_namespace($node); Returns the sub-trees for each namespace in the node as a reference to a hash of references to arrays of Ls. Say we've got the following code: #!perl my $x = blah(); package Foo; my $y = blah_blah(); { say 'Whee!'; package Bar; something(); } thingy(); package Baz; da_da_da(); package Foo; foreach ( blrfl() ) { ... } Calling this function on a L for the above returns a value that looks like this, using multi-line string literals for the actual code parts instead of PPI trees to make this easier to read: { main => [ q< #!perl my $x = blah(); >, ], Foo => [ q< package Foo; my $y = blah_blah(); { say 'Whee!'; } thingy(); >, q< package Foo; foreach ( blrfl() ) { ... } >, ], Bar => [ q< package Bar; something(); >, ], Baz => [ q< package Baz; da_da_da(); >, ], } Note that the return value contains copies of the original nodes, and not the original nodes themselves due to the need to handle namespaces that are not file-scoped. (Notice how the first element for "Foo" above differs from the original code.) =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book Code originally from L by Jeffrey Ryan Thalhammer , L and L by Elliot Shank , and L by Thomas R. Wyant, III =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2009-2010 Thomas R. Wyant, III, 2017 Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 SEE ALSO L, L, L split_ppi_node_by_namespace.t100644001750001750 11307013460615105 21725 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/t# Test file from PPIx::Utilities::Node use strict; use warnings; use Data::Dumper qw< >; use PPI::Document qw< >; use PPI::Dumper qw< >; use PPIx::Utils::Traversal qw< split_ppi_node_by_namespace >; use Test::More; my $DUMP_INDENT = 4; { my $source = <<'END_SOURCE'; package Foo; $x = 1; while (1) { $y = 2 } until (1) { $z = 3 } if (1) { $w = 4 } unless (1) { $v = 5 } for (1) { $u = 6 } foreach (1) { $t = 7 } given (1) { $s = 8 } when (1) { $r = 9 } END_SOURCE my %expected = ( Foo => [ <<'END_EXPECTED' ], PPI::Document PPI::Statement::Package [ 1, 1, 1 ] PPI::Token::Word 'package' [ 1, 8, 8 ] PPI::Token::Whitespace ' ' [ 1, 9, 9 ] PPI::Token::Word 'Foo' [ 1, 12, 12 ] PPI::Token::Structure ';' [ 1, 13, 13 ] PPI::Token::Whitespace '\n' PPI::Statement [ 2, 1, 1 ] PPI::Token::Symbol '$x' [ 2, 3, 3 ] PPI::Token::Whitespace ' ' [ 2, 4, 4 ] PPI::Token::Operator '=' [ 2, 5, 5 ] PPI::Token::Whitespace ' ' [ 2, 6, 6 ] PPI::Token::Number '1' [ 2, 7, 7 ] PPI::Token::Structure ';' [ 2, 8, 8 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 3, 1, 1 ] PPI::Token::Word 'while' [ 3, 6, 6 ] PPI::Token::Whitespace ' ' PPI::Structure::Condition ( ... ) PPI::Statement::Expression [ 3, 8, 8 ] PPI::Token::Number '1' [ 3, 10, 10 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 3, 12, 12 ] PPI::Token::Whitespace ' ' PPI::Statement [ 3, 13, 13 ] PPI::Token::Symbol '$y' [ 3, 15, 15 ] PPI::Token::Whitespace ' ' [ 3, 16, 16 ] PPI::Token::Operator '=' [ 3, 17, 17 ] PPI::Token::Whitespace ' ' [ 3, 18, 18 ] PPI::Token::Number '2' [ 3, 19, 19 ] PPI::Token::Whitespace ' ' [ 3, 21, 21 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 4, 1, 1 ] PPI::Token::Word 'until' [ 4, 6, 6 ] PPI::Token::Whitespace ' ' PPI::Structure::Condition ( ... ) PPI::Statement::Expression [ 4, 8, 8 ] PPI::Token::Number '1' [ 4, 10, 10 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 4, 12, 12 ] PPI::Token::Whitespace ' ' PPI::Statement [ 4, 13, 13 ] PPI::Token::Symbol '$z' [ 4, 15, 15 ] PPI::Token::Whitespace ' ' [ 4, 16, 16 ] PPI::Token::Operator '=' [ 4, 17, 17 ] PPI::Token::Whitespace ' ' [ 4, 18, 18 ] PPI::Token::Number '3' [ 4, 19, 19 ] PPI::Token::Whitespace ' ' [ 4, 21, 21 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 5, 1, 1 ] PPI::Token::Word 'if' [ 5, 3, 3 ] PPI::Token::Whitespace ' ' PPI::Structure::Condition ( ... ) PPI::Statement::Expression [ 5, 5, 5 ] PPI::Token::Number '1' [ 5, 7, 7 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 5, 9, 9 ] PPI::Token::Whitespace ' ' PPI::Statement [ 5, 10, 10 ] PPI::Token::Symbol '$w' [ 5, 12, 12 ] PPI::Token::Whitespace ' ' [ 5, 13, 13 ] PPI::Token::Operator '=' [ 5, 14, 14 ] PPI::Token::Whitespace ' ' [ 5, 15, 15 ] PPI::Token::Number '4' [ 5, 16, 16 ] PPI::Token::Whitespace ' ' [ 5, 18, 18 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 6, 1, 1 ] PPI::Token::Word 'unless' [ 6, 7, 7 ] PPI::Token::Whitespace ' ' PPI::Structure::Condition ( ... ) PPI::Statement::Expression [ 6, 9, 9 ] PPI::Token::Number '1' [ 6, 11, 11 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 6, 13, 13 ] PPI::Token::Whitespace ' ' PPI::Statement [ 6, 14, 14 ] PPI::Token::Symbol '$v' [ 6, 16, 16 ] PPI::Token::Whitespace ' ' [ 6, 17, 17 ] PPI::Token::Operator '=' [ 6, 18, 18 ] PPI::Token::Whitespace ' ' [ 6, 19, 19 ] PPI::Token::Number '5' [ 6, 20, 20 ] PPI::Token::Whitespace ' ' [ 6, 22, 22 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 7, 1, 1 ] PPI::Token::Word 'for' [ 7, 4, 4 ] PPI::Token::Whitespace ' ' PPI::Structure::List ( ... ) PPI::Statement [ 7, 6, 6 ] PPI::Token::Number '1' [ 7, 8, 8 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 7, 10, 10 ] PPI::Token::Whitespace ' ' PPI::Statement [ 7, 11, 11 ] PPI::Token::Symbol '$u' [ 7, 13, 13 ] PPI::Token::Whitespace ' ' [ 7, 14, 14 ] PPI::Token::Operator '=' [ 7, 15, 15 ] PPI::Token::Whitespace ' ' [ 7, 16, 16 ] PPI::Token::Number '6' [ 7, 17, 17 ] PPI::Token::Whitespace ' ' [ 7, 19, 19 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 8, 1, 1 ] PPI::Token::Word 'foreach' [ 8, 8, 8 ] PPI::Token::Whitespace ' ' PPI::Structure::List ( ... ) PPI::Statement [ 8, 10, 10 ] PPI::Token::Number '1' [ 8, 12, 12 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 8, 14, 14 ] PPI::Token::Whitespace ' ' PPI::Statement [ 8, 15, 15 ] PPI::Token::Symbol '$t' [ 8, 17, 17 ] PPI::Token::Whitespace ' ' [ 8, 18, 18 ] PPI::Token::Operator '=' [ 8, 19, 19 ] PPI::Token::Whitespace ' ' [ 8, 20, 20 ] PPI::Token::Number '7' [ 8, 21, 21 ] PPI::Token::Whitespace ' ' [ 8, 23, 23 ] PPI::Token::Whitespace '\n' PPI::Statement::Given [ 9, 1, 1 ] PPI::Token::Word 'given' [ 9, 6, 6 ] PPI::Token::Whitespace ' ' PPI::Structure::Given ( ... ) PPI::Statement::Expression [ 9, 8, 8 ] PPI::Token::Number '1' [ 9, 10, 10 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 9, 12, 12 ] PPI::Token::Whitespace ' ' PPI::Statement [ 9, 13, 13 ] PPI::Token::Symbol '$s' [ 9, 15, 15 ] PPI::Token::Whitespace ' ' [ 9, 16, 16 ] PPI::Token::Operator '=' [ 9, 17, 17 ] PPI::Token::Whitespace ' ' [ 9, 18, 18 ] PPI::Token::Number '8' [ 9, 19, 19 ] PPI::Token::Whitespace ' ' [ 9, 21, 21 ] PPI::Token::Whitespace '\n' PPI::Statement::When [ 10, 1, 1 ] PPI::Token::Word 'when' [ 10, 5, 5 ] PPI::Token::Whitespace ' ' PPI::Structure::When ( ... ) PPI::Statement::Expression [ 10, 7, 7 ] PPI::Token::Number '1' [ 10, 9, 9 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 10, 11, 11 ] PPI::Token::Whitespace ' ' PPI::Statement [ 10, 12, 12 ] PPI::Token::Symbol '$r' [ 10, 14, 14 ] PPI::Token::Whitespace ' ' [ 10, 15, 15 ] PPI::Token::Operator '=' [ 10, 16, 16 ] PPI::Token::Whitespace ' ' [ 10, 17, 17 ] PPI::Token::Number '9' [ 10, 18, 18 ] PPI::Token::Whitespace ' ' [ 10, 20, 20 ] PPI::Token::Whitespace '\n' END_EXPECTED ); _test($source, \%expected, 'Single namespace.'); } { my $source = <<'END_SOURCE'; $x = 1; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED' ], PPI::Document PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED ); _test($source, \%expected, 'Default namespace.'); } { my $source = <<'END_SOURCE'; $x = 1; package Foo; $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 3, 1, 1 ] PPI::Token::Word 'package' [ 3, 8, 8 ] PPI::Token::Whitespace ' ' [ 3, 9, 9 ] PPI::Token::Word 'Foo' [ 3, 12, 12 ] PPI::Token::Structure ';' [ 3, 13, 13 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 5, 1, 1 ] PPI::Token::Symbol '$y' [ 5, 3, 3 ] PPI::Token::Whitespace ' ' [ 5, 4, 4 ] PPI::Token::Operator '=' [ 5, 5, 5 ] PPI::Token::Whitespace ' ' [ 5, 6, 6 ] PPI::Token::Number '2' [ 5, 7, 7 ] PPI::Token::Structure ';' [ 5, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test($source, \%expected, 'Simple multiple namespaces: default followed by non-default.'); } { my $source = <<'END_SOURCE'; package Foo; $x = 1; package main; $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement::Package [ 4, 1, 1 ] PPI::Token::Word 'package' [ 4, 8, 8 ] PPI::Token::Whitespace ' ' [ 4, 9, 9 ] PPI::Token::Word 'main' [ 4, 13, 13 ] PPI::Token::Structure ';' [ 4, 14, 14 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 6, 1, 1 ] PPI::Token::Symbol '$y' [ 6, 3, 3 ] PPI::Token::Whitespace ' ' [ 6, 4, 4 ] PPI::Token::Operator '=' [ 6, 5, 5 ] PPI::Token::Whitespace ' ' [ 6, 6, 6 ] PPI::Token::Number '2' [ 6, 7, 7 ] PPI::Token::Structure ';' [ 6, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 1, 1, 1 ] PPI::Token::Word 'package' [ 1, 8, 8 ] PPI::Token::Whitespace ' ' [ 1, 9, 9 ] PPI::Token::Word 'Foo' [ 1, 12, 12 ] PPI::Token::Structure ';' [ 1, 13, 13 ] PPI::Token::Whitespace '\n' PPI::Statement [ 2, 1, 1 ] PPI::Token::Symbol '$x' [ 2, 3, 3 ] PPI::Token::Whitespace ' ' [ 2, 4, 4 ] PPI::Token::Operator '=' [ 2, 5, 5 ] PPI::Token::Whitespace ' ' [ 2, 6, 6 ] PPI::Token::Number '1' [ 2, 7, 7 ] PPI::Token::Structure ';' [ 2, 8, 8 ] PPI::Token::Whitespace '\n' [ 3, 1, 1 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test($source, \%expected, 'Simple multiple namespaces: non-default followed by default.'); } { my $source = <<'END_SOURCE'; $x = 1; package Foo; $y = 2; package main; $z = 3; package Foo; $w = 4; package main; $v = 5; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' PPI::Statement::Package [ 4, 1, 1 ] PPI::Token::Word 'package' [ 4, 8, 8 ] PPI::Token::Whitespace ' ' [ 4, 9, 9 ] PPI::Token::Word 'main' [ 4, 13, 13 ] PPI::Token::Structure ';' [ 4, 14, 14 ] PPI::Token::Whitespace '\n' PPI::Statement [ 5, 1, 1 ] PPI::Token::Symbol '$z' [ 5, 3, 3 ] PPI::Token::Whitespace ' ' [ 5, 4, 4 ] PPI::Token::Operator '=' [ 5, 5, 5 ] PPI::Token::Whitespace ' ' [ 5, 6, 6 ] PPI::Token::Number '3' [ 5, 7, 7 ] PPI::Token::Structure ';' [ 5, 8, 8 ] PPI::Token::Whitespace '\n' PPI::Statement::Package [ 8, 1, 1 ] PPI::Token::Word 'package' [ 8, 8, 8 ] PPI::Token::Whitespace ' ' [ 8, 9, 9 ] PPI::Token::Word 'main' [ 8, 13, 13 ] PPI::Token::Structure ';' [ 8, 14, 14 ] PPI::Token::Whitespace '\n' PPI::Statement [ 9, 1, 1 ] PPI::Token::Symbol '$v' [ 9, 3, 3 ] PPI::Token::Whitespace ' ' [ 9, 4, 4 ] PPI::Token::Operator '=' [ 9, 5, 5 ] PPI::Token::Whitespace ' ' [ 9, 6, 6 ] PPI::Token::Number '5' [ 9, 7, 7 ] PPI::Token::Structure ';' [ 9, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 2, 1, 1 ] PPI::Token::Word 'package' [ 2, 8, 8 ] PPI::Token::Whitespace ' ' [ 2, 9, 9 ] PPI::Token::Word 'Foo' [ 2, 12, 12 ] PPI::Token::Structure ';' [ 2, 13, 13 ] PPI::Token::Whitespace '\n' PPI::Statement [ 3, 1, 1 ] PPI::Token::Symbol '$y' [ 3, 3, 3 ] PPI::Token::Whitespace ' ' [ 3, 4, 4 ] PPI::Token::Operator '=' [ 3, 5, 5 ] PPI::Token::Whitespace ' ' [ 3, 6, 6 ] PPI::Token::Number '2' [ 3, 7, 7 ] PPI::Token::Structure ';' [ 3, 8, 8 ] PPI::Token::Whitespace '\n' PPI::Statement::Package [ 6, 1, 1 ] PPI::Token::Word 'package' [ 6, 8, 8 ] PPI::Token::Whitespace ' ' [ 6, 9, 9 ] PPI::Token::Word 'Foo' [ 6, 12, 12 ] PPI::Token::Structure ';' [ 6, 13, 13 ] PPI::Token::Whitespace '\n' PPI::Statement [ 7, 1, 1 ] PPI::Token::Symbol '$w' [ 7, 3, 3 ] PPI::Token::Whitespace ' ' [ 7, 4, 4 ] PPI::Token::Operator '=' [ 7, 5, 5 ] PPI::Token::Whitespace ' ' [ 7, 6, 6 ] PPI::Token::Number '4' [ 7, 7, 7 ] PPI::Token::Structure ';' [ 7, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test( $source, \%expected, 'Simple multiple namespaces: back and forth between two.', ); } { my $source = <<'END_SOURCE'; $x = 1; { package Foo; $a = 17; } $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound PPI::Structure::Block { ... } [ 3, 2, 2 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace ' ' [ 6, 2, 2 ] PPI::Token::Whitespace '\n' [ 7, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 8, 1, 1 ] PPI::Token::Symbol '$y' [ 8, 3, 3 ] PPI::Token::Whitespace ' ' [ 8, 4, 4 ] PPI::Token::Operator '=' [ 8, 5, 5 ] PPI::Token::Whitespace ' ' [ 8, 6, 6 ] PPI::Token::Number '2' [ 8, 7, 7 ] PPI::Token::Structure ';' [ 8, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 4, 5, 5 ] PPI::Token::Word 'package' [ 4, 12, 12 ] PPI::Token::Whitespace ' ' [ 4, 13, 13 ] PPI::Token::Word 'Foo' [ 4, 16, 16 ] PPI::Token::Structure ';' [ 4, 17, 17 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement [ 5, 5, 5 ] PPI::Token::Symbol '$a' [ 5, 7, 7 ] PPI::Token::Whitespace ' ' [ 5, 8, 8 ] PPI::Token::Operator '=' [ 5, 9, 9 ] PPI::Token::Whitespace ' ' [ 5, 10, 10 ] PPI::Token::Number '17' [ 5, 12, 12 ] PPI::Token::Structure ';' [ 5, 13, 13 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test($source, \%expected, 'Single lexically scoped namespace: scope block.'); } { my $source = <<'END_SOURCE'; $x = 1; foreach qw< l m n > { package Foo; $a = 17; } $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement::Compound [ 3, 1, 1 ] PPI::Token::Word 'foreach' [ 3, 8, 8 ] PPI::Token::Whitespace ' ' [ 3, 9, 9 ] PPI::Token::QuoteLike::Words 'qw< l m n >' [ 3, 20, 20 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 3, 22, 22 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace ' ' [ 6, 2, 2 ] PPI::Token::Whitespace '\n' [ 7, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 8, 1, 1 ] PPI::Token::Symbol '$y' [ 8, 3, 3 ] PPI::Token::Whitespace ' ' [ 8, 4, 4 ] PPI::Token::Operator '=' [ 8, 5, 5 ] PPI::Token::Whitespace ' ' [ 8, 6, 6 ] PPI::Token::Number '2' [ 8, 7, 7 ] PPI::Token::Structure ';' [ 8, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 4, 5, 5 ] PPI::Token::Word 'package' [ 4, 12, 12 ] PPI::Token::Whitespace ' ' [ 4, 13, 13 ] PPI::Token::Word 'Foo' [ 4, 16, 16 ] PPI::Token::Structure ';' [ 4, 17, 17 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement [ 5, 5, 5 ] PPI::Token::Symbol '$a' [ 5, 7, 7 ] PPI::Token::Whitespace ' ' [ 5, 8, 8 ] PPI::Token::Operator '=' [ 5, 9, 9 ] PPI::Token::Whitespace ' ' [ 5, 10, 10 ] PPI::Token::Number '17' [ 5, 12, 12 ] PPI::Token::Structure ';' [ 5, 13, 13 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test( $source, \%expected, 'Single lexically scoped namespace: foreach loop.', ); } { my $source = <<'END_SOURCE'; $x = 1; given qw< l m n > { package Foo; $a = 17; } $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement::Given [ 3, 1, 1 ] PPI::Token::Word 'given' [ 3, 6, 6 ] PPI::Token::Whitespace ' ' [ 3, 7, 7 ] PPI::Token::QuoteLike::Words 'qw< l m n >' [ 3, 18, 18 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 3, 20, 20 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace ' ' [ 6, 2, 2 ] PPI::Token::Whitespace '\n' [ 7, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 8, 1, 1 ] PPI::Token::Symbol '$y' [ 8, 3, 3 ] PPI::Token::Whitespace ' ' [ 8, 4, 4 ] PPI::Token::Operator '=' [ 8, 5, 5 ] PPI::Token::Whitespace ' ' [ 8, 6, 6 ] PPI::Token::Number '2' [ 8, 7, 7 ] PPI::Token::Structure ';' [ 8, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 4, 5, 5 ] PPI::Token::Word 'package' [ 4, 12, 12 ] PPI::Token::Whitespace ' ' [ 4, 13, 13 ] PPI::Token::Word 'Foo' [ 4, 16, 16 ] PPI::Token::Structure ';' [ 4, 17, 17 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement [ 5, 5, 5 ] PPI::Token::Symbol '$a' [ 5, 7, 7 ] PPI::Token::Whitespace ' ' [ 5, 8, 8 ] PPI::Token::Operator '=' [ 5, 9, 9 ] PPI::Token::Whitespace ' ' [ 5, 10, 10 ] PPI::Token::Number '17' [ 5, 12, 12 ] PPI::Token::Structure ';' [ 5, 13, 13 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test( $source, \%expected, 'Single lexically scoped namespace: given.', ); } { my $source = <<'END_SOURCE'; $x = 1; when qw< l m n > { package Foo; $a = 17; } $y = 2; END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN' ], PPI::Document::Fragment PPI::Statement [ 1, 1, 1 ] PPI::Token::Symbol '$x' [ 1, 3, 3 ] PPI::Token::Whitespace ' ' [ 1, 4, 4 ] PPI::Token::Operator '=' [ 1, 5, 5 ] PPI::Token::Whitespace ' ' [ 1, 6, 6 ] PPI::Token::Number '1' [ 1, 7, 7 ] PPI::Token::Structure ';' [ 1, 8, 8 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement::When [ 3, 1, 1 ] PPI::Token::Word 'when' [ 3, 5, 5 ] PPI::Token::Whitespace ' ' [ 3, 6, 6 ] PPI::Token::QuoteLike::Words 'qw< l m n >' [ 3, 17, 17 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 3, 19, 19 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace ' ' [ 6, 2, 2 ] PPI::Token::Whitespace '\n' [ 7, 1, 1 ] PPI::Token::Whitespace '\n' PPI::Statement [ 8, 1, 1 ] PPI::Token::Symbol '$y' [ 8, 3, 3 ] PPI::Token::Whitespace ' ' [ 8, 4, 4 ] PPI::Token::Operator '=' [ 8, 5, 5 ] PPI::Token::Whitespace ' ' [ 8, 6, 6 ] PPI::Token::Number '2' [ 8, 7, 7 ] PPI::Token::Structure ';' [ 8, 8, 8 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN Foo => [ <<'END_EXPECTED_FOO' ], PPI::Document::Fragment PPI::Statement::Package [ 4, 5, 5 ] PPI::Token::Word 'package' [ 4, 12, 12 ] PPI::Token::Whitespace ' ' [ 4, 13, 13 ] PPI::Token::Word 'Foo' [ 4, 16, 16 ] PPI::Token::Structure ';' [ 4, 17, 17 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement [ 5, 5, 5 ] PPI::Token::Symbol '$a' [ 5, 7, 7 ] PPI::Token::Whitespace ' ' [ 5, 8, 8 ] PPI::Token::Operator '=' [ 5, 9, 9 ] PPI::Token::Whitespace ' ' [ 5, 10, 10 ] PPI::Token::Number '17' [ 5, 12, 12 ] PPI::Token::Structure ';' [ 5, 13, 13 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO ); _test( $source, \%expected, 'Single lexically scoped namespace: when.', ); } { my $source = <<'END_SOURCE'; given (0) { package Foo; when (1) { package main; } when (2) { package main; } default { package main; while (3) { package Foo; package Bar; package Foo; package main; foreach (4) { package Foo; } } } } END_SOURCE my %expected = ( main => [ <<'END_EXPECTED_MAIN', PPI::Document::Fragment PPI::Statement::Given [ 1, 1, 1 ] PPI::Token::Word 'given' [ 1, 6, 6 ] PPI::Token::Whitespace ' ' PPI::Structure::Given ( ... ) PPI::Statement::Expression [ 1, 8, 8 ] PPI::Token::Number '0' [ 1, 10, 10 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 1, 12, 12 ] PPI::Token::Whitespace '\n' [ 2, 1, 1 ] PPI::Token::Whitespace ' ' [ 21, 2, 2 ] PPI::Token::Whitespace '\n' END_EXPECTED_MAIN <<'END_EXPECTED_MAIN', PPI::Document::Fragment PPI::Statement::Package [ 4, 9, 9 ] PPI::Token::Word 'package' [ 4, 16, 16 ] PPI::Token::Whitespace ' ' [ 4, 17, 17 ] PPI::Token::Word 'main' [ 4, 21, 21 ] PPI::Token::Structure ';' [ 4, 22, 22 ] PPI::Token::Whitespace '\n' [ 5, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_MAIN <<'END_EXPECTED_MAIN', PPI::Document::Fragment PPI::Statement::Package [ 7, 9, 9 ] PPI::Token::Word 'package' [ 7, 16, 16 ] PPI::Token::Whitespace ' ' [ 7, 17, 17 ] PPI::Token::Word 'main' [ 7, 21, 21 ] PPI::Token::Structure ';' [ 7, 22, 22 ] PPI::Token::Whitespace '\n' [ 8, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_MAIN <<'END_EXPECTED_MAIN', PPI::Document::Fragment PPI::Statement::Package [ 10, 9, 9 ] PPI::Token::Word 'package' [ 10, 16, 16 ] PPI::Token::Whitespace ' ' [ 10, 17, 17 ] PPI::Token::Word 'main' [ 10, 21, 21 ] PPI::Token::Structure ';' [ 10, 22, 22 ] PPI::Token::Whitespace '\n' [ 11, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::Compound [ 11, 9, 9 ] PPI::Token::Word 'while' [ 11, 14, 14 ] PPI::Token::Whitespace ' ' PPI::Structure::Condition ( ... ) PPI::Statement::Expression [ 11, 16, 16 ] PPI::Token::Number '3' [ 11, 18, 18 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 11, 20, 20 ] PPI::Token::Whitespace '\n' [ 12, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::Package [ 15, 13, 13 ] PPI::Token::Word 'package' [ 15, 20, 20 ] PPI::Token::Whitespace ' ' [ 15, 21, 21 ] PPI::Token::Word 'main' [ 15, 25, 25 ] PPI::Token::Structure ';' [ 15, 26, 26 ] PPI::Token::Whitespace '\n' [ 16, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::Compound [ 16, 13, 13 ] PPI::Token::Word 'foreach' [ 16, 20, 20 ] PPI::Token::Whitespace ' ' PPI::Structure::List ( ... ) PPI::Statement [ 16, 22, 22 ] PPI::Token::Number '4' [ 16, 24, 24 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 16, 26, 26 ] PPI::Token::Whitespace '\n' [ 17, 1, 1 ] PPI::Token::Whitespace ' ' [ 18, 14, 14 ] PPI::Token::Whitespace '\n' [ 19, 1, 1 ] PPI::Token::Whitespace ' ' [ 19, 10, 10 ] PPI::Token::Whitespace '\n' [ 20, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_MAIN ], Foo => [ <<'END_EXPECTED_FOO', PPI::Document::Fragment PPI::Statement::Package [ 2, 5, 5 ] PPI::Token::Word 'package' [ 2, 12, 12 ] PPI::Token::Whitespace ' ' [ 2, 13, 13 ] PPI::Token::Word 'Foo' [ 2, 16, 16 ] PPI::Token::Structure ';' [ 2, 17, 17 ] PPI::Token::Whitespace '\n' [ 3, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::When [ 3, 5, 5 ] PPI::Token::Word 'when' [ 3, 9, 9 ] PPI::Token::Whitespace ' ' PPI::Structure::When ( ... ) PPI::Statement::Expression [ 3, 11, 11 ] PPI::Token::Number '1' [ 3, 13, 13 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 3, 15, 15 ] PPI::Token::Whitespace '\n' [ 4, 1, 1 ] PPI::Token::Whitespace ' ' [ 5, 6, 6 ] PPI::Token::Whitespace '\n' [ 6, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::When [ 6, 5, 5 ] PPI::Token::Word 'when' [ 6, 9, 9 ] PPI::Token::Whitespace ' ' PPI::Structure::When ( ... ) PPI::Statement::Expression [ 6, 11, 11 ] PPI::Token::Number '2' [ 6, 13, 13 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 6, 15, 15 ] PPI::Token::Whitespace '\n' [ 7, 1, 1 ] PPI::Token::Whitespace ' ' [ 8, 6, 6 ] PPI::Token::Whitespace '\n' [ 9, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::When [ 9, 5, 5 ] PPI::Token::Word 'default' [ 9, 12, 12 ] PPI::Token::Whitespace ' ' PPI::Structure::Block { ... } [ 9, 14, 14 ] PPI::Token::Whitespace '\n' [ 10, 1, 1 ] PPI::Token::Whitespace ' ' [ 20, 6, 6 ] PPI::Token::Whitespace '\n' END_EXPECTED_FOO <<'END_EXPECTED_FOO', PPI::Document::Fragment PPI::Statement::Package [ 12, 13, 13 ] PPI::Token::Word 'package' [ 12, 20, 20 ] PPI::Token::Whitespace ' ' [ 12, 21, 21 ] PPI::Token::Word 'Foo' [ 12, 24, 24 ] PPI::Token::Structure ';' [ 12, 25, 25 ] PPI::Token::Whitespace '\n' [ 13, 1, 1 ] PPI::Token::Whitespace ' ' PPI::Statement::Package [ 14, 13, 13 ] PPI::Token::Word 'package' [ 14, 20, 20 ] PPI::Token::Whitespace ' ' [ 14, 21, 21 ] PPI::Token::Word 'Foo' [ 14, 24, 24 ] PPI::Token::Structure ';' [ 14, 25, 25 ] PPI::Token::Whitespace '\n' [ 15, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_FOO <<'END_EXPECTED_FOO', PPI::Document::Fragment PPI::Statement::Package [ 17, 17, 17 ] PPI::Token::Word 'package' [ 17, 24, 24 ] PPI::Token::Whitespace ' ' [ 17, 25, 25 ] PPI::Token::Word 'Foo' [ 17, 28, 28 ] PPI::Token::Structure ';' [ 17, 29, 29 ] PPI::Token::Whitespace '\n' [ 18, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_FOO ], Bar => [ <<'END_EXPECTED_BAR' ], PPI::Document::Fragment PPI::Statement::Package [ 13, 13, 13 ] PPI::Token::Word 'package' [ 13, 20, 20 ] PPI::Token::Whitespace ' ' [ 13, 21, 21 ] PPI::Token::Word 'Bar' [ 13, 24, 24 ] PPI::Token::Structure ';' [ 13, 25, 25 ] PPI::Token::Whitespace '\n' [ 14, 1, 1 ] PPI::Token::Whitespace ' ' END_EXPECTED_BAR ); _test( $source, \%expected, 'Heavilly nested namespaces.', ); } sub _test { my ($source, $expected_ref, $test_name) = @_; my $document = PPI::Document->new(\$source); my %expanded_expected; foreach my $namespace ( keys %{$expected_ref} ) { my $strings = $expected_ref->{$namespace}; $expanded_expected{$namespace} = [ map { [ split m/ \n /x ] } @{$strings} ]; } my $got = split_ppi_node_by_namespace($document); my %got_expanded; foreach my $namespace ( keys %{$got} ) { my $ppi_doms = $got->{$namespace}; $got_expanded{$namespace} = [ map { [ map { _expand_tabs($_) } _new_dumper($_)->list() ] } @{$ppi_doms} ]; } is_deeply(\%got_expanded, \%expanded_expected, $test_name) or diag( Data::Dumper->Dump( [\%got_expanded, \%expanded_expected], [ qw ], ) ); return; } sub _new_dumper { my ($node) = @_; return PPI::Dumper->new($node, indent => $DUMP_INDENT, locations => 1); } # Why Adam had to put @#$^@#$&^ hard tabs in his dumper output, I don't know. sub _expand_tabs { my ($string) = @_; while ( $string =~ s< \A ( [^\t]* ) ( \t+ ) > <$1 . ( ' ' x (length($2) * $DUMP_INDENT - length($1) % $DUMP_INDENT) )>xe ) { # Nothing here. } return $string; } done_testing; Classification.pm100644001750001750 7607713460615105 21535 0ustar00grinnzgrinnz000000000000PPIx-Utils-0.003/lib/PPIx/Utilspackage PPIx::Utils::Classification; use strict; use warnings; use B::Keywords; use Exporter 'import'; use Scalar::Util 'blessed'; use PPIx::Utils::Traversal qw(first_arg parse_arg_list); # Functions also used by PPIx::Utils::Traversal use PPIx::Utils::_Common qw( is_ppi_expression_or_generic_statement is_ppi_simple_statement ); our $VERSION = '0.003'; our @EXPORT_OK = qw( is_assignment_operator is_class_name is_function_call is_hash_key is_in_void_context is_included_module_name is_integer is_label_pointer is_method_call is_package_declaration is_perl_bareword is_perl_builtin is_perl_builtin_with_list_context is_perl_builtin_with_multiple_arguments is_perl_builtin_with_no_arguments is_perl_builtin_with_one_argument is_perl_builtin_with_optional_argument is_perl_builtin_with_zero_and_or_one_arguments is_perl_filehandle is_perl_global is_qualified_name is_subroutine_name is_unchecked_call is_ppi_expression_or_generic_statement is_ppi_generic_statement is_ppi_statement_subclass is_ppi_simple_statement is_ppi_constant_element is_subroutine_declaration is_in_subroutine ); our %EXPORT_TAGS = (all => [@EXPORT_OK]); # From Perl::Critic::Utils sub _name_for_sub_or_stringified_element { my $elem = shift; if ( blessed $elem and $elem->isa('PPI::Statement::Sub') ) { return $elem->name(); } return "$elem"; } my %BUILTINS = map { $_ => 1 } @B::Keywords::Functions; sub is_perl_builtin { my $elem = shift; return undef if !$elem; return exists $BUILTINS{ _name_for_sub_or_stringified_element($elem) }; } my %BAREWORDS = map { $_ => 1 } @B::Keywords::Barewords; sub is_perl_bareword { my $elem = shift; return undef if !$elem; return exists $BAREWORDS{ _name_for_sub_or_stringified_element($elem) }; } sub _build_globals_without_sigils { my @globals = map { substr $_, 1 } @B::Keywords::Arrays, @B::Keywords::Hashes, @B::Keywords::Scalars; # Not all of these have sigils foreach my $filehandle (@B::Keywords::Filehandles) { (my $stripped = $filehandle) =~ s< \A [*] ><>x; push @globals, $stripped; } return @globals; } my %GLOBALS = map { $_ => 1 } _build_globals_without_sigils(); sub is_perl_global { my $elem = shift; return undef if !$elem; my $var_name = "$elem"; #Convert Token::Symbol to string $var_name =~ s{\A [\$@%*] }{}x; #Chop off the sigil return exists $GLOBALS{ $var_name }; } my %FILEHANDLES = map { $_ => 1 } @B::Keywords::Filehandles; sub is_perl_filehandle { my $elem = shift; return undef if !$elem; return exists $FILEHANDLES{ _name_for_sub_or_stringified_element($elem) }; } # egrep '=item.*LIST' perlfunc.pod my %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT = map { $_ => 1 } qw{ chmod chown die exec formline grep import join kill map no open pack print printf push reverse say sort splice sprintf syscall system tie unlink unshift use utime warn }; sub is_perl_builtin_with_list_context { my $elem = shift; return exists $BUILTINS_WHICH_PROVIDE_LIST_CONTEXT{ _name_for_sub_or_stringified_element($elem) }; } # egrep '=item.*[A-Z],' perlfunc.pod my %BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS = map { $_ => 1 } qw{ accept atan2 bind binmode bless connect crypt dbmopen fcntl flock gethostbyaddr getnetbyaddr getpriority getservbyname getservbyport getsockopt index ioctl link listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe read recv rename rindex seek seekdir select semctl semget semop send setpgrp setpriority setsockopt shmctl shmget shmread shmwrite shutdown socket socketpair splice split substr symlink sysopen sysread sysseek syswrite truncate unpack vec waitpid }, keys %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT; sub is_perl_builtin_with_multiple_arguments { my $elem = shift; return exists $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ _name_for_sub_or_stringified_element($elem) }; } my %BUILTINS_WHICH_TAKE_NO_ARGUMENTS = map { $_ => 1 } qw{ endgrent endhostent endnetent endprotoent endpwent endservent fork format getgrent gethostent getlogin getnetent getppid getprotoent getpwent getservent setgrent setpwent split time times wait wantarray }; sub is_perl_builtin_with_no_arguments { my $elem = shift; return exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ _name_for_sub_or_stringified_element($elem) }; } my %BUILTINS_WHICH_TAKE_ONE_ARGUMENT = map { $_ => 1 } qw{ closedir dbmclose delete each exists fileno getgrgid getgrnam gethostbyname getnetbyname getpeername getpgrp getprotobyname getprotobynumber getpwnam getpwuid getsockname goto keys local prototype readdir readline readpipe rewinddir scalar sethostent setnetent setprotoent setservent telldir tied untie values }; sub is_perl_builtin_with_one_argument { my $elem = shift; return exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ _name_for_sub_or_stringified_element($elem) }; } my %BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT = map { $_ => 1 } grep { not exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $_ } } grep { not exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $_ } } grep { not exists $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ $_ } } @B::Keywords::Functions; sub is_perl_builtin_with_optional_argument { my $elem = shift; return exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ _name_for_sub_or_stringified_element($elem) }; } sub is_perl_builtin_with_zero_and_or_one_arguments { my $elem = shift; return undef if not $elem; my $name = _name_for_sub_or_stringified_element($elem); return ( exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $name } or exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $name } or exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ $name } ); } sub is_qualified_name { my $name = shift; return undef if not $name; return index ( $name, q{::} ) >= 0; } sub _is_followed_by_parens { my $elem = shift; return undef if !$elem; my $sibling = $elem->snext_sibling() || return undef; return $sibling->isa('PPI::Structure::List'); } sub is_hash_key { my $elem = shift; return undef if !$elem; #If followed by an argument list, then its a function call, not a literal return undef if _is_followed_by_parens($elem); #Check curly-brace style: $hash{foo} = bar; my $parent = $elem->parent(); return undef if !$parent; my $grandparent = $parent->parent(); return undef if !$grandparent; return 1 if $grandparent->isa('PPI::Structure::Subscript'); #Check declarative style: %hash = (foo => bar); my $sib = $elem->snext_sibling(); return undef if !$sib; return 1 if $sib->isa('PPI::Token::Operator') && $sib eq '=>'; return undef; } sub is_included_module_name { my $elem = shift; return undef if !$elem; my $stmnt = $elem->statement(); return undef if !$stmnt; return undef if !$stmnt->isa('PPI::Statement::Include'); return $stmnt->schild(1) == $elem; } sub is_integer { my ($value) = @_; return 0 if not defined $value; return $value =~ m{ \A [+-]? [0-9]+ \z }x; } sub is_label_pointer { my $elem = shift; return undef if !$elem; my $statement = $elem->statement(); return undef if !$statement; my $psib = $elem->sprevious_sibling(); return undef if !$psib; return $statement->isa('PPI::Statement::Break') && $psib =~ m/(?:redo|goto|next|last)/x; } sub _is_dereference_operator { my $elem = shift; return undef if !$elem; return $elem->isa('PPI::Token::Operator') && $elem eq q{->}; } sub is_method_call { my $elem = shift; return undef if !$elem; return _is_dereference_operator( $elem->sprevious_sibling() ); } sub is_class_name { my $elem = shift; return undef if !$elem; return _is_dereference_operator( $elem->snext_sibling() ) && !_is_dereference_operator( $elem->sprevious_sibling() ); } sub is_package_declaration { my $elem = shift; return undef if !$elem; my $stmnt = $elem->statement(); return undef if !$stmnt; return undef if !$stmnt->isa('PPI::Statement::Package'); return $stmnt->schild(1) == $elem; } sub is_subroutine_name { my $elem = shift; return undef if !$elem; my $sib = $elem->sprevious_sibling(); return undef if !$sib; my $stmnt = $elem->statement(); return undef if !$stmnt; return $stmnt->isa('PPI::Statement::Sub') && $sib eq 'sub'; } sub is_function_call { my $elem = shift or return undef; return undef if is_perl_bareword($elem); return undef if is_perl_filehandle($elem); return undef if is_package_declaration($elem); return undef if is_included_module_name($elem); return undef if is_method_call($elem); return undef if is_class_name($elem); return undef if is_subroutine_name($elem); return undef if is_label_pointer($elem); return undef if is_hash_key($elem); return 1; } sub is_in_void_context { my ($token) = @_; # If part of a collective, can't be void. return undef if $token->sprevious_sibling(); my $parent = $token->statement()->parent(); if ($parent) { return undef if $parent->isa('PPI::Structure::List'); return undef if $parent->isa('PPI::Structure::For'); return undef if $parent->isa('PPI::Structure::Condition'); return undef if $parent->isa('PPI::Structure::Constructor'); return undef if $parent->isa('PPI::Structure::Subscript'); my $grand_parent = $parent->parent(); if ($grand_parent) { return undef if $parent->isa('PPI::Structure::Block') and not $grand_parent->isa('PPI::Statement::Compound'); } } return 1; } my %ASSIGNMENT_OPERATORS = map { $_ => 1 } qw( = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //= ); sub is_assignment_operator { my $elem = shift; return exists $ASSIGNMENT_OPERATORS{ $elem }; } sub is_unchecked_call { my $elem = shift; return undef if not is_function_call( $elem ); # check to see if there's an '=' or 'unless' or something before this. if( my $sib = $elem->sprevious_sibling() ){ return undef if $sib; } if( my $statement = $elem->statement() ){ # "open or die" is OK. # We can't check snext_sibling for 'or' since the next siblings are an # unknown number of arguments to the system call. Instead, check all of # the elements to this statement to see if we find 'or' or '||'. my $or_operators = sub { my (undef, $elem) = @_; return undef if not $elem->isa('PPI::Token::Operator'); return undef if $elem ne q{or} && $elem ne q{||}; return 1; }; return undef if $statement->find( $or_operators ); if( my $parent = $elem->statement()->parent() ){ # Check if we're in an if( open ) {good} else {bad} condition return undef if $parent->isa('PPI::Structure::Condition'); # Return val could be captured in data structure and checked later return undef if $parent->isa('PPI::Structure::Constructor'); # "die if not ( open() )" - It's in list context. if ( $parent->isa('PPI::Structure::List') ) { if( my $uncle = $parent->sprevious_sibling() ){ return undef if $uncle; } } } } return undef if _is_fatal($elem); # Otherwise, return. this system call is unchecked. return 1; } # Based upon autodie 2.10. my %AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP = ( # Map builtins to themselves. ( map { ($_ => { $_ => 1 }) } qw< accept bind binmode chdir chmod close closedir connect dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl link listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe read readlink recv rename rmdir seek semctl semget semop send setsockopt shmctl shmget shmread shutdown socketpair symlink sysopen sysread sysseek system syswrite truncate umask unlink > ), # Generate these using tools/dump-autodie-tag-contents ':threads' => { map { $_ => 1 } qw< fork > }, ':system' => { map { $_ => 1 } qw< exec system > }, ':dbm' => { map { $_ => 1 } qw< dbmclose dbmopen > }, ':semaphore' => { map { $_ => 1 } qw< semctl semget semop > }, ':shm' => { map { $_ => 1 } qw< shmctl shmget shmread > }, ':msg' => { map { $_ => 1 } qw< msgctl msgget msgrcv msgsnd > }, ':file' => { map { $_ => 1 } qw< binmode chmod close fcntl fileno flock ioctl open sysopen truncate > }, ':filesys' => { map { $_ => 1 } qw< chdir closedir link mkdir opendir readlink rename rmdir symlink umask unlink > }, ':ipc' => { map { $_ => 1 } qw< msgctl msgget msgrcv msgsnd pipe semctl semget semop shmctl shmget shmread > }, ':socket' => { map { $_ => 1 } qw< accept bind connect getsockopt listen recv send setsockopt shutdown socketpair > }, ':io' => { map { $_ => 1 } qw< accept bind binmode chdir chmod close closedir connect dbmclose dbmopen fcntl fileno flock getsockopt ioctl link listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe read readlink recv rename rmdir seek semctl semget semop send setsockopt shmctl shmget shmread shutdown socketpair symlink sysopen sysread sysseek syswrite truncate umask unlink > }, ':default' => { map { $_ => 1 } qw< accept bind binmode chdir chmod close closedir connect dbmclose dbmopen fcntl fileno flock fork getsockopt ioctl link listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe read readlink recv rename rmdir seek semctl semget semop send setsockopt shmctl shmget shmread shutdown socketpair symlink sysopen sysread sysseek syswrite truncate umask unlink > }, ':all' => { map { $_ => 1 } qw< accept bind binmode chdir chmod close closedir connect dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl link listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe read readlink recv rename rmdir seek semctl semget semop send setsockopt shmctl shmget shmread shutdown socketpair symlink sysopen sysread sysseek system syswrite truncate umask unlink > }, ); sub _is_fatal { my ($elem) = @_; my $top = $elem->top(); return undef if not $top->isa('PPI::Document'); my $includes = $top->find('PPI::Statement::Include'); return undef if not $includes; for my $include (@{$includes}) { next if 'use' ne $include->type(); if ('Fatal' eq $include->module()) { my @args = parse_arg_list($include->schild(1)); foreach my $arg (@args) { return 1 if $arg->[0]->isa('PPI::Token::Quote') && $elem eq $arg->[0]->string(); } } elsif ('Fatal::Exception' eq $include->module()) { my @args = parse_arg_list($include->schild(1)); shift @args; # skip exception class name foreach my $arg (@args) { return 1 if $arg->[0]->isa('PPI::Token::Quote') && $elem eq $arg->[0]->string(); } } elsif ('autodie' eq $include->pragma()) { return _is_covered_by_autodie($elem, $include); } } return undef; } sub _is_covered_by_autodie { my ($elem, $include) = @_; my $autodie = $include->schild(1); my @args = parse_arg_list($autodie); my $first_arg = first_arg($autodie); # The first argument to any `use` pragma could be a version number. # If so, then we just discard it. We only want the arguments after it. if ($first_arg and $first_arg->isa('PPI::Token::Number')){ shift @args }; if (@args) { foreach my $arg (@args) { my $builtins = $AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{ $arg->[0]->string }; return 1 if $builtins and $builtins->{$elem->content()}; } } else { my $builtins = $AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{':default'}; return 1 if $builtins and $builtins->{$elem->content()}; } return undef; } # End from Perl::Critic::Utils # From Perl::Critic::Utils::PPI sub is_ppi_generic_statement { my $element = shift; my $element_class = blessed($element); return undef if not $element_class; return undef if not $element->isa('PPI::Statement'); return $element_class eq 'PPI::Statement'; } sub is_ppi_statement_subclass { my $element = shift; my $element_class = blessed($element); return undef if not $element_class; return undef if not $element->isa('PPI::Statement'); return $element_class ne 'PPI::Statement'; } sub is_ppi_constant_element { my $element = shift or return undef; blessed( $element ) or return undef; # TODO implement here documents once PPI::Token::HereDoc grows the # necessary PPI::Token::Quote interface. return $element->isa( 'PPI::Token::Number' ) || $element->isa( 'PPI::Token::Quote::Literal' ) || $element->isa( 'PPI::Token::Quote::Single' ) || $element->isa( 'PPI::Token::QuoteLike::Words' ) || ( $element->isa( 'PPI::Token::Quote::Double' ) || $element->isa( 'PPI::Token::Quote::Interpolate' ) ) && $element->string() !~ m< (?: \A | [^\\] ) (?: \\\\)* [\$\@] >smx ; } sub is_subroutine_declaration { my $element = shift; return undef if not $element; return 1 if $element->isa('PPI::Statement::Sub'); if ( is_ppi_generic_statement($element) ) { my $first_element = $element->first_element(); return 1 if $first_element and $first_element->isa('PPI::Token::Word') and $first_element->content() eq 'sub'; } return undef; } sub is_in_subroutine { my ($element) = @_; return undef if not $element; return 1 if is_subroutine_declaration($element); while ( $element = $element->parent() ) { return 1 if is_subroutine_declaration($element); } return undef; } # End from Perl::Critic::Utils::PPI 1; =head1 NAME PPIx::Utils::Classification - Utility functions for classification of PPI elements =head1 SYNOPSIS use PPIx::Utils::Classification ':all'; =head1 DESCRIPTION This package is a component of L that contains functions for classification of L elements. =head1 FUNCTIONS All functions can be imported by name, or with the tag C<:all>. =head2 is_assignment_operator my $bool = is_assignment_operator($element); Given a L or a string, returns true if that token represents one of the assignment operators (e.g. C<= &&= ||= //= += -=> etc.). =head2 is_perl_global my $bool = is_perl_global($element); Given a L or a string, returns true if that token represents one of the global variables provided by the L module, or one of the builtin global variables like C<%SIG>, C<%ENV>, or C<@ARGV>. The sigil on the symbol is ignored, so things like C<$ARGV> or C<$ENV> will still return true. =head2 is_perl_builtin my $bool = is_perl_builtin($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8. =head2 is_perl_bareword my $bool = is_perl_bareword($element); Given a L, L, or string, returns true if that token represents a bareword (e.g. "if", "else", "sub", "package") defined in Perl 5.8.8. =head2 is_perl_filehandle my $bool = is_perl_filehandle($element); Given a L, or string, returns true if that token represents one of the global filehandles (e.g. C, C, C, C) that are defined in Perl 5.8.8. Note that this function will return false if given a filehandle that is represented as a typeglob (e.g. C<*STDIN>) =head2 is_perl_builtin_with_list_context my $bool = is_perl_builtin_with_list_context($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that provide a list context to the following tokens. =head2 is_perl_builtin_with_multiple_arguments my $bool = is_perl_builtin_with_multiple_arguments($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that B take multiple arguments. =head2 is_perl_builtin_with_no_arguments my $bool = is_perl_builtin_with_no_arguments($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that B take any arguments. =head2 is_perl_builtin_with_one_argument my $bool = is_perl_builtin_with_one_argument($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes B argument. =head2 is_perl_builtin_with_optional_argument my $bool = is_perl_builtin_with_optional_argument($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes B argument. The sets of values for which L, L, L, and L return true are disjoint and their union is precisely the set of values that L will return true for. =head2 is_perl_builtin_with_zero_and_or_one_arguments my $bool = is_perl_builtin_with_zero_and_or_one_arguments($element); Given a L, L, or string, returns true if that token represents a call to any of the builtin functions defined in Perl 5.8.8 that takes no and/or one argument. Returns true if any of L, L, and L returns true. =head2 is_qualified_name my $bool = is_qualified_name($name); Given a string, L, or L, answers whether it has a module component, i.e. contains "::". =head2 is_hash_key my $bool = is_hash_key($element); Given a L, returns true if the element is a literal hash key. PPI doesn't distinguish between regular barewords (like keywords or subroutine calls) and barewords in hash subscripts (which are considered literal). So this subroutine is useful if your Policy is searching for L elements and you want to filter out the hash subscript variety. In both of the following examples, "foo" is considered a hash key: $hash1{foo} = 1; %hash2 = (foo => 1); But if the bareword is followed by an argument list, then perl treats it as a function call. So in these examples, "foo" is B considered a hash key: $hash1{ foo() } = 1; &hash2 = (foo() => 1); =head2 is_included_module_name my $bool = is_included_module_name($element); Given a L, returns true if the element is the name of a module that is being included via C, C, or C. =head2 is_integer my $bool = is_integer($value); Answers whether the parameter, as a string, looks like an integral value. =head2 is_class_name my $bool = is_class_name($element); Given a L, returns true if the element that immediately follows this element is the dereference operator "->". When a bareword has a "->" on the B side, it usually means that it is the name of the class (from which a method is being called). =head2 is_label_pointer my $bool = is_label_pointer($element); Given a L, returns true if the element is the label in a C, C, C, or C statement. Note this is not the same thing as the label declaration. =head2 is_method_call my $bool = is_method_call($element); Given a L, returns true if the element that immediately precedes this element is the dereference operator "->". When a bareword has a "->" on the B side, it usually means that it is the name of a method (that is being called from a class). =head2 is_package_declaration my $bool = is_package_declaration($element); Given a L, returns true if the element is the name of a package that is being declared. =head2 is_subroutine_name my $bool = is_subroutine_name($element); Given a L, returns true if the element is the name of a subroutine declaration. This is useful for distinguishing barewords and from function calls from subroutine declarations. =head2 is_function_call my $bool = is_function_call($element); Given a L returns true if the element appears to be call to a static function. Specifically, this function returns true if L, L, L, L, L, L, L, L and L all return false for the given element. =head2 is_in_void_context my $bool = is_in_void_context($token); Given a L, answer whether it appears to be in a void context. =head2 is_unchecked_call my $bool = is_unchecked_call($element); Given a L, test to see if it contains a function call whose return value is not checked. =head2 is_ppi_expression_or_generic_statement my $bool = is_ppi_expression_or_generic_statement($element); Answers whether the parameter is an expression or an undifferentiated statement. I.e. the parameter either is a L or the class of the parameter is L and not one of its subclasses other than C. =head2 is_ppi_generic_statement my $bool = is_ppi_generic_statement($element); Answers whether the parameter is an undifferentiated statement, i.e. the parameter is a L but not one of its subclasses. =head2 is_ppi_statement_subclass my $bool = is_ppi_statement_subclass($element); Answers whether the parameter is a specialized statement, i.e. the parameter is a L but the class of the parameter is not L. =head2 is_ppi_simple_statement my $bool = is_ppi_simple_statement($element); Answers whether the parameter represents a simple statement, i.e. whether the parameter is a L, L, L, L, L, or L. =head2 is_ppi_constant_element my $bool = is_ppi_constant_element($element); Answers whether the parameter represents a constant value, i.e. whether the parameter is a L, L, L, or L, or is a L or L which does not in fact contain any interpolated variables. This subroutine does B interpret any form of here document as a constant value, and may not until L acquires the relevant portions of the L interface. This subroutine also does B interpret entities created by the L module (or similar) or the L pragma as constants. =head2 is_subroutine_declaration my $bool = is_subroutine_declaration($element); Is the parameter a subroutine declaration, named or not? =head2 is_in_subroutine my $bool = is_in_subroutine($element); Is the parameter a subroutine or inside one? =head1 BUGS Report any issues on the public bugtracker. =head1 AUTHOR Dan Book Code originally from L by Jeffrey Ryan Thalhammer and L by Elliot Shank =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2005-2011 Imaginative Software Systems, 2007-2011 Elliot Shank, 2017 Dan Book. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =head1 SEE ALSO L, L