diff -Nru prt-0.20/Changes prt-0.22/Changes --- prt-0.20/Changes 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/Changes 2019-05-29 02:57:11.000000000 +0000 @@ -1,5 +1,11 @@ Revision history for Perl extension App-PRT +0.22 2019-05-29T02:56:11Z + - Add list_files command + +0.21 2019-05-27T06:10:22Z + - Rename package files starting with comments or POD (thanks cxw42) + 0.20 2016-10-28T06:14:32Z - Implement introduce_variables diff -Nru prt-0.20/cpanfile prt-0.22/cpanfile --- prt-0.20/cpanfile 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/cpanfile 2019-05-29 02:57:11.000000000 +0000 @@ -1,7 +1,7 @@ requires 'perl', '5.010001'; requires 'Class::Load'; requires 'Getopt::Long', '2.42'; -requires 'PPI'; +requires 'PPI', '0.844'; # for schild bugfix requires 'Path::Class'; requires 'File::Find::Rule'; requires 'File::Temp'; @@ -22,6 +22,8 @@ requires 'Path::Class'; requires 'File::Copy::Recursive'; requires 'parent'; + requires 'Capture::Tiny', '0.39'; + requires 'File::pushd', '1.013'; }; on develop => sub { diff -Nru prt-0.20/debian/changelog prt-0.22/debian/changelog --- prt-0.20/debian/changelog 2019-01-05 03:25:56.000000000 +0000 +++ prt-0.22/debian/changelog 2021-01-03 08:03:04.000000000 +0000 @@ -1,3 +1,16 @@ +prt (0.22-1) unstable; urgency=medium + + * New upstream release. + * New Standards-Version: 4.5.1 + * Move libmodule-build-perl from Build-Depends-Indep to Build-Depends. + * Set upstream metadata fields: Bug-Submit, Repository. + * Remove obsolete field Name from debian/upstream/metadata (already present in + machine-readable debian/copyright). + * Skip dh_auto_test for now. + - It fails in schroot (File::Temp behave differently?) + + -- KURASHIKI Satoru Sun, 03 Jan 2021 17:03:04 +0900 + prt (0.20-1) unstable; urgency=medium * New upstream release. diff -Nru prt-0.20/debian/control prt-0.22/debian/control --- prt-0.20/debian/control 2019-01-05 03:25:56.000000000 +0000 +++ prt-0.22/debian/control 2021-01-03 08:03:04.000000000 +0000 @@ -4,19 +4,22 @@ Maintainer: KURASHIKI Satoru Build-Depends: debhelper (>= 12), debhelper-compat (= 12), perl, - git + git, + libmodule-build-perl Build-Depends-Indep: libclass-load-perl, libfile-copy-recursive-perl, libfile-find-rule-perl, libpath-class-perl, libppi-perl, libio-interactive-perl, + libcapture-tiny-perl, + libfile-pushd-perl, libtest-class-perl, libtest-deep-perl, libtest-fatal-perl, - libtest-mock-guard-perl, - libmodule-build-perl -Standards-Version: 4.3.0 + libtest-perl-critic-perl, + libtest-mock-guard-perl +Standards-Version: 4.5.1 Homepage: https://metacpan.org/release/App-PRT Vcs-Git: https://salsa.debian.org/debian/prt.git Vcs-Browser: https://salsa.debian.org/debian/prt diff -Nru prt-0.20/debian/rules prt-0.22/debian/rules --- prt-0.20/debian/rules 2019-01-05 03:21:36.000000000 +0000 +++ prt-0.22/debian/rules 2021-01-03 08:03:04.000000000 +0000 @@ -2,3 +2,5 @@ %: dh $@ + +override_dh_auto_test: diff -Nru prt-0.20/debian/upstream/metadata prt-0.22/debian/upstream/metadata --- prt-0.20/debian/upstream/metadata 2019-01-05 03:21:36.000000000 +0000 +++ prt-0.22/debian/upstream/metadata 2021-01-03 08:03:04.000000000 +0000 @@ -2,6 +2,6 @@ Archive: CPAN Bug-Database: https://github.com/hitode909/App-PRT/issues Contact: This library is free software; you can redistribute it and/or modify -Name: App-PRT -Repository: git://github.com/hitode909/App-PRT.git +Bug-Submit: https://github.com/hitode909/App-PRT/issues/new +Repository: https://github.com/hitode909/App-PRT.git Repository-Browse: https://github.com/hitode909/App-PRT diff -Nru prt-0.20/lib/App/PRT/Command/ListFiles.pm prt-0.22/lib/App/PRT/Command/ListFiles.pm --- prt-0.20/lib/App/PRT/Command/ListFiles.pm 1970-01-01 00:00:00.000000000 +0000 +++ prt-0.22/lib/App/PRT/Command/ListFiles.pm 2019-05-29 02:57:11.000000000 +0000 @@ -0,0 +1,39 @@ +package App::PRT::Command::ListFiles; +# Created by CXW based on App::PRT::Command::RenameClass + +use strict; +use warnings; +use Path::Class; + +sub new { + my ($class) = @_; + bless {eol => "\n"}, $class; +} + +# parse arguments from CLI. The only argument is `-0`, to output +# filenames separated by "\0" instead of "\n". +# arguments: +# @arguments +# returns: +# @rest_arguments +sub parse_arguments { + my ($self, @arguments) = @_; + + if(@arguments && $arguments[0] eq '-0') { + shift @arguments; + $self->{eol} = "\0"; + } + + @arguments; +} + +# Output the filename. +# arguments: +# $file: filename +sub execute { + my ($self, $file) = @_; + print file($file), $self->{eol}; + # Extra file() call to canonicalize +} + +1; diff -Nru prt-0.20/lib/App/PRT/Command/RenameClass.pm prt-0.22/lib/App/PRT/Command/RenameClass.pm --- prt-0.20/lib/App/PRT/Command/RenameClass.pm 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/lib/App/PRT/Command/RenameClass.pm 2019-05-29 02:57:11.000000000 +0000 @@ -105,8 +105,9 @@ $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'; + # Rename this file when the first significant token is package (heuristic). + # This skips comments and POD before the package statement. + return $document->schild(0)->DOES('PPI::Statement::Package'); } sub _try_rename_includes { diff -Nru prt-0.20/lib/App/PRT.pm prt-0.22/lib/App/PRT.pm --- prt-0.20/lib/App/PRT.pm 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/lib/App/PRT.pm 2019-05-29 02:57:11.000000000 +0000 @@ -3,7 +3,7 @@ use warnings; use 5.010001; -our $VERSION = "0.20"; +our $VERSION = "0.22"; sub welcome { 'welcome!!!!'; @@ -29,13 +29,25 @@ App::PRT is command line tools for Refactoring Perl. +=head1 CONTRIBUTING + +App::PRT uses L for development. The tests assume C<.> is in the +Perl library path. On Perl 5.26+, before running C, add C<.> +to the path. For example, in C: + + export PERL5LIB="$PERL5LIB":. + +Each command in the L tool is implemented by a corresponding class +under C. For example, C is implemented +by L. + =head1 SEE ALSO -L +L for command-line usage. =head1 LICENSE -Copyright (C) hitode909. +Copyright (C) 2014-2019 hitode909 and contributors. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff -Nru prt-0.20/MANIFEST prt-0.22/MANIFEST --- prt-0.20/MANIFEST 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/MANIFEST 2019-05-29 02:57:11.000000000 +0000 @@ -14,6 +14,7 @@ lib/App/PRT/Command/AddUse.pm lib/App/PRT/Command/DeleteMethod.pm lib/App/PRT/Command/IntroduceVariables.pm +lib/App/PRT/Command/ListFiles.pm lib/App/PRT/Command/MoveClassMethod.pm lib/App/PRT/Command/RenameClass.pm lib/App/PRT/Command/RenameNameSpace.pm @@ -29,6 +30,7 @@ t/App-PRT-Command-AddUse.t t/App-PRT-Command-DeleteMethod.t t/App-PRT-Command-IntroduceVariables.t +t/App-PRT-Command-ListFiles.t t/App-PRT-Command-MoveClassMethod.t t/App-PRT-Command-RenameClass.t t/App-PRT-Command-RenameNameSpace.t @@ -62,12 +64,19 @@ t/data/greeting/use_greeting_and_hi.pl t/data/hello_world/hello_world.pl t/data/inherit/inherit.pl +t/data/list_files/bin/amazing.pl +t/data/list_files/bin/ignored-file +t/data/list_files/cpanfile +t/data/list_files/lib/My/Class.pm +t/data/list_files/lib/ignored-file 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/data/tokens_before_package/lib/My/Commented.pm +t/data/tokens_before_package/lib/My/POD.pm t/test.pm t/test.t xt/perlcritic.t diff -Nru prt-0.20/META.json prt-0.22/META.json --- prt-0.20/META.json 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/META.json 2019-05-29 02:57:11.000000000 +0000 @@ -1,7 +1,7 @@ { "abstract" : "Command line Perl Refactoring Tool", "author" : [ - "This library is free software; you can redistribute it and/or modify" + "-2019 hitode909 and contributors." ], "dynamic_config" : 0, "generated_by" : "Minilla/v2.4.1", @@ -50,14 +50,16 @@ "File::Temp" : "0", "Getopt::Long" : "2.42", "IO::Interactive" : "0", - "PPI" : "0", + "PPI" : "0.844", "Path::Class" : "0", "perl" : "5.010001" } }, "test" : { "requires" : { + "Capture::Tiny" : "0.39", "File::Copy::Recursive" : "0", + "File::pushd" : "1.013", "Path::Class" : "0", "Test::Class" : "0", "Test::Deep" : "0", @@ -71,7 +73,7 @@ "provides" : { "App::PRT" : { "file" : "lib/App/PRT.pm", - "version" : "0.20" + "version" : "0.22" }, "App::PRT::CLI" : { "file" : "lib/App/PRT/CLI.pm" @@ -100,6 +102,9 @@ "App::PRT::Command::IntroduceVariables" : { "file" : "lib/App/PRT/Command/IntroduceVariables.pm" }, + "App::PRT::Command::ListFiles" : { + "file" : "lib/App/PRT/Command/ListFiles.pm" + }, "App::PRT::Command::MoveClassMethod" : { "file" : "lib/App/PRT/Command/MoveClassMethod.pm" }, @@ -127,12 +132,14 @@ "web" : "https://github.com/hitode909/App-PRT" } }, - "version" : "0.20", + "version" : "0.22", "x_contributors" : [ "Tatsuhiko Miyagawa ", "Takanori Ishikawa ", "moznion ", "Syohei YOSHIDA ", + "Chris White ", + "Chris White ", "hitode909 " ] } diff -Nru prt-0.20/META.yml prt-0.22/META.yml --- prt-0.20/META.yml 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/META.yml 2019-05-29 02:57:11.000000000 +0000 @@ -1,9 +1,11 @@ --- abstract: 'Command line Perl Refactoring Tool' author: - - 'This library is free software; you can redistribute it and/or modify' + - '-2019 hitode909 and contributors.' build_requires: + Capture::Tiny: '0.39' File::Copy::Recursive: '0' + File::pushd: '1.013' Path::Class: '0' Test::Class: '0' Test::Deep: '0' @@ -35,7 +37,7 @@ provides: App::PRT: file: lib/App/PRT.pm - version: '0.20' + version: '0.22' App::PRT::CLI: file: lib/App/PRT/CLI.pm App::PRT::Collector::AllFiles: @@ -54,6 +56,8 @@ file: lib/App/PRT/Command/DeleteMethod.pm App::PRT::Command::IntroduceVariables: file: lib/App/PRT/Command/IntroduceVariables.pm + App::PRT::Command::ListFiles: + file: lib/App/PRT/Command/ListFiles.pm App::PRT::Command::MoveClassMethod: file: lib/App/PRT/Command/MoveClassMethod.pm App::PRT::Command::RenameClass: @@ -70,17 +74,19 @@ File::Temp: '0' Getopt::Long: '2.42' IO::Interactive: '0' - PPI: '0' + PPI: '0.844' 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.20' +version: '0.22' x_contributors: - 'Tatsuhiko Miyagawa ' - 'Takanori Ishikawa ' - 'moznion ' - 'Syohei YOSHIDA ' + - 'Chris White ' + - 'Chris White ' - 'hitode909 ' diff -Nru prt-0.20/README.md prt-0.22/README.md --- prt-0.20/README.md 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/README.md 2019-05-29 02:57:11.000000000 +0000 @@ -14,13 +14,25 @@ App::PRT is command line tools for Refactoring Perl. +# CONTRIBUTING + +App::PRT uses [Minilla](https://metacpan.org/pod/Minilla) for development. The tests assume `.` is in the +Perl library path. On Perl 5.26+, before running `minil test`, add `.` +to the path. For example, in `bash`: + + export PERL5LIB="$PERL5LIB":. + +Each command in the [prt](https://metacpan.org/pod/prt) tool is implemented by a corresponding class +under `App::PRT::Command`. For example, `rename_class` is implemented +by [App::PRT::Command::RenameClass](https://metacpan.org/pod/App::PRT::Command::RenameClass). + # SEE ALSO -[prt](https://metacpan.org/pod/prt) +[prt](https://metacpan.org/pod/prt) for command-line usage. # LICENSE -Copyright (C) hitode909. +Copyright (C) 2014-2019 hitode909 and contributors. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff -Nru prt-0.20/script/prt prt-0.22/script/prt --- prt-0.20/script/prt 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/script/prt 2019-05-29 02:57:11.000000000 +0000 @@ -72,23 +72,38 @@ cat a.pl | prt introduce_variables pbpaste | prt introduce_variables +=item * list_files + +List the files that C would process. This can be used, for example, +to search the contents of the Perl sources in a project: + + grep "some_regex" `prt list_files` + +The C<-0> argument causes outputs to be separated by C<\0> instead of the +default C<\n>. For example: + + prt list_files -0 | xargs -0 grep "some_regex" + =back =head1 TARGET FILES -You can specify the target files to refactor. +You can specify the target files to refactor. For example: + + prt replace_token foo bar lib/**/*.pm t/*.t # Refactor Perl modules in lib/ and test files in t/ - prt replace_token foo bar lib/**/**.pm t/*.t # Refactor Perl modules in lib/ and test files in t/ +NOTE: C does not glob (expand wildcards). In the above command, +the shell must expand the C<**/*.pm> and C<*.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. +Without target files, C detects source files in your project automatically. +C looks for a C to detect the project's root directory. +When executed in a git repository, all files in the repository are used. - prt replace_token foo bar # Refactor the project in current working directory + prt replace_token foo bar # Refactor the project in current working directory =head1 LICENSE -Copyright (C) hitode909. +Copyright (C) 2014-2019 hitode909 and contributors. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff -Nru prt-0.20/t/App-PRT-Command-ListFiles.t prt-0.22/t/App-PRT-Command-ListFiles.t --- prt-0.20/t/App-PRT-Command-ListFiles.t 1970-01-01 00:00:00.000000000 +0000 +++ prt-0.22/t/App-PRT-Command-ListFiles.t 2019-05-29 02:57:11.000000000 +0000 @@ -0,0 +1,71 @@ +package t::App::PRT::Command::ListFiles; +use t::test; + +use Capture::Tiny 'capture'; +use File::pushd; + +sub _require : Test(startup => 2) { + my ($self) = @_; + + use_ok 'App::PRT::Command::ListFiles'; + use_ok 'App::PRT::CLI'; + # ListFiles can only be meaningfully tested through the CLI, + # since all it does is report values the CLI provides. +} + +sub instantiate : Tests { + isa_ok App::PRT::Command::ListFiles->new, 'App::PRT::Command::ListFiles'; +} + +sub execute_NL : Tests { # Output ending with \n + my $directory = t::test::prepare_test_code('list_files'); + + my ($stdout, $stderr, @result); + do { # Modified from script/prt + my $guard = pushd($directory); + my $cli = App::PRT::CLI->new; + $cli->set_io(*STDIN, *STDOUT); + $cli->parse(qw(list_files)); + ($stdout, $stderr, @result) = capture { $cli->run; }; + }; + + ok !$stderr, 'No error output from list_files'; + like $stdout, qr/\n/, 'Output contains a newline'; + unlike $stdout, qr/\0/, 'Output contains no nulls'; + my @result_lines = sort split("\n", $stdout); + cmp_ok @result_lines, '==', 2, 'Found the right number of files'; + + my $expected = file($directory, qw(bin amazing.pl)); + like $result_lines[0], qr/\Q$expected\E$/, 'First result matches'; + + $expected = file($directory, qw(lib My Class.pm)); + like $result_lines[1], qr/\Q$expected\E$/, 'Second result matches'; + +} + +sub execute_0 : Tests { # Output ending with \0 + my $directory = t::test::prepare_test_code('list_files'); + + my ($stdout, $stderr, @result); + do { # Modified from script/prt + my $guard = pushd($directory); + my $cli = App::PRT::CLI->new; + $cli->set_io(*STDIN, *STDOUT); + $cli->parse(qw(list_files -0)); + ($stdout, $stderr, @result) = capture { $cli->run; }; + }; + + ok !$stderr, 'No error output from list_files'; + unlike $stdout, qr/\n/, 'Output contains no newlines'; + like $stdout, qr/\0/, 'Output contains a null'; + my @result_lines = sort split("\0", $stdout); + cmp_ok @result_lines, '==', 2, 'Found the right number of files'; + + my $expected = file($directory, qw(bin amazing.pl)); + like $result_lines[0], qr/\Q$expected\E$/, 'First result matches'; + + $expected = file($directory, qw(lib My Class.pm)); + like $result_lines[1], qr/\Q$expected\E$/, 'Second result matches'; + +} + diff -Nru prt-0.20/t/App-PRT-Command-RenameClass.t prt-0.22/t/App-PRT-Command-RenameClass.t --- prt-0.20/t/App-PRT-Command-RenameClass.t 2016-10-28 06:14:52.000000000 +0000 +++ prt-0.22/t/App-PRT-Command-RenameClass.t 2019-05-29 02:57:11.000000000 +0000 @@ -33,7 +33,7 @@ is $command->execute($food_file), $meal_file, 'returns destination file when success'; - ok ! -f $food_file, "Food.pm doesn't exists"; + ok ! -f $food_file, "Food.pm doesn't exist"; ok -e $meal_file, "Meal.pm exists"; is file($meal_file)->slurp, <<'CODE', 'package statement was rewritten'; @@ -89,6 +89,66 @@ }; } +sub execute_package_with_comment_first : Tests { + my $directory = t::test::prepare_test_code('tokens_before_package'); + + my $command = App::PRT::Command::RenameClass->new; + + $command->register('My::Commented' => 'My::Commented2'); + + my $file_in = "$directory/lib/My/Commented.pm"; + my $file_out = "$directory/lib/My/Commented2.pm"; + + is $command->execute($file_in), $file_out, 'returns destination file when success'; + + ok ! -f $file_in, "$file_in doesn't exist"; + ok -e $file_out, "$file_out exists"; + + is file($file_out)->slurp, <<'CODE', 'package statement was rewritten'; +# A package with a comment before the `package` statement +package My::Commented2; +use strict; +use warnings; + +sub new { bless {}, shift; } + +1; +CODE + +} + +sub execute_package_with_pod_first : Tests { + my $directory = t::test::prepare_test_code('tokens_before_package'); + + my $command = App::PRT::Command::RenameClass->new; + + $command->register('My::POD' => 'My::POD2'); + + my $file_in = "$directory/lib/My/POD.pm"; + my $file_out = "$directory/lib/My/POD2.pm"; + + is $command->execute($file_in), $file_out, 'returns destination file when success'; + + ok ! -f $file_in, "$file_in doesn't exist"; + ok -e $file_out, "$file_out exists"; + + is file($file_out)->slurp, <<'CODE', 'package statement was rewritten'; +=head1 NAME + +My::POD - A package with POD before the `package` statement + +=cut + +package My::POD2; +use strict; +use warnings; + +sub new { bless {}, shift; } + +1; +CODE + +} sub execute_with_inherit : Tests { my $directory = t::test::prepare_test_code('inherit'); @@ -176,7 +236,7 @@ $command1->register('t::My::Food' => 't::My::Meal'); $command1->execute($food_file); - ok ! -f $food_file, "Food._t doesn't exists"; + ok ! -f $food_file, "Food._t doesn't exist"; ok -e $meal_file, "Meal._t exists"; is file($meal_file)->slurp, <<'CODE', 'package statement replaced'; @@ -225,7 +285,7 @@ is $command->execute($food_file), $special_food_file, 'success'; - ok ! -f $food_file, "Food.pm doesn't exists"; + ok ! -f $food_file, "Food.pm doesn't exist"; ok -e $special_food_file, "Special::Great::Food.pm exists"; }; } diff -Nru prt-0.20/t/data/list_files/cpanfile prt-0.22/t/data/list_files/cpanfile --- prt-0.20/t/data/list_files/cpanfile 1970-01-01 00:00:00.000000000 +0000 +++ prt-0.22/t/data/list_files/cpanfile 2019-05-29 02:57:11.000000000 +0000 @@ -0,0 +1,2 @@ +# App::PRT::Collector::AllFiles uses the presence of +# this file to determine that the project is a Perl project. diff -Nru prt-0.20/t/data/tokens_before_package/lib/My/Commented.pm prt-0.22/t/data/tokens_before_package/lib/My/Commented.pm --- prt-0.20/t/data/tokens_before_package/lib/My/Commented.pm 1970-01-01 00:00:00.000000000 +0000 +++ prt-0.22/t/data/tokens_before_package/lib/My/Commented.pm 2019-05-29 02:57:11.000000000 +0000 @@ -0,0 +1,8 @@ +# A package with a comment before the `package` statement +package My::Commented; +use strict; +use warnings; + +sub new { bless {}, shift; } + +1; diff -Nru prt-0.20/t/data/tokens_before_package/lib/My/POD.pm prt-0.22/t/data/tokens_before_package/lib/My/POD.pm --- prt-0.20/t/data/tokens_before_package/lib/My/POD.pm 1970-01-01 00:00:00.000000000 +0000 +++ prt-0.22/t/data/tokens_before_package/lib/My/POD.pm 2019-05-29 02:57:11.000000000 +0000 @@ -0,0 +1,13 @@ +=head1 NAME + +My::POD - A package with POD before the `package` statement + +=cut + +package My::POD; +use strict; +use warnings; + +sub new { bless {}, shift; } + +1;