Build.PL100644000765000024 311512401224621 14177 0ustar00hitode909staff000000000000App-PRT-0.19# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use Module::Build; use File::Basename; use File::Spec; my %args = ( license => 'perl', dynamic_config => 0, configure_requires => { 'Module::Build' => 0.38, }, name => 'App-PRT', module_name => 'App::PRT', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = Module::Build->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); use File::Copy; print "cp META.json MYMETA.json\n"; copy("META.json","MYMETA.json") or die "Copy failed(META.json): $!"; if (-f 'META.yml') { print "cp META.yml MYMETA.yml\n"; copy("META.yml","MYMETA.yml") or die "Copy failed(META.yml): $!"; } else { print "There is no META.yml... You may install this module from the repository...\n"; } Changes100644000765000024 324412401224621 14201 0ustar00hitode909staff000000000000App-PRT-0.19Revision history for Perl extension App-PRT 0.19 2014-09-02T02:20:48Z - Rename rename_name_space to rename_namespace 0.18 2014-09-02T01:37:56Z - Index failed. reverted 334bf37b4b265220031a7af647dd18766d904ea5 0.17 2014-09-02T01:01:32Z - Rename rename_name_space to rename_namespace (thanks miyagawa) - Delete help command for DRY. You can use perldoc prt instead. 0.16 2014-08-31T10:35:30Z - Fix typo, add documentation (thanks syohex) 0.15 2014-08-01T10:16:21Z - Version 0.14 was released from wrong branch 0.14 2014-08-01T10:14:51Z - Fixed a bug of directory preparation - Support renaming packages in script 0.13 2014-05-13T08:35:25Z - Support function to rename symbols on RenameClass command 0.12 2014-04-28T10:26:59Z - I forgot to git pull 0.11 2014-04-28T10:21:50Z - Implement rename_name_space command 0.10 2014-04-18T03:29:09Z - Collect target files with git ls-files in Git repository - Implement move_class_method command 0.09 2014-04-03T02:53:51Z - Fix a document 0.08 2014-04-03T02:47:03Z - Slurp all of perl files if script executes with no file args (thanks moznion) - Fix missing 'literal' method error while renaming class (thanks ishikawa) - avoid warnings saying smartmatch is experimental (thanks miyagawa) 0.07 2014-03-28T08:44:39Z - Fix a typo 0.06 2014-03-28T07:21:49Z - Fix a bug 0.05 2014-03-28T07:12:05Z - Improve renaming behavior 0.04 2014-03-25T04:46:18Z - Various fixes by moznion 0.03 2014-03-25T03:19:54Z - Remove cpanfile.snapshot 0.02 2014-03-25T03:16:37Z - FAKE_RELEASE succeed at version 0.01 0.01 2014-03-25T03:04:47Z - original version LICENSE100644000765000024 4374212401224621 13742 0ustar00hitode909staff000000000000App-PRT-0.19This software is copyright (c) 2014 by hitode909 . 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) 2014 by hitode909 . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by hitode909 . 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 EndMETA.json100644000765000024 723412401224621 14332 0ustar00hitode909staff000000000000App-PRT-0.19{ "abstract" : "Command line Perl Refactoring Tool", "author" : [ "This library is free software; you can redistribute it and/or modify" ], "dynamic_config" : 0, "generated_by" : "Minilla/v2.1.1", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "App-PRT", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "CPAN::Meta" : "0", "CPAN::Meta::Prereqs" : "0", "Module::Build" : "0.38" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.04", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "Class::Load" : "0", "File::Find::Rule" : "0", "Getopt::Long" : "2.42", "PPI" : "0", "Path::Class" : "0", "perl" : "5.010001" } }, "test" : { "requires" : { "File::Copy::Recursive" : "0", "File::Temp" : "0", "Path::Class" : "0", "Test::Class" : "0", "Test::Deep" : "0", "Test::Fatal" : "0", "Test::Mock::Guard" : "0", "Test::More" : "0.98", "parent" : "0" } } }, "provides" : { "App::PRT" : { "file" : "lib/App/PRT.pm", "version" : "0.19" }, "App::PRT::CLI" : { "file" : "lib/App/PRT/CLI.pm" }, "App::PRT::Collector::AllFiles" : { "file" : "lib/App/PRT/Collector/AllFiles.pm" }, "App::PRT::Collector::Files" : { "file" : "lib/App/PRT/Collector/Files.pm" }, "App::PRT::Collector::GitDirectory" : { "file" : "lib/App/PRT/Collector/GitDirectory.pm" }, "App::PRT::Command::AddMethod" : { "file" : "lib/App/PRT/Command/AddMethod.pm" }, "App::PRT::Command::AddUse" : { "file" : "lib/App/PRT/Command/AddUse.pm" }, "App::PRT::Command::DeleteMethod" : { "file" : "lib/App/PRT/Command/DeleteMethod.pm" }, "App::PRT::Command::MoveClassMethod" : { "file" : "lib/App/PRT/Command/MoveClassMethod.pm" }, "App::PRT::Command::RenameClass" : { "file" : "lib/App/PRT/Command/RenameClass.pm" }, "App::PRT::Command::RenameNameSpace" : { "file" : "lib/App/PRT/Command/RenameNameSpace.pm" }, "App::PRT::Command::ReplaceToken" : { "file" : "lib/App/PRT/Command/ReplaceToken.pm" }, "App::PRT::Util::DestinationFile" : { "file" : "lib/App/PRT/Util/DestinationFile.pm" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/hitode909/App-PRT/issues" }, "homepage" : "https://github.com/hitode909/App-PRT", "repository" : { "url" : "git://github.com/hitode909/App-PRT.git", "web" : "https://github.com/hitode909/App-PRT" } }, "version" : "0.19", "x_contributors" : [ "Tatsuhiko Miyagawa ", "Takanori Ishikawa ", "moznion ", "Syohei YOSHIDA ", "hitode909 " ] } README.md100644000765000024 134012401224621 14160 0ustar00hitode909staff000000000000App-PRT-0.19[![Build Status](https://travis-ci.org/hitode909/App-PRT.png?branch=master)](https://travis-ci.org/hitode909/App-PRT) [![Coverage Status](https://coveralls.io/repos/hitode909/App-PRT/badge.png?branch=master)](https://coveralls.io/r/hitode909/App-PRT?branch=master) # NAME App::PRT - Command line Perl Refactoring Tool # SYNOPSIS use App::PRT::CLI; my $cli = App::PRT::CLI->new; $cli->parse(@ARGV); $cli->run; # DESCRIPTION App::PRT is command line tools for Refactoring Perl. # SEE ALSO [prt](https://metacpan.org/pod/prt) # LICENSE Copyright (C) hitode909. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. # AUTHOR hitode909 prt100755000765000024 353012401224621 14207 0ustar00hitode909staff000000000000App-PRT-0.19/bin#!perl use strict; use warnings; use App::PRT::CLI; my $cli = App::PRT::CLI->new; $cli->parse(@ARGV); $cli->run; __END__ =encoding utf-8 =head1 NAME prt - Command line frontend of App::PRT =head1 SYNOPSIS $ prt $ prt =head1 DESCRIPTION prt is the command line frontend of L. =head1 SUBCOMMANDS =over 4 =item * replace_token Replace C token with C. prt replace_token foo bar Replace C token with C but target statements must have C token. prt replace_token foo bar --in-statement bazz =item * rename_class Rename C class to C class. prt rename_class Foo Bar =item * rename_namespace Rename C and C classes to C and C classes. prt rename_namespace Foo Bar =item * delete_method Delete C method from C class. prt delete_method Food eat =item * move_class_method Move C method in C class to C method in C. C's including packages are copied to C. prt move_class_method 'Class#method' 'AnotherClass#another_method' =back =head1 TARGET FILES You can specify the target files to refactor. prt replace_token foo bar lib/**/**.pm t/*.t # Refactor Perl modules in lib/ and test files in t/ Without target files, C collects source codes in your project automatically. C searches C to detect project root directory. When executed in git repository, All files in the repository are used. prt replace_token foo bar # Refactor the project in current working directory =head1 LICENSE Copyright (C) hitode909. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR hitode909 Ehitode909@gmail.comE =cut cpanfile100644000765000024 116012401224621 14405 0ustar00hitode909staff000000000000App-PRT-0.19requires 'perl', '5.010001'; requires 'Class::Load'; requires 'Getopt::Long', '2.42'; requires 'PPI'; requires 'Path::Class'; requires 'File::Find::Rule'; on configure => sub { requires 'CPAN::Meta'; requires 'CPAN::Meta::Prereqs'; requires 'Module::Build'; }; on 'test' => sub { requires 'Test::More', '0.98'; requires 'Test::Class'; requires 'Test::Fatal'; requires 'Test::Deep'; requires 'Test::Mock::Guard'; requires 'Path::Class'; requires 'File::Temp'; requires 'File::Copy::Recursive'; requires 'parent'; }; on develop => sub { requires 'Test::Perl::Critic'; }; PRT.pm100644000765000024 117212401224621 15175 0ustar00hitode909staff000000000000App-PRT-0.19/lib/Apppackage App::PRT; use strict; use warnings; use 5.010001; our $VERSION = "0.19"; sub welcome { 'welcome!!!!'; } 1; __END__ =encoding utf-8 =head1 NAME App::PRT - Command line Perl Refactoring Tool =head1 SYNOPSIS use App::PRT::CLI; my $cli = App::PRT::CLI->new; $cli->parse(@ARGV); $cli->run; =head1 DESCRIPTION App::PRT is command line tools for Refactoring Perl. =head1 SEE ALSO L =head1 LICENSE Copyright (C) hitode909. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR hitode909 Ehitode909@gmail.comE =cut CLI.pm100644000765000024 450312401224621 15605 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRTpackage App::PRT::CLI; use strict; use warnings; use Class::Load qw(load_class); use Getopt::Long qw(GetOptionsFromArray); use Cwd (); use App::PRT::Collector::Files; use App::PRT::Collector::AllFiles; use App::PRT::Collector::GitDirectory; sub new { my ($class) = @_; bless {}, $class; } sub parse { my ($self, @args) = @_; my $command = shift @args or die 'prt '; my $command_class = $self->_command_name_to_command_class($command); eval { load_class $command_class; }; if ($@) { die "Command $command not found ($@)"; } $self->{command} = $command_class->new; my @rest_args = $self->{command}->parse_arguments(@args); my $collector = $self->_prepare_collector(@rest_args); unless ($collector) { die 'Cannot decide target files'; } $self->{collector} = $collector; 1; } sub run { my ($self) = @_; my $collector = $self->collector; my $command = $self->command; if ($command->can('execute_files')) { # TODO: create a base class for command? $command->execute_files($collector->collect); } else { for my $file (@{$collector->collect}) { $command->execute($file); } } } sub _prepare_collector { my ($class, @args) = @_; # target files specified? if (@args) { return App::PRT::Collector::Files->new(@args); } my $cwd = Cwd::getcwd; # git directory? my $git_root_directory = App::PRT::Collector::GitDirectory->find_git_root_directory($cwd); if ($git_root_directory) { return App::PRT::Collector::GitDirectory->new($git_root_directory); } # seems perl project? my $project_root_directory = App::PRT::Collector::AllFiles->find_project_root_directory($cwd); if ($project_root_directory) { return App::PRT::Collector::AllFiles->new($project_root_directory); } return; } sub command { my ($self) = @_; $self->{command}; } sub collector { my ($self) = @_; $self->{collector}; } sub _command_name_to_command_class { my ($self, $name) = @_; my $command_class = join '', map { ucfirst } split '_', $name; # XXX: Super hack to fix typo if ($command_class eq 'RenameNamespace') { $command_class = 'RenameNameSpace'; } 'App::PRT::Command::' . $command_class; } 1; AllFiles.pm100644000765000024 313712401224621 20621 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Collectorpackage App::PRT::Collector::AllFiles; use strict; use warnings; use File::Find::Rule; use Path::Class; # find project root directory from specified directory path # If exists cpanfile on path, it is a project root. # # returns: # directory path (when found) # undef (when not found) sub find_project_root_directory { my ($class, $directory) = @_; die "$directory does not exist" unless -d $directory; my $current = dir($directory); while (1) { if (-e $current->file('cpanfile')) { return $current->stringify; } if ($current eq $current->parent) { # not found return; } $current = $current->parent; } } sub new { my ($class, $directory) = @_; bless { directory => $directory, }, $class; } sub directory { my ($self) = @_; $self->{directory}; } sub collect { my ($self) = @_; die "directory @{[ $self->directory ]} does not exist" unless -d $self->directory; my @files = $self->_retrieve_all_perl_files; \@files; } sub _retrieve_all_perl_files { my ($self) = @_; my @ignore_directories = qw(share fatlib _build .git blib local); my $rule = File::Find::Rule->new; $rule = $rule->or($rule->new ->directory ->name(@ignore_directories) ->prune ->discard, $rule->new); my @files = $rule->file ->name(qr/\.(?:pl|pm|psgi|t)\Z/) ->in($self->directory); return @files; } 1; Files.pm100644000765000024 50112401224621 20140 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Collectorpackage App::PRT::Collector::Files; use strict; use warnings; sub new { my ($class, @files) = @_; bless { files => [@files], }, $class; } sub collect { my ($self) = @_; for my $file (@{$self->{files}}) { die "$file does not exist" unless -f $file; } $self->{files}; } 1; GitDirectory.pm100644000765000024 253212401224621 21534 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Collectorpackage App::PRT::Collector::GitDirectory; use strict; use warnings; use Path::Class; # find git directory from specified directory path # returns: # directory path (when found) # undef (when not found) sub find_git_root_directory { my ($class, $directory) = @_; die "$directory does not exist" unless -d $directory; my $current = dir($directory); while (1) { if (-d $current->subdir('.git')) { return $current->stringify; } if ($current eq $current->parent) { # not found return; } $current = $current->parent; } } sub new { my ($class, $directory) = @_; die 'directory requird' unless defined $directory; die "directory $directory does not exist" unless -d $directory; bless { directory => $directory, }, $class; } sub collect { my ($self) = @_; my $git_directory = dir($self->directory)->subdir('.git'); my $output = `git --no-pager --git-dir $git_directory ls-files --full-name 2> /dev/null`; if ($?) { # when success, exit status is 0 die "directory @{[ $self->directory ]} seems not a git repository"; } my $dir = dir($self->directory); [ map { $dir->file($_)->stringify } split /\n/, $output ]; } sub directory { my ($self) = @_; $self->{directory}; } 1; AddMethod.pm100644000765000024 271612401224621 20411 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::AddMethod; use strict; use warnings; use PPI; # Internal command to add method to file sub new { my ($class) = @_; bless { code => undef, }, $class; } # register a method # arguments: # $code: Source code string of method to add sub register { my ($self, $code) = @_; $self->{code} = $code; } sub code { my ($self) = @_; $self->{code}; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; my $document = PPI::Document->new($file); my $statements = $document->find('PPI::Statement'); die 'statement not found' unless $statements; my $after = $statements->[-1]; my $code_document = PPI::Document->new(\$self->code); my $code_statement = $code_document->find_first('PPI::Statement::Sub'); my @comments; my $cursor = $code_statement->first_token->previous_token; while (defined $cursor && (ref $cursor eq 'PPI::Token::Comment' || ref $cursor eq 'PPI::Token::Whitespace')) { unshift @comments, $cursor; $cursor = $cursor->previous_token; } while (ref $comments[0] eq 'PPI::Token::Whitespace') { shift @comments; } $after->insert_before($_) for @comments; $after->insert_before($code_statement); my $whitespaces_document = PPI::Document->new(\"\n\n"); $after->insert_before($_) for @{ $whitespaces_document->find('PPI::Token') }; $document->save($file); } 1; AddUse.pm100644000765000024 245612401224621 17726 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::AddUse; use strict; use warnings; use PPI; # Internal command to add use statement to file sub new { my ($class) = @_; bless { namespace => undef, }, $class; } # register a method # arguments: # $namespace: package name to use sub register { my ($self, $namespace) = @_; $self->{namespace} = $namespace; } sub namespace { my ($self) = @_; $self->{namespace}; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; my $document = PPI::Document->new($file); return unless $document; my $used = 0; my $last_use; my $include_statements = $document->find('PPI::Statement::Include'); if ($include_statements) { for my $statement (@$include_statements) { next unless defined $statement->module; if ($statement->module eq $self->namespace) { $used++; } $last_use = $statement; } } return if $used; my $insert_to = $last_use || $document->find_first('PPI::Statement::Package') || $document->find_first('PPI::Statement'); my $tokens_to_insert = PPI::Document->new(\"\nuse @{[ $self->namespace ]};"); $insert_to->add_element($tokens_to_insert); $document->save($file); } 1; DeleteMethod.pm100644000765000024 427312401224621 21123 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::DeleteMethod; use strict; use warnings; use PPI; sub new { my ($class) = @_; bless {}, $class; } # parse arguments from CLI # arguments: # @arguments # returns: # @rest_arguments sub parse_arguments { my ($self, @arguments) = @_; die "class and method required" unless @arguments >= 2; $self->register(shift @arguments => shift @arguments); @arguments; } # register a replacing rule # arguments: # $target_class_name: Target Class Name # $target_method_name: Target Method Name sub register { my ($self, $target_class_name, $target_method_name) = @_; $self->{target_class_name} = $target_class_name; $self->{target_method_name} = $target_method_name; } sub target_class_name { my ($self) = @_; $self->{target_class_name}; } sub target_method_name { my ($self) = @_; $self->{target_method_name}; } sub deleted_code { my ($self) = @_; $self->{deleted_code}; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; my $document = PPI::Document->new($file); return unless $document; my $package = $document->find_first('PPI::Statement::Package'); return unless $package; return unless $package->namespace eq $self->target_class_name; my $subs = $document->find('PPI::Statement::Sub'); my $replaced = 0; for my $sub (@$subs) { next unless $sub->name eq $self->target_method_name; my @garbages; # comment before method my $cursor = $sub->first_token->previous_token; while (defined $cursor && ref $cursor eq 'PPI::Token::Comment') { unshift @garbages, $cursor; $cursor = $cursor->previous_token; } # method body push @garbages, $sub; # whitespace after method $cursor = $sub->last_token->next_token; while (defined $cursor && ref $cursor eq 'PPI::Token::Whitespace') { push @garbages, $cursor; $cursor = $cursor->next_token; } $self->{deleted_code} = join '', @garbages; $_->remove for @garbages; $replaced++; } $document->save($file) if $replaced; } 1; MoveClassMethod.pm100644000765000024 1167212401224621 21636 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::MoveClassMethod; use strict; use warnings; use PPI; use Path::Class; use App::PRT::Command::ReplaceToken; use App::PRT::Command::AddUse; use App::PRT::Command::AddMethod; use App::PRT::Command::DeleteMethod; use App::PRT::Util::DestinationFile; sub new { my ($class) = @_; bless { source_class_name => undef, source_method_name => undef, destination_class_name => undef, destination_method_name => undef, }, $class; } # parse arguments from CLI # arguments: # @arguments # returns: # @rest_arguments sub parse_arguments { my ($self, @arguments) = @_; die "source and destination are required" unless @arguments >= 2; $self->register(shift @arguments => shift @arguments); @arguments; } # register a replacing rule # arguments: # $source: source class name and method name, joined by '#' # $dest: destination class name and method name, joined by '#' sub register { my ($self, $source, $destination) = @_; die 'invalid format' unless $source =~ qr/\A[^#]+#[^#]+\Z/; die 'invalid format' unless $destination; ($self->{source_class_name}, $self->{source_method_name}) = split '#', $source; ($self->{destination_class_name}, $self->{destination_method_name}) = split '#', $destination; $self->{destination_method_name} //= $self->{source_method_name}; } sub source_class_name { my ($self) = @_; $self->{source_class_name}; } sub source_method_name { my ($self) = @_; $self->{source_method_name}; } sub destination_class_name { my ($self) = @_; $self->{destination_class_name}; } sub destination_method_name { my ($self) = @_; $self->{destination_method_name}; } sub source_method_body { my ($self) = @_; $self->{source_method_body}; } sub destination_method_body { my ($self) = @_; my $document = PPI::Document->new(\$self->{source_method_body}); my $sub = $document->find_first('PPI::Statement::Sub'); $sub->schild(1)->set_content($self->destination_method_name); $document->content; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; my $replaced = $self->_try_replace_tokens($file); # TODO: # - Move comment before method? # - Move pod? # - Move test code? my $document = PPI::Document->new($file); # When parse failed return unless $document; my $method_body = $self->_try_delete_method_and_get_deleted_code($file); if ($method_body) { $self->{source_method_body} = $method_body; # replace $class->$method $self->_try_replace_tokens_in_target_class($file); $document = PPI::Document->new($file); my $destination_file = App::PRT::Util::DestinationFile::destination_file( $self->source_class_name, $self->destination_class_name, $file ); unless (-e $destination_file) { # prepare destination file my $fh = file($destination_file)->open('w'); print $fh <destination_class_name ]}; 1; CODE $fh->close; } { # move method my $command = App::PRT::Command::AddMethod->new; $command->register($self->destination_method_body); $command->execute($destination_file); } # copy including modules my $packages_in_source = [ map { $_->module } @{ $document->find('PPI::Statement::Include') } ]; for my $package (@$packages_in_source) { my $command = App::PRT::Command::AddUse->new; $command->register($package); $command->execute($destination_file); } 1; } $replaced; } sub _try_replace_tokens { my ($self, $file) = @_; my $command = App::PRT::Command::ReplaceToken->new; $command->register( "@{[ $self->source_class_name ]}->@{[ $self->source_method_name ]}", "@{[ $self->destination_class_name ]}->@{[ $self->destination_method_name ]}" ); if ($command->execute($file)) { $self->_try_add_use($file); } } sub _try_replace_tokens_in_target_class { my ($self, $file) = @_; my $command = App::PRT::Command::ReplaceToken->new; $command->register( "\$class->@{[ $self->source_method_name ]}", "@{[ $self->destination_class_name ]}->@{[ $self->destination_method_name ]}" ); if ($command->execute($file)) { $self->_try_add_use($file); } } sub _try_add_use { my ($self, $file) = @_; my $command = App::PRT::Command::AddUse->new; $command->register($self->destination_class_name); $command->execute($file); } sub _try_delete_method_and_get_deleted_code { my ($self, $file) = @_; my $command = App::PRT::Command::DeleteMethod->new; $command->register($self->source_class_name, $self->source_method_name); if ($command->execute($file)) { return $command->deleted_code; } } 1; RenameClass.pm100644000765000024 1416412401224621 20775 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::RenameClass; use strict; use warnings; use PPI; use App::PRT::Util::DestinationFile; use Path::Class; sub new { my ($class) = @_; bless { rule => undef, }, $class; } # parse arguments from CLI # arguments: # @arguments # returns: # @rest_arguments sub parse_arguments { my ($self, @arguments) = @_; die "source and destination class are required" unless @arguments >= 2; $self->register(shift @arguments => shift @arguments); @arguments; } # register a replacing rule # arguments: # $source: source class name # $dest: destination class name sub register { my ($self, $source_class_name, $destination_class_name) = @_; $self->{source_class_name} = $source_class_name; $self->{destination_class_name} = $destination_class_name; } sub source_class_name { my ($self) = @_; $self->{source_class_name}; } sub destination_class_name { my ($self) = @_; $self->{destination_class_name}; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; my $replaced = 0; my $document = PPI::Document->new($file); # When parse failed return unless $document; my $should_rename = $self->_try_rename_package_statement($document); $replaced += $self->_try_rename_includes($document); $replaced += $self->_try_rename_parent_class($document); $replaced += $self->_try_rename_quotes($document); $replaced += $self->_try_rename_tokens($document); $replaced += $self->_try_rename_symbols($document); if ($should_rename) { my $dest_file = App::PRT::Util::DestinationFile::destination_file($self->source_class_name, $self->destination_class_name, $file); my $dest_dir = file($dest_file)->dir; $dest_dir->mkpath; $document->save($dest_file); unlink($file); $dest_file; } else { return unless $replaced; $document->save($file); $file; } } # returns: should rename this document? sub _try_rename_package_statement { my ($self, $document) = @_; my $package = $document->find_first('PPI::Statement::Package'); return unless $package; return unless $package->namespace eq $self->source_class_name; my $namespace = $package->schild(1); return unless $namespace->isa('PPI::Token::Word'); $namespace->set_content($self->destination_class_name); # rename this file when the first token is package (heuristic) return $document->find_first('PPI::Token') eq 'package'; } sub _try_rename_includes { my ($self, $document) = @_; my $replaced = 0; my $statements = $document->find('PPI::Statement::Include'); return 0 unless $statements; for my $statement (@$statements) { next unless defined $statement->module; next unless $statement->module eq $self->source_class_name; my $module = $statement->schild(1); return unless $module->isa('PPI::Token::Word'); $module->set_content($self->destination_class_name); $replaced++; } $replaced; } sub _try_rename_quotes { my ($self, $document) = @_; my $replaced = 0; my $quotes = $document->find('PPI::Token::Quote'); return 0 unless $quotes; for my $quote (@$quotes) { next unless $quote->string eq $self->source_class_name; $quote->set_content("'@{[ $self->destination_class_name ]}'"); $replaced++; } $replaced; } # TODO: too complicated sub _try_rename_parent_class { my ($self, $document) = @_; my $replaced = 0; my $includes = $document->find('PPI::Statement::Include'); return 0 unless $includes; for my $statement (@$includes) { next unless defined $statement->pragma; next unless $statement->pragma =~ /^parent|base$/; # only 'use parent' and 'use base' are supported # schild(2) is 'Foo' of use parent Foo my $parent = $statement->schild(2); if ($parent->isa('PPI::Token::Quote')) { # The 'literal' method is not implemented by ::Quote::Double or ::Quote::Interpolate. my $string = $parent->can('literal') ? $parent->literal : $parent->string; if ($string eq $self->source_class_name) { $parent->set_content("'@{[ $self->destination_class_name ]}'"); $replaced++; } } elsif ($parent->isa('PPI::Token::QuoteLike::Words')) { # use parent qw(A B C) pattern # literal is array when QuoteLike::Words my $_replaced = 0; my @new_literal = map { if ($_ eq $self->source_class_name) { $_replaced++; $self->destination_class_name; } else { $_; } } $parent->literal; if ($_replaced) { $parent->set_content('qw(' . join(' ', @new_literal) . ')'); $replaced++; } } } $replaced; } # discussions: # seems too wild sub _try_rename_tokens { my ($self, $document) = @_; my $replaced = 0; my $tokens = $document->find('PPI::Token'); return 0 unless $tokens; for my $token (@$tokens) { next unless $token->content eq $self->source_class_name; $token->set_content($self->destination_class_name); $replaced++; } $replaced; } # e.g. # $Foo::Bar::GLOBAL_VAR # ~~~~~~~~ Rename here # # $Foo::Bar::Buz::GLOBAL_VAR <= Don't rename because it's not the same class sub _try_rename_symbols { my ($self, $document) = @_; my $replaced = 0; my $symbols = $document->find('PPI::Token::Symbol'); return 0 unless $symbols; my $source_class_name = $self->source_class_name; my $destination_class_name = $self->destination_class_name; for my $symbol (@$symbols) { my $content = $symbol->content; my $sigil = substr $content, 0, 1, ''; if ($content =~ s/\A${source_class_name}::// && scalar(split /::/, $content) == 1) { $symbol->set_content($sigil . $destination_class_name . '::' . $content); $replaced++; } } $replaced; } 1; RenameNameSpace.pm100644000765000024 503412401224621 21540 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::RenameNameSpace; use strict; use warnings; use PPI; use App::PRT::Command::RenameClass; sub new { my ($class) = @_; bless { source_name_space => undef, target_hname_space => undef, }, $class; } # parse arguments from CLI # arguments: # @arguments # returns: # @rest_arguments sub parse_arguments { my ($self, @arguments) = @_; die "source and destination class are required" unless @arguments >= 2; $self->register(shift @arguments => shift @arguments); @arguments; } # register a replacing rule # arguments: # $source: source name space # $dest: destination name space sub register { my ($self, $source_name_space, $destination_name_space) = @_; $self->{source_name_space} = $source_name_space; $self->{destination_name_space} = $destination_name_space; } sub source_name_space { my ($self) = @_; $self->{source_name_space}; } sub destination_name_space { my ($self) = @_; $self->{destination_name_space}; } # refactor files # argumensts: # $files: [ filenames for refactoring ] sub execute_files { my ($self, $files) = @_; my $target_classes = $self->_collect_target_classes($files); my $knowns = { map { $_ => 1 } @$target_classes }; for my $target_class (@$target_classes) { my $rename_command = App::PRT::Command::RenameClass->new; $rename_command->register($target_class => $self->_destination_class_name($target_class)); for my $file (@$files) { next unless -f $file; my $file_after = $rename_command->execute($file); if ($file_after && $file_after ne $file && !$knowns->{$file_after}) { $knowns->{$file_after}++; push @$files, $file_after; } } } } sub _collect_target_classes { my ($self, $files) = @_; [ grep { $_ } map { $self->_is_target_class($_); } @$files ]; } sub _is_target_class { my ($self, $file) = @_; my $document = PPI::Document->new($file); # When parse failed return unless $document; my $package = $document->find_first('PPI::Statement::Package'); return unless $package; if (index($package->namespace, $self->source_name_space) == 0) { $package->namespace; } } sub _destination_class_name { my ($self, $class_name) = @_; return unless index($class_name, $self->source_name_space) == 0; my $dest = $class_name; $self->destination_name_space . substr($class_name, length($self->source_name_space)); } 1; ReplaceToken.pm100644000765000024 1016012401224621 21144 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Commandpackage App::PRT::Command::ReplaceToken; use strict; use warnings; use PPI; sub new { my ($class) = @_; bless { source_tokens => undef, destination_tokens => undef, statement_in => undef, }, $class; } # parse arguments from CLI # arguments: # @arguments # returns: # @rest_arguments sub parse_arguments { my ($self, @arguments) = @_; die "source and destination tokens required" unless @arguments >= 2; $self->register(shift @arguments => shift @arguments); if (@arguments >= 2 && $arguments[0] eq '--in-statement') { shift @arguments; $self->set_replace_only_statement_which_has_token(shift @arguments); } @arguments; } # register a replacing rule # arguments: # $source: source token # $destination: destinationination token # discussions: # should consider utf-8 flag ? sub register { my ($self, $source, $destination) = @_; my $source_tokens = do { my $document = PPI::Document::Fragment->new(\$source); [ map { $_->content } @{ $document->find('PPI::Token') } ]; }; my $destination_tokens = do { my $document = PPI::Document::Fragment->new(\$destination); [ map { $_->content } @{ $document->find('PPI::Token') } ]; }; $self->{source_tokens} = $source_tokens; $self->{destination_tokens} = $destination_tokens; } sub set_replace_only_statement_which_has_token { my ($self, $in) = @_; $self->{statement_in} = $in; } sub replace_only_statement_which_has_token { my ($self) = @_; $self->{statement_in}; } sub source_tokens { my ($self) = @_; $self->{source_tokens}; } sub destination_tokens { my ($self) = @_; $self->{destination_tokens}; } # refactor a file # argumensts: # $file: filename for refactoring sub execute { my ($self, $file) = @_; return unless defined $self->source_tokens; my $document = PPI::Document->new($file); # When parse failed return unless $document; my $replaced = 0; if (defined $self->replace_only_statement_which_has_token) { $replaced += $self->_replace_in_statement($document); } else { $replaced += $self->_replace_all($document); } $document->save($file) if $replaced; } sub _replace_all { my ($self, $document) = @_; my $tokens = $document->find('PPI::Token'); return 0 unless $tokens; my $replaced = 0; for my $token (@$tokens) { $replaced += $self->_try_replace($token); } $replaced; } sub _try_replace { my ($self, $token) = @_; my @matched = $self->_match($token); return 0 unless @matched; my $first = shift @matched; $first->set_content(join '', @{$self->destination_tokens}); $_->set_content('') for @matched; # removing `(` will delete (...). So set empty content. 1; } sub _match { my ($self, $token) = @_; my @matched; for my $source (@{$self->source_tokens}) { if ($token->content eq $source) { push @matched, $token; $token = $token->next_token; } elsif (@matched && $token->next_token && ref $token eq 'PPI::Token::Whitespace') { # ignore white spaces of source push @matched, $token; $token = $token->next_token; redo; } else { return; } } return @matched; } sub _replace_in_statement { my ($self, $document) = @_; my $statements = $document->find('PPI::Statement'); return 0 unless $statements; my $replaced = 0; for my $statement (@$statements) { next if ref $statement eq 'PPI::Statement::Sub'; next if ref $statement eq 'PPI::Statement::Compound'; next if $statement->schild(0)->content eq 'do'; my $found = 0; my $tokens = $statement->find('PPI::Token'); for my $token (@$tokens) { if ($token->content eq $self->replace_only_statement_which_has_token) { $found++; last; } } next unless $found; for my $token (@$tokens) { $replaced += $self->_try_replace($token); } } $replaced; } 1; DestinationFile.pm100644000765000024 133712401224621 21176 0ustar00hitode909staff000000000000App-PRT-0.19/lib/App/PRT/Utilpackage App::PRT::Util::DestinationFile; use strict; use warnings; use Path::Class; sub destination_file { my ($source_class_name, $destination_class_name, $input_file) = @_; my @delimiters = do { my $pattern = $source_class_name; $pattern =~ s{::}{(.+)}g; ($input_file =~ qr/^(.*)$pattern(.*)$/); }; my $prefix = shift @delimiters; my $suffix = pop @delimiters; my $fallback_delimiter = $delimiters[-1]; my $dir = file($input_file)->dir; $dir = $dir->parent for grep { $_ eq '/' } @delimiters; my $basename = $destination_class_name; $basename =~ s{::}{ shift @delimiters // $fallback_delimiter; }ge; $dir->file("$basename$suffix")->stringify; } 1; minil.toml100644000765000024 6212401224621 14646 0ustar00hitode909staff000000000000App-PRT-0.19name = "App-PRT" badges = ["travis", "coveralls"] App-PRT-CLI.t100644000765000024 1327612401224621 15154 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::CLI; use t::test; use FindBin; use File::Basename (); sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::CLI'; } sub instantiate : Tests { isa_ok App::PRT::CLI->new, 'App::PRT::CLI'; } sub _command_name_to_command_class : Tests { my $cli = App::PRT::CLI->new; is $cli->_command_name_to_command_class('hello'), 'App::PRT::Command::Hello', 'ucfirst'; is $cli->_command_name_to_command_class('replace_token'), 'App::PRT::Command::ReplaceToken', 'separate by _'; subtest 'alias' => sub { is $cli->_command_name_to_command_class('rename_namespace'), 'App::PRT::Command::RenameNameSpace', 'rename_namespace is alias for rename_name_space. Namespace is not name space'; }; } sub parse : Tests { subtest 'when empty input' => sub { my $cli = App::PRT::CLI->new; like exception { $cli->parse(); }, qr/prt /; }; subtest 'when command specified, not a git directory' => sub { my $directory = t::test::prepare_test_code('contain_ignores'); my $g = mock_guard 'Cwd' => { getcwd => "$directory", }; my $cli = App::PRT::CLI->new; $cli->parse(qw{replace_token foo bar}); cmp_deeply $cli->command, isa('App::PRT::Command::ReplaceToken') & methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], ), 'ReplaceToken command loaded'; cmp_deeply $cli->collector, isa('App::PRT::Collector::AllFiles') & methods( directory => $directory, ); }; subtest 'when command specified, git directory' => sub { my $directory = t::test::prepare_test_code('dinner'); t::test::prepare_as_git_repository($directory); my $g = mock_guard 'Cwd' => { getcwd => "$directory", }; my $cli = App::PRT::CLI->new; $cli->parse(qw{replace_token foo bar}); cmp_deeply $cli->command, isa('App::PRT::Command::ReplaceToken') & methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], ), 'ReplaceToken command loaded'; cmp_deeply $cli->collector, isa('App::PRT::Collector::GitDirectory') & methods( directory => $directory, ); }; subtest 'when source, destination, target files specified' => sub { my $cli = App::PRT::CLI->new; my $directory = t::test::prepare_test_code('dinner'); $cli->parse( qw{replace_token foo bar}, qq{$directory/dinner.pl}, qq{$directory/lib/My/Food.pm}, qq{$directory/lib/My/Human.pm} ); cmp_deeply $cli->command, isa('App::PRT::Command::ReplaceToken') & methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], ), 'ReplaceToken command loaded and foo => bar registered'; cmp_deeply $cli->collector, isa('App::PRT::Collector::Files') & methods( collect => [ qq{$directory/dinner.pl}, qq{$directory/lib/My/Food.pm}, qq{$directory/lib/My/Human.pm} ], ), 'Files collector loaded and files are registered'; }; subtest 'when target ' => sub { my $directory = t::test::prepare_test_code('contain_ignores'); my $g = mock_guard 'Cwd' => { getcwd => "$directory", }; my $cli = App::PRT::CLI->new; $cli->parse(qw{replace_token foo bar}); cmp_deeply $cli->command, isa('App::PRT::Command::ReplaceToken') & methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], ), 'ReplaceToken command loaded'; cmp_deeply $cli->collector, isa('App::PRT::Collector::AllFiles') & methods( directory => $directory, ); }; subtest 'when neither git directory or project root directory detected' => sub { my $directory = t::test::prepare_test_code('hello_world'); my $g = mock_guard 'Cwd' => { getcwd => "$directory", }; my $cli = App::PRT::CLI->new; like exception { $cli->parse(qw{replace_token foo bar}); }, qr/Cannot decide target files/; }; subtest 'when invalid command specified' => sub { my $cli = App::PRT::CLI->new; like exception { $cli->parse('invalid_command'); }, qr/Command invalid_command not found/; } } sub run : Tests { subtest 'command which can execute' => sub { my $directory = t::test::prepare_test_code('hello_world'); my $cli = App::PRT::CLI->new; $cli->parse(qw(replace_token foo bar), "$directory/hello_world.pl"); my $file; my $g = mock_guard 'App::PRT::Command::ReplaceToken' => { execute => sub { (undef, $file) = @_; }, }; $cli->run; is $g->call_count('App::PRT::Command::ReplaceToken', 'execute'), 1, 'execute called'; is $file, "$directory/hello_world.pl", 'called with file' }; subtest 'command which can execute_files' => sub { my $directory = t::test::prepare_test_code('dinner'); my $cli = App::PRT::CLI->new; $cli->parse(qw(rename_namespace My Our), "$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm"); my $files; my $g = mock_guard 'App::PRT::Command::RenameNameSpace' => { execute_files => sub { (undef, $files) = @_; }, }; $cli->run; is $g->call_count('App::PRT::Command::RenameNameSpace', 'execute_files'), 1, 'execute_files called'; cmp_deeply $files, ["$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm"], 'called with files'; }; } App-PRT-Collector-AllFiles.t100644000765000024 342112401224621 20133 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Collector::AllFiles; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Collector::AllFiles'; } sub instantiate : Tests { my $collector = App::PRT::Collector::AllFiles->new('foo/'); isa_ok $collector, 'App::PRT::Collector::AllFiles'; is $collector->directory, 'foo/'; } sub find_project_root_directory: Tests { subtest 'directory without cpanfile' => sub { my $directory = t::test::prepare_test_code('hello_world'); is App::PRT::Collector::AllFiles->find_project_root_directory($directory), undef, 'not found'; }; subtest 'directory with cpanfile' => sub { my $directory = t::test::prepare_test_code('contain_ignores'); is App::PRT::Collector::AllFiles->find_project_root_directory($directory), $directory, 'found from root directory'; is App::PRT::Collector::AllFiles->find_project_root_directory("$directory/lib"), $directory, 'found from sub directory'; }; subtest 'not existing directory' => sub { ok exception { App::PRT::Collector::AllFiles->find_project_root_directory('/not/existing/directory'); }; }; } sub collect: Tests { my $directory = t::test::prepare_test_code('contain_ignores'); my $files = [ "$directory/app.psgi", "$directory/eg/eg.pl", "$directory/lib/Foo.pm", "$directory/lib/Foo/Bar.pm", "$directory/t/test.t", ]; my $collector = App::PRT::Collector::AllFiles->new($directory); cmp_bag $collector->collect, $files, 'all files are returned'; subtest 'not existing directory' => sub { my $collector = App::PRT::Collector::AllFiles->new('/not/existing/directory'); ok exception { $collector->collect; }; }; } App-PRT-Collector-Files.t100644000765000024 222212401224621 17500 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Collector::Files; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Collector::Files'; } sub instantiate : Tests { isa_ok App::PRT::Collector::Files->new, 'App::PRT::Collector::Files'; } sub collect : Tests { my $directory = t::test::prepare_test_code('hello_world'); subtest 'when files specified' => sub { my $collector = App::PRT::Collector::Files->new("$directory/hello_world.pl"); is_deeply $collector->collect, ["$directory/hello_world.pl"]; }, 'specified files returned'; subtest 'when not existing file specified' => sub { my $collector = App::PRT::Collector::Files->new("$directory/not_existd.pl"); ok exception { $collector->collect; }, 'died'; }; } sub collect_multi_files: Tests { my $directory = t::test::prepare_test_code('dinner'); my $files = [ "$directory/dinner.pl", "$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm", ]; my $collector = App::PRT::Collector::Files->new(@$files); is_deeply $collector->collect, $files, 'specified files are returned'; } App-PRT-Command-AddMethod.t100644000765000024 374112401224621 17726 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::AddMethod; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::AddMethod'; } sub instantiate : Tests { isa_ok App::PRT::Command::AddMethod->new, 'App::PRT::Command::AddMethod'; } sub register : Tests { my $command = App::PRT::Command::AddMethod->new; $command->register('sub one { 1 }'); is $command->code, 'sub one { 1 }'; } sub execute : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::AddMethod->new; $command->register(< sub { $command->execute($human_file); is file($human_file)->slurp, <<'CODE', 'sub one added to last'; package My::Human; use strict; use warnings; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } sub eat { my ($self, $food) = @_; print "@{[ $self->name ]} is eating @{[ $food->name ]}.\n"; } sub one { return 1; } 1; CODE }; } sub execute_with_comment : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::AddMethod->new; $command->register(< sub { $command->execute($human_file); is file($human_file)->slurp, <<'CODE', 'sub one added to last'; package My::Human; use strict; use warnings; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } sub eat { my ($self, $food) = @_; print "@{[ $self->name ]} is eating @{[ $food->name ]}.\n"; } # returns 1 # You can use when you want one sub one { return 1; } 1; CODE }; } App-PRT-Command-AddUse.t100644000765000024 364412401224621 17244 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::AddUse; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::AddUse'; } sub instantiate : Tests { isa_ok App::PRT::Command::AddUse->new, 'App::PRT::Command::AddUse'; } sub register : Tests { subtest 'package' => sub { my $command = App::PRT::Command::AddUse->new; $command->register('My::Package'); is $command->namespace, 'My::Package'; }; subtest 'package and arguments' => sub { my $command = App::PRT::Command::AddUse->new; $command->register('My::Package qw()'); is $command->namespace, 'My::Package qw()'; }; } sub execute : Tests { my $directory = t::test::prepare_test_code('greeting'); my $command = App::PRT::Command::AddUse->new; $command->register('Hi'); subtest 'script with use statement, not using Hi' => sub { my $file = "$directory/use_greeting.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'Hi was added'; use strict; use warnings; use lib 'lib'; use Greeting; use Hi; print Greeting->hi('Alice'); print Greeting->bye('Bob'); CODE }; subtest 'script, already using Hi' => sub { my $file = "$directory/use_greeting_and_hi.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'Hi was not added'; use strict; use warnings; use lib 'lib'; use Greeting; use Hi; print Greeting->hi('Alice'); print Greeting->bye('Bob'); CODE }; subtest 'script without any use, but with package statement' => sub { my $file = "$directory/no_use_but_package.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'Hi was added after package statement'; package Main; use Hi; print Greeting->hi('Alice'); print Greeting->bye('Bob'); CODE }; } App-PRT-Command-DeleteMethod.t100644000765000024 573312401224621 20443 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::DeleteMethod; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::DeleteMethod'; } sub instantiate : Tests { isa_ok App::PRT::Command::DeleteMethod->new, 'App::PRT::Command::DeleteMethod'; } sub register : Tests { my $command = App::PRT::Command::DeleteMethod->new; $command->register('My::Food' => 'name'); is $command->target_class_name, 'My::Food'; is $command->target_method_name, 'name'; } sub parse_arguments : Tests { subtest "when class and method specified" => sub { my $command = App::PRT::Command::DeleteMethod->new; my @args = qw(Class method a.pl lib/B.pm); my @args_after = $command->parse_arguments(@args); is $command->target_class_name, 'Class'; is $command->target_method_name, 'method'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when arguments are not enough" => sub { my $command = App::PRT::Command::DeleteMethod->new; ok exception { $command->parse_arguments('Method'); }, 'died'; }; } sub execute : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::DeleteMethod->new; $command->register('My::Human' => 'name'); my $human_file = "$directory/lib/My/Human.pm"; my $food_file = "$directory/lib/My/Food.pm"; subtest 'target file' => sub { ok $command->execute($human_file); is file($human_file)->slurp, <<'CODE', 'name removed'; package My::Human; use strict; use warnings; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub eat { my ($self, $food) = @_; print "@{[ $self->name ]} is eating @{[ $food->name ]}.\n"; } 1; CODE is $command->deleted_code, <<'CODE', 'deleted code stored'; sub name { my ($self) = @_; $self->{name}; } CODE }; subtest 'another file' => sub { my $before = file($food_file)->slurp; ok ! $command->execute($food_file); is file($food_file)->slurp, $before, 'nothing happen'; }; } sub execute_delete_method_and_comment : Tests { my $directory = t::test::prepare_test_code('method_with_comment'); my $command = App::PRT::Command::DeleteMethod->new; $command->register('FoodWithComment' => 'new'); my $file = "$directory/FoodWithComment.pm"; $command->execute($file); is $command->deleted_code, <<'CODE', 'comment before method was deleted'; # create a new food # You can use when you want to create a new instance sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } CODE $command->register('FoodWithComment' => 'name'); $command->execute($file); is $command->deleted_code, <<'CODE', 'another comment was not deleted because previous token of sub name is whitespace'; sub name { my ($self) = @_; $self->{name}; } CODE } App-PRT-Command-MoveClassMethod.t100644000765000024 1725212401224621 21154 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::MoveClassMethod; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::MoveClassMethod'; } sub instantiate : Tests { isa_ok App::PRT::Command::MoveClassMethod->new, 'App::PRT::Command::MoveClassMethod'; } sub register_rule : Tests { subtest 'valid rule' => sub { my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Source#source' => 'Dest#dest'); is $command->source_class_name, 'Source'; is $command->source_method_name, 'source'; is $command->destination_class_name, 'Dest'; is $command->destination_method_name, 'dest'; }; subtest 'when destination method name is same' => sub { my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Source#source' => 'Dest'); is $command->source_class_name, 'Source'; is $command->source_method_name, 'source'; is $command->destination_class_name, 'Dest'; is $command->destination_method_name, 'source'; }; subtest 'invalid syntax' => sub { my $command = App::PRT::Command::MoveClassMethod->new; ok exception { $command->register('Source' => 'Dest'); }, qr/invalid format/; ok exception { $command->register('Source' => 'Dest#dest'); }, qr/invalid format/; }; } sub execute_method_body_when_destination_file_exists : Tests { my $directory = t::test::prepare_test_code('greeting'); my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Greeting#hi' => 'Hi#hello'); my $file = "$directory/lib/Greeting.pm"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'hi method was removed'; package Greeting; use strict; use warnings; use Hello; use GoodAfternoon; sub bye { my ($class, $name) = @_; "Bye, $name\n"; } 1; CODE my $source_method = <<'METHOD'; sub hi { my ($class, $name) = @_; "Hi, $name\n"; } METHOD is $command->source_method_body, $source_method, 'method body stored'; my $destination_method = <<'METHOD'; sub hello { my ($class, $name) = @_; "Hi, $name\n"; } METHOD is $command->destination_method_body, $destination_method, 'destination method prepared'; my $destination_file = "$directory/lib/Hi.pm"; ok -f $destination_file, 'destination file exists'; is file($destination_file)->slurp, <<'CODE', 'hello method was added, use GoodAfternoon was added because it may be necessary'; package Hi; use strict; use warnings; use Hello; use GoodAfternoon; sub good_morning { my ($class, $name) = @_; "Good morning, $name\n"; } sub hello { my ($class, $name) = @_; "Hi, $name\n"; } 1; CODE } sub execute_method_body_when_destination_file_not_exists : Tests { my $directory = t::test::prepare_test_code('greeting'); my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Greeting#hi' => 'Salutation#hello'); my $file = "$directory/lib/Greeting.pm"; $command->execute($file); ok -f $file, 'source file exists'; my $destination_file = "$directory/lib/Salutation.pm"; ok -f $destination_file, 'destination file exists'; is file($destination_file)->slurp, <<'CODE', 'hello was added, uses are copied'; package Salutation; use strict; use warnings; use Hello; use GoodAfternoon; sub hello { my ($class, $name) = @_; "Hi, $name\n"; } 1; CODE } sub execute_method_move_comment_too : Tests { my $directory = t::test::prepare_test_code('method_with_comment'); my $command = App::PRT::Command::MoveClassMethod->new; $command->register('FoodWithComment#new' => 'AnotherClass#another_new'); my $file = "$directory/FoodWithComment.pm"; $command->execute($file); my $destination_file = "$directory/AnotherClass.pm"; ok -f $destination_file, 'destination file exists'; is file($destination_file)->slurp, <<'CODE', 'method and comment was added'; package AnotherClass; use strict; use warnings; # create a new food # You can use when you want to create a new instance sub another_new { my ($class, $name) = @_; bless { name => $name, }, $class; } 1; CODE } sub execute_call_as_class_method : Tests { my $directory = t::test::prepare_test_code('greeting'); my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Bye#good' => 'Good#very_good'); my $file = "$directory/lib/Bye.pm"; $command->execute($file); ok -f $file, 'source file exists'; is file($file)->slurp, <<'CODE', 'use was Added, $class->good was replaced'; package Bye; use strict; use warnings; use Hello; use Good; sub good_bye { my ($class, $name) = @_; Good->very_good("bye, $name\n"); } 1; CODE } sub execute_client_script : Tests { my $directory = t::test::prepare_test_code('greeting'); my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Greeting#hi' => 'Hi#hello'); subtest 'client script with use Greeting' => sub { my $file = "$directory/use_greeting.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'calling Greeting#hi was rewritten, use Hi was added'; use strict; use warnings; use lib 'lib'; use Greeting; use Hi; print Hi->hello('Alice'); print Greeting->bye('Bob'); CODE }; subtest 'client script with use Greeting and Hi' => sub { my $file = "$directory/use_greeting_and_hi.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'calling Greeting#hi was rewritten, Hi was not added'; use strict; use warnings; use lib 'lib'; use Greeting; use Hi; print Hi->hello('Alice'); print Greeting->bye('Bob'); CODE }; subtest 'client script without Greeting or Hi' => sub { my $file = "$directory/no_use.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'calling Greeting#hi was rewritten, Hi was added after last use'; use strict; use warnings; use lib 'lib'; use Hi; print Hi->hello('Alice'); print Greeting->bye('Bob'); CODE }; subtest 'client script without Greeting or Hi, with package statement' => sub { my $file = "$directory/no_use_but_package.pl"; $command->execute($file); ok -f $file, 'File exists'; is file($file)->slurp, <<'CODE', 'calling Greeting#hi was rewritten, Hi was added after package statement'; package Main; use Hi; print Hi->hello('Alice'); print Greeting->bye('Bob'); CODE }; } sub execute_for_not_perl_file: Tests { my $directory = t::test::prepare_test_code('readme'); my $readme = "$directory/README.md"; my $command = App::PRT::Command::MoveClassMethod->new; $command->register('Greeting#hi' => 'Hi#hello'); $command->execute($readme); ok -f $readme, 'README exists'; } sub parse_arguments : Tests { subtest "when source and destination specified" => sub { my $command = App::PRT::Command::MoveClassMethod->new; my @args = ('From#from', 'To#to', qw(a.pl lib/B.pm)); my @args_after = $command->parse_arguments(@args); is $command->source_class_name, 'From'; is $command->source_method_name, 'from'; is $command->destination_class_name, 'To'; is $command->destination_method_name, 'to'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when arguments are not enough" => sub { my $command = App::PRT::Command::MoveClassMethod->new; ok exception { $command->parse_arguments('From'); }, 'died'; }; } App-PRT-Command-RenameClass.t100644000765000024 1610712401224621 20312 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::RenameClass; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::RenameClass'; } sub instantiate : Tests { isa_ok App::PRT::Command::RenameClass->new, 'App::PRT::Command::RenameClass'; } sub register_rule : Tests { my $command = App::PRT::Command::RenameClass->new; $command->register('Foo' => 'Bar'); is $command->source_class_name, 'Foo'; is $command->destination_class_name, 'Bar'; } sub execute : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::RenameClass->new; $command->register('My::Food' => 'My::Meal'); subtest 'target class' => sub { my $food_file = "$directory/lib/My/Food.pm"; my $meal_file = "$directory/lib/My/Meal.pm"; is $command->execute($food_file), $meal_file, 'returns destination file when success'; ok ! -f $food_file, "Food.pm doesn't exists"; ok -e $meal_file, "Meal.pm exists"; is file($meal_file)->slurp, <<'CODE', 'package statement was rewritten'; package My::Meal; use strict; use warnings; $My::Meal::SOME_MAGIC_NUMBER = '0.01'; $My::Food::Foo::GLOBAL_VAR = 'foobar'; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } 1; CODE }; subtest 'client file' => sub { my $dinner_file = "$directory/dinner.pl"; is $command->execute($dinner_file), $dinner_file, 'returns source file when success and not moved'; ok -f $dinner_file, 'dinner.pl exists'; is file($dinner_file)->slurp, <<'CODE', 'use statement and class-method invocation were rewritten'; use strict; use warnings; use lib 'lib'; use My::Human; use My::Meal; undef *My::Meal::new; undef *My::Food::Foo::new; my $human = My::Human->new('Alice'); my $food = My::Meal->new('Pizza'); $human->eat($food); CODE }; } sub execute_with_inherit : Tests { my $directory = t::test::prepare_test_code('inherit'); my $command = App::PRT::Command::RenameClass->new; $command->register('Parent' => 'Boss'); subtest 'target class' => sub { my $file = "$directory/inherit.pl"; $command->execute($file); ok -e $file, "script file exists"; is file($file)->slurp, <<'CODE', 'use parent, use base statements were rewritten'; package Child1 { use DateTime; use utf8; use parent 'Boss'; }; package Child2 { use parent qw(Boss AnotherParent YetAnother::Parent); }; package Child3 { use base 'Boss'; }; package Child4 { use base 'Boss'; }; package Child5 { use base 'Boss'; }; package Child6 { use base 'Boss'; }; package GrandChild { use base 'Child'; }; CODE }; } sub execute_test_more_style_test_file : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::RenameClass->new; $command->register('My::Food' => 'My::Meal'); my $file = "$directory/t/001-my-food._t"; $command->execute($file); is file($file)->slurp, <<'CODE', 'test replaced'; use Test::More tests => 5; use_ok 'My::Meal'; require_ok 'My::Meal'; new_ok 'My::Meal'; isa_ok My::Meal->new, 'My::Meal'; subtest 'name' => sub { my $pizza = My::Meal->new('Pizza'); is $pizza->name, 'Pizza'; }; CODE } sub execute_test_class_style_test_file: Tests { my $directory = t::test::prepare_test_code('dinner'); my $food_file = "$directory/t/My-Food._t"; my $meal_file = "$directory/t/My-Meal._t"; my $command1 = App::PRT::Command::RenameClass->new; $command1->register('t::My::Food' => 't::My::Meal'); $command1->execute($food_file); ok ! -f $food_file, "Food._t doesn't exists"; ok -e $meal_file, "Meal._t exists"; is file($meal_file)->slurp, <<'CODE', 'package statement replaced'; package t::My::Meal; use base qw(Test::Class); use Test::More; sub _load : Test(startup => 1) { use_ok 'My::Food'; } sub instantiate : Test(1) { isa_ok My::Food->new('banana'), 'My::Food'; } sub name : Test(1) { my $food = My::Food->new('banana'); is $food->name, 'banana'; } __PACKAGE__->runtests; CODE } sub execute_for_not_perl_file: Tests { my $directory = t::test::prepare_test_code('readme'); my $readme = "$directory/README.md"; my $command = App::PRT::Command::RenameClass->new; $command->register('Alice' => 'Bob'); $command->execute($readme); ok -f $readme, 'README exists'; } sub execute_rename_to_deeper_directory : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::RenameClass->new; $command->register('My::Food' => 'My::Special::Great::Food'); subtest 'target class' => sub { my $food_file = "$directory/lib/My/Food.pm"; my $special_food_file = "$directory/lib/My/Special/Great/Food.pm"; is $command->execute($food_file), $special_food_file, 'success'; ok ! -f $food_file, "Food.pm doesn't exists"; ok -e $special_food_file, "Special::Great::Food.pm exists"; }; } sub execute_rename_package_in_block_statement : Tests { my $directory = t::test::prepare_test_code('package_in_block'); my $command = App::PRT::Command::RenameClass->new; $command->register('Hello' => 'Greeting'); subtest '{ package } style' => sub { my $script = "$directory/package_in_block.pl"; is $command->execute($script), $script, 'success'; ok -e $script, "script exists"; is file($script)->slurp, <<'CODE', 'package statement replaced'; use strict; use warnings; { package Greeting; sub hello { "hello!" } }; print Greeting->hello; CODE }; subtest 'package { } style' => sub { my $script = "$directory/package_block_statement.pl"; is $command->execute($script), $script, 'success'; ok -e $script, "script exists"; is file($script)->slurp, <<'CODE', 'package statement replaced'; use strict; use warnings; package Greeting { sub hello { "hello" } }; print Greeting->hello; CODE }; subtest 'multi packages' => sub { my $script = "$directory/multi_packages.pl"; is $command->execute($script), $script, 'success'; ok -e $script, "script exists"; is file($script)->slurp, <<'CODE', 'package statement replaced'; use strict; use warnings; package Bye { sub bye { "bye" } }; package Greeting { sub hello { "hello" } }; print Greeting->hello; CODE }; } sub parse_arguments : Tests { subtest "when source and destination specified" => sub { my $command = App::PRT::Command::RenameClass->new; my @args = qw(From To a.pl lib/B.pm); my @args_after = $command->parse_arguments(@args); is $command->source_class_name, 'From'; is $command->destination_class_name, 'To'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when arguments are not enough" => sub { my $command = App::PRT::Command::RenameClass->new; ok exception { $command->parse_arguments('hi'); }, 'died'; }; } App-PRT-Command-RenameNameSpace.t100644000765000024 700212401224621 21053 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::RenameNameSpace; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::RenameNameSpace'; } sub instantiate : Tests { isa_ok App::PRT::Command::RenameNameSpace->new, 'App::PRT::Command::RenameNameSpace'; } sub register_rule : Tests { my $command = App::PRT::Command::RenameNameSpace->new; $command->register('Foo' => 'Bar'); is $command->source_name_space, 'Foo'; is $command->destination_name_space, 'Bar'; } sub parse_arguments : Tests { subtest "when source and destination specified" => sub { my $command = App::PRT::Command::RenameNameSpace->new; my @args = qw(From To a.pl lib/B.pm); my @args_after = $command->parse_arguments(@args); is $command->source_name_space, 'From'; is $command->destination_name_space, 'To'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when arguments are not enough" => sub { my $command = App::PRT::Command::RenameClass->new; ok exception { $command->parse_arguments('NotEnough'); }, 'died'; }; } sub _collect_target_classes : Tests { my $command = App::PRT::Command::RenameNameSpace->new; $command->register('My' => 'Our'); my $directory = t::test::prepare_test_code('dinner'); cmp_bag $command->_collect_target_classes([ "$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm", "$directory/lib/Your/Food.pm", "$directory/dinner.pl", ]), [ 'My::Food', 'My::Human', ], 'classes under My:: are collected'; } sub _destination_class_name : Tests { my $command = App::PRT::Command::RenameNameSpace->new; $command->register('My' => 'Our'); is $command->_destination_class_name('My::Food'), 'Our::Food', 'converted'; is $command->_destination_class_name('The::My::Food'), undef, 'not match'; is $command->_destination_class_name('Our::Food'), undef, 'not match'; } sub execute : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::RenameNameSpace->new; $command->register('My' => 'Our'); $command->execute_files([ "$directory/dinner.pl", "$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm", "$directory/lib/Your/Food.pm", "$directory/t/001-my-food._t", "$directory/t/My-Food._t", ]); ok -f "$directory/dinner.pl", "script exists"; is file("$directory/dinner.pl")->slurp, <<'CODE', 'My:: was moved to Our::'; use strict; use warnings; use lib 'lib'; use Our::Human; use Our::Food; undef *Our::Food::new; undef *My::Food::Foo::new; my $human = Our::Human->new('Alice'); my $food = Our::Food->new('Pizza'); $human->eat($food); CODE ok ! -f "$directory/lib/My/Food.pm", "My::Food doesn't exist"; ok ! -f "$directory/lib/My/Human.pm", "My::Human doesn't exist"; ok -f "$directory/lib/Our/Food.pm", "Our::Food exist"; ok -f "$directory/lib/Our/Human.pm", "Our::Human exist"; is file("$directory/lib/Our/Food.pm")->slurp, <<'CODE', 'target class replaced'; package Our::Food; use strict; use warnings; $Our::Food::SOME_MAGIC_NUMBER = '0.01'; $My::Food::Foo::GLOBAL_VAR = 'foobar'; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } 1; CODE is file("$directory/lib/Your/Food.pm")->slurp, <<'CODE', 'not changed'; package Your::Food; 1; CODE } App-PRT-Command-ReplaceToken.t100644000765000024 1526412401224621 20474 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Command::ReplaceToken; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Command::ReplaceToken'; } sub instantiate : Tests { isa_ok App::PRT::Command::ReplaceToken->new, 'App::PRT::Command::ReplaceToken'; } sub register_rules : Tests { subtest 'single token' => sub { my $command = App::PRT::Command::ReplaceToken->new; is $command->source_tokens, undef; is $command->destination_tokens, undef; $command->register('print' => 'warn'); is_deeply $command->source_tokens, [ 'print' ]; is_deeply $command->destination_tokens, [ 'warn' ]; }; subtest 'multi tokens' => sub { my $command = App::PRT::Command::ReplaceToken->new; is $command->source_tokens, undef; is $command->destination_tokens, undef; $command->register('$foo->bar' => '$bar->baz->qux'); is_deeply $command->source_tokens, [ '$foo', '->', 'bar' ]; is_deeply $command->destination_tokens, [ '$bar', '->', 'baz', '->', 'qux' ]; }; subtest 'replace_only_statement_which_has_token' => sub { my $command = App::PRT::Command::ReplaceToken->new; is $command->replace_only_statement_which_has_token, undef; $command->set_replace_only_statement_which_has_token('$fh'); is $command->replace_only_statement_which_has_token, '$fh'; }; } sub execute : Tests { my $directory = t::test::prepare_test_code('hello_world'); my $command = App::PRT::Command::ReplaceToken->new; my $file = "$directory/hello_world.pl"; subtest 'nothing happen when no rules are specified' => sub { ok ! $command->execute($file), 'fails'; is file($file)->slurp, <<'CODE', 'nothing changed'; print "Hello, World!\n"; CODE }; subtest 'tokens will be replaced when a rules is specified' => sub { $command->register('print' => 'warn'); ok $command->execute($file), 'success'; is file($file)->slurp, <<'CODE', 'changed'; warn "Hello, World!\n"; CODE }; } sub execute_with_replace_only_statement_which_has_token : Tests { my $directory = t::test::prepare_test_code('dinner'); subtest 'only statement with My::Food was replaced' => sub { my $command = App::PRT::Command::ReplaceToken->new; $command->register(new => 'new->bake'); $command->set_replace_only_statement_which_has_token('My::Food'); my $file = "$directory/dinner.pl"; $command->execute($file); is file($file)->slurp, <<'CODE'; use strict; use warnings; use lib 'lib'; use My::Human; use My::Food; undef *My::Food::new; undef *My::Food::Foo::new; my $human = My::Human->new('Alice'); my $food = My::Food->new->bake('Pizza'); $human->eat($food); CODE }; subtest 'only statement with My::Food was replaced' => sub { my $command = App::PRT::Command::ReplaceToken->new; $command->register('$class' => '$klass'); $command->set_replace_only_statement_which_has_token('@_'); my $file = "$directory/lib/My/Food.pm"; $command->execute($file); is file($file)->slurp, <<'CODE', 'target is `my ($class, $name) = @_;`, not subroutine'; package My::Food; use strict; use warnings; $My::Food::SOME_MAGIC_NUMBER = '0.01'; $My::Food::Foo::GLOBAL_VAR = 'foobar'; sub new { my ($klass, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } 1; CODE }; } sub execute_replace_token_sequences : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::ReplaceToken->new; $command->register('My::Human->new' => 'NewHuman'); my $file = "$directory/dinner.pl"; $command->execute($file); is file($file)->slurp, <<'CODE'; use strict; use warnings; use lib 'lib'; use My::Human; use My::Food; undef *My::Food::new; undef *My::Food::Foo::new; my $human = NewHuman('Alice'); my $food = My::Food->new('Pizza'); $human->eat($food); CODE } sub execute_replace_token_sequences_in_statement : Tests { my $directory = t::test::prepare_test_code('dinner'); my $command = App::PRT::Command::ReplaceToken->new; $command->register('new(' => 'new->bake('); # `new` and `(` $command->set_replace_only_statement_which_has_token('My::Food'); my $file = "$directory/dinner.pl"; $command->execute($file); is file($file)->slurp, <<'CODE', 'new( in statement with My::Food was replaced'; use strict; use warnings; use lib 'lib'; use My::Human; use My::Food; undef *My::Food::new; undef *My::Food::Foo::new; my $human = My::Human->new('Alice'); my $food = My::Food->new->bake('Pizza'); $human->eat($food); CODE } sub execute_with_whitespace : Tests { my $directory = t::test::prepare_test_code('method_call_with_whitespace'); my $command = App::PRT::Command::ReplaceToken->new; $command->register("hello('World')" => "hello('Work')"); my $file = "$directory/hello.pl"; $command->execute($file); is file($file)->slurp, <<'CODE', 'all hello are replaced'; hello('Work'); hello('Work'); hello('Work'); CODE } sub execute_for_not_perl_file: Tests { my $directory = t::test::prepare_test_code('readme'); my $readme = "$directory/README.md"; my $command = App::PRT::Command::ReplaceToken->new; $command->register('alice' => 'bob'); $command->execute($readme); ok -f $readme, 'README exists'; } sub parse_arguments : Tests { subtest "when source and destination specified" => sub { my $command = App::PRT::Command::ReplaceToken->new; my @args = qw(foo bar a.pl lib/B.pm); my @args_after = $command->parse_arguments(@args); cmp_deeply $command, methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], replace_only_statement_which_has_token => undef, ), 'registered'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when source, destination, and --in-statement specified" => sub { my $command = App::PRT::Command::ReplaceToken->new; my @args = qw(foo bar --in-statement bazz a.pl lib/B.pm); my @args_after = $command->parse_arguments(@args); cmp_deeply $command, methods( source_tokens => [ 'foo' ], destination_tokens => [ 'bar' ], replace_only_statement_which_has_token => 'bazz', ), 'registered'; cmp_deeply \@args_after, [qw(a.pl lib/B.pm)], 'parse_arguments returns rest arguments'; }; subtest "when arguments are not enough" => sub { my $command = App::PRT::Command::ReplaceToken->new; ok exception { $command->parse_arguments('hi'); }, 'died'; }; } App-PRT-Util-DestinationFile.t100644000765000024 274112401224621 20514 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT::Util::DestinationFile; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Util::DestinationFile'; } sub destination_file : Tests { for my $case ( ['Foo', 'Bar', 'Foo.pm', './Bar.pm', 'without directory'], ['Foo', 'Bar', 'Foo.pm', './Bar.pm', 'with directory'], ['Foo', 'Bar', 'Foo.txt', './Bar.txt', 'with extname'], ['Foo::Bar', 'Foo::Bazz', 'Foo/Bar.pm', 'Foo/Bazz.pm', 'move deeper'], ['Foo::Bar::Bazz', 'Foo::Bar', 'Foo/Bar/Bazz.pm', 'Foo/Bar.pm', 'move lighter'], ['Foo::Bar::Bazz', 'Foo::Bar', '/tmp/lib/Foo/Bar/Bazz.pm', '/tmp/lib/Foo/Bar.pm', 'absolute path'], ['Test::Foo', 'Test::Foo::Bar', 't/lib/Test/Foo.pm', 't/lib/Test/Foo/Bar.pm', 't/lib'], ['t::Foo', 't::Bar', 't/Foo.t', 't/Bar.t', 'test file'], ['A::B::C', 'D::E::F', 'A-B_C.pm', './D-E_F.pm', 'separated with -, _'], ['A::B', 'A::B::C::D', 'A-B.pm', './A-B-C-D.pm', 'separated with -, _, move deeper'], ['A::B::C::D', 'A::B', 'A-B-C-D.pm', './A-B.pm', 'separated with -, _, move lighter'], ['A::B::C', 'D::E::F::G', 'A/B-C.pm', 'D/E-F-G.pm', 'separated with -, _, mixed with directory'], ) { my ($source_class_name, $destination_class_name, $input_file, $expected_file, $description) = @$case; is App::PRT::Util::DestinationFile::destination_file($source_class_name => $destination_class_name => $input_file), $expected_file, $description; } } App-PRT.t100644000765000024 27012401224621 14475 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::PRT; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT'; } sub welcome : Tests { is App::PRT->welcome, 'welcome!!!!'; } App-Prt-Collector-GitDirectory.t100644000765000024 446412401224621 21160 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::App::Prt::Collector::GitDirectory; use t::test; sub _require : Test(startup => 1) { my ($self) = @_; use_ok 'App::PRT::Collector::GitDirectory'; } sub find_git_root_directory : Tests { my $directory = t::test::prepare_test_code('dinner'); is App::PRT::Collector::GitDirectory->find_git_root_directory($directory), undef, 'not a git directory'; t::test::prepare_as_git_repository($directory); is App::PRT::Collector::GitDirectory->find_git_root_directory($directory), $directory, 'find from root directory'; is App::PRT::Collector::GitDirectory->find_git_root_directory("$directory/lib"), $directory, 'find from sub directory'; ok exception { App::PRT::Collector::GitDirectory->find_git_root_directory('/not/existing/directory'); }, 'dies when not existing directory'; } sub instantiate : Tests { my $directory = t::test::prepare_test_code('hello_world'); ok exception { App::PRT::Collector::GitDirectory->new; }, 'directory required'; ok exception { App::PRT::Collector::GitDirectory->new('not_exist_directory'); }, 'existing directory required'; t::test::prepare_as_git_repository($directory); subtest 'can initialize with git repository' => sub { my $collector = App::PRT::Collector::GitDirectory->new($directory); isa_ok $collector, 'App::PRT::Collector::GitDirectory'; is $collector->directory, $directory, 'collector has directory'; is_deeply $collector->collect, [ "$directory/hello_world.pl" ], 'collector can collect'; }; } sub collect : Tests { my $directory = t::test::prepare_test_code('dinner'); t::test::prepare_as_git_repository($directory); my $collector = App::PRT::Collector::GitDirectory->new($directory); cmp_bag $collector->collect, [ "$directory/dinner.pl", "$directory/lib/My/Food.pm", "$directory/lib/My/Human.pm", "$directory/lib/Your/Food.pm", "$directory/t/001-my-food._t", "$directory/t/My-Food._t", ], 'all files in directory are returned'; subtest 'when not a git directory' => sub { my $directory = t::test::prepare_test_code('hello_world'); my $collector = App::PRT::Collector::GitDirectory->new($directory); ok exception { $collector->collect; }; }; } Build.pm100644000765000024 012401224621 22001 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/_buildapp.psgi100644000765000024 012401224621 20612 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignoresBlib.pm100644000765000024 012401224621 21264 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/blibcpanfile100644000765000024 012401224621 20652 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignoreseg.pl100644000765000024 012401224621 20471 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/egFatlib.pm100644000765000024 012401224621 22146 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/fatlibFoo.pm100644000765000024 012401224621 20775 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/libBar.pm100644000765000024 012401224621 21501 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/lib/FooLocal.pm100644000765000024 012401224621 21630 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/localshare.pl100644000765000024 012401224621 21707 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/sharetest.t100644000765000024 7112401224621 20605 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/contain_ignores/tuse strict; use Test::More; ok 1, 'dummy'; done_testing; dinner.pl100644000765000024 32712401224621 17134 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinneruse strict; use warnings; use lib 'lib'; use My::Human; use My::Food; undef *My::Food::new; undef *My::Food::Foo::new; my $human = My::Human->new('Alice'); my $food = My::Food->new('Pizza'); $human->eat($food); Food.pm100644000765000024 42212401224621 17674 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinner/lib/Mypackage My::Food; use strict; use warnings; $My::Food::SOME_MAGIC_NUMBER = '0.01'; $My::Food::Foo::GLOBAL_VAR = 'foobar'; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } 1; Human.pm100644000765000024 45712401224621 20065 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinner/lib/Mypackage My::Human; use strict; use warnings; sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } sub name { my ($self) = @_; $self->{name}; } sub eat { my ($self, $food) = @_; print "@{[ $self->name ]} is eating @{[ $food->name ]}.\n"; } 1; Food.pm100644000765000024 3012401224621 20220 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinner/lib/Yourpackage Your::Food; 1; 001-my-food._t100644000765000024 33612401224621 17757 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinner/tuse Test::More tests => 5; use_ok 'My::Food'; require_ok 'My::Food'; new_ok 'My::Food'; isa_ok My::Food->new, 'My::Food'; subtest 'name' => sub { my $pizza = My::Food->new('Pizza'); is $pizza->name, 'Pizza'; }; My-Food._t100644000765000024 47712401224621 17367 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/dinner/tpackage t::My::Food; use base qw(Test::Class); use Test::More; sub _load : Test(startup => 1) { use_ok 'My::Food'; } sub instantiate : Test(1) { isa_ok My::Food->new('banana'), 'My::Food'; } sub name : Test(1) { my $food = My::Food->new('banana'); is $food->name, 'banana'; } __PACKAGE__->runtests; Bye.pm100644000765000024 31412401224621 17464 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greeting/libpackage Bye; use strict; use warnings; use Hello; sub good { my ($class, $message) = @_; "Good $message"; } sub good_bye { my ($class, $name) = @_; $class->good("bye, $name\n"); } 1; Greeting.pm100644000765000024 31212401224621 20507 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greeting/libpackage Greeting; use strict; use warnings; use Hello; use GoodAfternoon; sub hi { my ($class, $name) = @_; "Hi, $name\n"; } sub bye { my ($class, $name) = @_; "Bye, $name\n"; } 1; Hi.pm100644000765000024 20612401224621 17305 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greeting/libpackage Hi; use strict; use warnings; use Hello; sub good_morning { my ($class, $name) = @_; "Good morning, $name\n"; } 1; no_use.pl100644000765000024 14312401224621 17466 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greetinguse strict; use warnings; use lib 'lib'; print Greeting->hi('Alice'); print Greeting->bye('Bob'); no_use_but_package.pl100644000765000024 11012401224621 22005 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greetingpackage Main; print Greeting->hi('Alice'); print Greeting->bye('Bob'); use_greeting.pl100644000765000024 16212401224621 20657 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greetinguse strict; use warnings; use lib 'lib'; use Greeting; print Greeting->hi('Alice'); print Greeting->bye('Bob'); use_greeting_and_hi.pl100644000765000024 17212401224621 22162 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/greetinguse strict; use warnings; use lib 'lib'; use Greeting; use Hi; print Greeting->hi('Alice'); print Greeting->bye('Bob'); hello_world.pl100644000765000024 3112401224621 21172 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/hello_worldprint "Hello, World!\n"; inherit.pl100644000765000024 60012401224621 17474 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/inheritpackage Child1 { use DateTime; use utf8; use parent 'Parent'; }; package Child2 { use parent qw(Parent AnotherParent YetAnother::Parent); }; package Child3 { use base 'Parent'; }; package Child4 { use base "Parent"; }; package Child5 { use base q{Parent}; }; package Child6 { use base qq/Parent/; }; package GrandChild { use base 'Child'; }; hello.pl100644000765000024 7012401224621 23176 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/method_call_with_whitespacehello('World'); hello( 'World' ); hello( 'World' ); FoodWithComment.pm100644000765000024 44712401224621 23505 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/method_with_commentpackage FoodWithComment; use strict; use warnings; # create a new food # You can use when you want to create a new instance sub new { my ($class, $name) = @_; bless { name => $name, }, $class; } # another comment sub name { my ($self) = @_; $self->{name}; } 1; multi_packages.pl100644000765000024 20512401224621 22614 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/package_in_blockuse strict; use warnings; package Bye { sub bye { "bye" } }; package Hello { sub hello { "hello" } }; print Hello->hello; package_block_statement.pl100644000765000024 13512401224621 24457 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/package_in_blockuse strict; use warnings; package Hello { sub hello { "hello" } }; print Hello->hello; package_in_block.pl100644000765000024 14412401224621 23061 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/package_in_blockuse strict; use warnings; { package Hello; sub hello { "hello!" } }; print Hello->hello; README.md100644000765000024 15412401224621 16553 0ustar00hitode909staff000000000000App-PRT-0.19/t/data/readme# README.md README.md describes this project. ## List - A - B - C ## Dan the Unicode Section 小飼弾 test.pm100644000765000024 256012401224621 14466 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::test; use strict; use warnings; use utf8; use Path::Class; use lib file(__FILE__)->dir->parent->subdir('lib')->stringify; use FindBin; use File::Spec::Functions qw/catfile/; use File::Temp qw(tempdir); use File::Copy::Recursive; # use Exporter::Lite (); our @EXPORT = qw( create_hello_world ); sub import { my ($class) = @_; strict->import; utf8->import; warnings->import; my ($package, $file) = caller; my $code = qq[ package $package; use strict; use warnings; use utf8; use parent qw(Test::Class); use Test::More; use Test::Fatal; use Test::Deep; use Test::Mock::Guard; use Path::Class; END { $package->runtests } ]; eval $code; die $@ if $@; } sub prepare_test_code { my ($name) = @_; my $base_directory = catfile($FindBin::Bin, 'data', $name); my $tmpdir = tempdir; unless (-d $base_directory) { die "$name is not defined"; } File::Copy::Recursive::dircopy($base_directory, $tmpdir); $tmpdir; } sub prepare_as_git_repository { my ($directory) = @_; # TODO: replace with https://metacpan.org/pod/Test::Git system "cd $directory && git init --quiet && git config user.email 'test at example.com' && git config user.name 'Tester' && git add * && git commit --quiet -m 'init'"; } 1; test.t100644000765000024 131412401224621 14311 0ustar00hitode909staff000000000000App-PRT-0.19/tpackage t::TestForTest; use t::test; sub _prepare_test_code : Tests { subtest 'valid input' => sub { my $directory = t::test::prepare_test_code('hello_world'); ok $directory; ok -d $directory, 'directory exists'; ok -f "$directory/hello_world.pl", 'hello_world.pl exists'; }; subtest 'valid input' => sub { ok exception { t::test::prepare_test_code('not_defined_name'); }, 'dies when specified code is not prepared' }; } sub _prepare_as_git_repository : Tests { my $directory = t::test::prepare_test_code('hello_world'); t::test::prepare_as_git_repository($directory); ok -d "$directory/.git", '.git directory exists'; } perlcritic.t100644000765000024 34412401224621 15644 0ustar00hitode909staff000000000000App-PRT-0.19/xt#!perl use strict; use Test::More; eval { require Test::Perl::Critic; Test::Perl::Critic->import( -profile => 'xt/perlcriticrc' ); }; plan skip_all => "Test::Perl::Critic is not installed." if $@; all_critic_ok('lib'); perlcriticrc100644000765000024 012401224621 15654 0ustar00hitode909staff000000000000App-PRT-0.19/xtMETA.yml100644000765000024 433712401224621 14163 0ustar00hitode909staff000000000000App-PRT-0.19--- abstract: 'Command line Perl Refactoring Tool' author: - 'This library is free software; you can redistribute it and/or modify' build_requires: File::Copy::Recursive: '0' File::Temp: '0' Path::Class: '0' Test::Class: '0' Test::Deep: '0' Test::Fatal: '0' Test::Mock::Guard: '0' Test::More: '0.98' parent: '0' configure_requires: CPAN::Meta: '0' CPAN::Meta::Prereqs: '0' Module::Build: '0.38' dynamic_config: 0 generated_by: 'Minilla/v2.1.1, CPAN::Meta::Converter version 2.142060' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: App-PRT no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: App::PRT: file: lib/App/PRT.pm version: '0.19' App::PRT::CLI: file: lib/App/PRT/CLI.pm App::PRT::Collector::AllFiles: file: lib/App/PRT/Collector/AllFiles.pm App::PRT::Collector::Files: file: lib/App/PRT/Collector/Files.pm App::PRT::Collector::GitDirectory: file: lib/App/PRT/Collector/GitDirectory.pm App::PRT::Command::AddMethod: file: lib/App/PRT/Command/AddMethod.pm App::PRT::Command::AddUse: file: lib/App/PRT/Command/AddUse.pm App::PRT::Command::DeleteMethod: file: lib/App/PRT/Command/DeleteMethod.pm App::PRT::Command::MoveClassMethod: file: lib/App/PRT/Command/MoveClassMethod.pm App::PRT::Command::RenameClass: file: lib/App/PRT/Command/RenameClass.pm App::PRT::Command::RenameNameSpace: file: lib/App/PRT/Command/RenameNameSpace.pm App::PRT::Command::ReplaceToken: file: lib/App/PRT/Command/ReplaceToken.pm App::PRT::Util::DestinationFile: file: lib/App/PRT/Util/DestinationFile.pm requires: Class::Load: '0' File::Find::Rule: '0' Getopt::Long: '2.42' PPI: '0' Path::Class: '0' perl: '5.010001' resources: bugtracker: https://github.com/hitode909/App-PRT/issues homepage: https://github.com/hitode909/App-PRT repository: git://github.com/hitode909/App-PRT.git version: '0.19' x_contributors: - 'Tatsuhiko Miyagawa ' - 'Takanori Ishikawa ' - 'moznion ' - 'Syohei YOSHIDA ' - 'hitode909 ' MANIFEST100644000765000024 376612401224621 14050 0ustar00hitode909staff000000000000App-PRT-0.19Build.PL Changes LICENSE META.json README.md bin/prt cpanfile lib/App/PRT.pm lib/App/PRT/CLI.pm lib/App/PRT/Collector/AllFiles.pm lib/App/PRT/Collector/Files.pm lib/App/PRT/Collector/GitDirectory.pm lib/App/PRT/Command/AddMethod.pm lib/App/PRT/Command/AddUse.pm lib/App/PRT/Command/DeleteMethod.pm lib/App/PRT/Command/MoveClassMethod.pm lib/App/PRT/Command/RenameClass.pm lib/App/PRT/Command/RenameNameSpace.pm lib/App/PRT/Command/ReplaceToken.pm lib/App/PRT/Util/DestinationFile.pm minil.toml t/App-PRT-CLI.t t/App-PRT-Collector-AllFiles.t t/App-PRT-Collector-Files.t t/App-PRT-Command-AddMethod.t t/App-PRT-Command-AddUse.t t/App-PRT-Command-DeleteMethod.t t/App-PRT-Command-MoveClassMethod.t t/App-PRT-Command-RenameClass.t t/App-PRT-Command-RenameNameSpace.t t/App-PRT-Command-ReplaceToken.t t/App-PRT-Util-DestinationFile.t t/App-PRT.t t/App-Prt-Collector-GitDirectory.t t/data/contain_ignores/_build/Build.pm t/data/contain_ignores/app.psgi t/data/contain_ignores/blib/Blib.pm t/data/contain_ignores/cpanfile t/data/contain_ignores/eg/eg.pl t/data/contain_ignores/fatlib/Fatlib.pm t/data/contain_ignores/lib/Foo.pm t/data/contain_ignores/lib/Foo/Bar.pm t/data/contain_ignores/local/Local.pm t/data/contain_ignores/share/share.pl t/data/contain_ignores/t/test.t t/data/dinner/dinner.pl t/data/dinner/lib/My/Food.pm t/data/dinner/lib/My/Human.pm t/data/dinner/lib/Your/Food.pm t/data/dinner/t/001-my-food._t t/data/dinner/t/My-Food._t t/data/greeting/lib/Bye.pm t/data/greeting/lib/Greeting.pm t/data/greeting/lib/Hi.pm t/data/greeting/no_use.pl t/data/greeting/no_use_but_package.pl t/data/greeting/use_greeting.pl t/data/greeting/use_greeting_and_hi.pl t/data/hello_world/hello_world.pl t/data/inherit/inherit.pl t/data/method_call_with_whitespace/hello.pl t/data/method_with_comment/FoodWithComment.pm t/data/package_in_block/multi_packages.pl t/data/package_in_block/package_block_statement.pl t/data/package_in_block/package_in_block.pl t/data/readme/README.md t/test.pm t/test.t xt/perlcritic.t xt/perlcriticrc META.yml MANIFEST