Skip to content
Browse files

Use File::Find instead of the MANIFEST file (suggested by tokuhirom)

  • Loading branch information...
1 parent b9ebf34 commit 9aff18fa617be6c1c2b692554e8e6c968987e857 @gfx committed Mar 14, 2010
Showing with 80 additions and 16 deletions.
  1. +36 −7 lib/ShipIt/Step/ChangeAllVersions.pm
  2. +20 −8 t/01_basic.t
  3. +13 −0 t/02_collect_files.t
  4. +1 −1 t/test/Makefile.PL
  5. 0 t/test/{ → lib}/Foo.pm
  6. +10 −0 t/test/script/qux
View
43 lib/ShipIt/Step/ChangeAllVersions.pm
@@ -7,8 +7,39 @@ use warnings;
our $VERSION = '0.003';
use parent qw(ShipIt::Step);
-use ExtUtils::Manifest qw(maniread);
-use Fatal qw(open close rename);
+use Fatal qw(open close rename read opendir closedir);
+use File::Find qw(find);
+
+my $looks_like_perl = qr/\. p(?: [ml]c? | od | erl ) \z/xms;
+
+sub collect_files {
+ my @files;
+
+ # from subdir
+ find sub {
+ return if not -f $_;
+
+ if($_ =~ $looks_like_perl) {
+ push @files, $File::Find::name;
+ }
+ else {
+ open my $in, '<', $_;
+ read $in, my($buff), 2;
+
+ if($buff && $buff eq '#!'){
+ push @files, $File::Find::name;
+ }
+ close $in;
+ }
+ }, grep{ -d } qw(lib script bin);
+
+ # from toplevel
+ opendir my $dirh, '.';
+ push @files, grep{ $_ =~ $looks_like_perl } readdir($dirh);
+ closedir $dirh;
+
+ return @files;
+}
sub run {
my ($self, $state) = @_;
@@ -22,16 +53,14 @@ sub run {
my $current_version = quotemeta $state->pt->{version};
my $new_version = $state->version;
- # get all modules
- my @modules =
- grep { -f && m{\A (?:bin|script)/ | \.(?: p[lm]c? | pod ) \z}xms } keys %{maniread()};
-
- foreach my $module (@modules) {
+ foreach my $module ($self->collect_files) {
open my $in, '<', $module;
+ binmode $in;
my $out;
if(!$dry_run){
open $out, '>', "$module.tmp";
+ binmode $out;
}
my $need_replace = 0;
View
28 t/01_basic.t
@@ -1,7 +1,9 @@
#!perl -w
use strict;
-use Test::More tests => 22;
+use Test::More;
+use Fatal qw(open close chdir);
+use File::Spec;
my $new_version;
@@ -16,7 +18,7 @@ use ShipIt;
use ShipIt::VC;
use ShipIt::Step::ChangeAllVersions;
-chdir 't/test' or die "Cannot chdir: $!";
+chdir 't/test';
{
package ShipIt::VC::Dummy;
@@ -30,6 +32,10 @@ chdir 't/test' or die "Cannot chdir: $!";
close STDOUT;
+sub f{
+ File::Spec->catfile(split /\//, $_[0]);
+}
+
for(
{new_version => '0.001_01', current_version => '0.001' },
@@ -47,28 +53,34 @@ for(
ok $step->run($state), $step;
if($step->isa('ShipIt::Step::ChangeAllVersions')){
- is $step->changed_version_variable->{'Foo.pm'}, 1, 'VERSION variable in Foo.pm';
- is $step->changed_version_variable->{'Bar.pm'}, 1, 'VERSION variable in Bar.pm';
+ ok $step->changed_version_variable->{f 'lib/Foo.pm'}, 'VERSION variable in Foo.pm changed';
+ ok $step->changed_version_variable->{'Bar.pm'}, 'VERSION variable in Bar.pm changed';
+ ok $step->changed_version_variable->{f 'script/qux'}, 'VERSION variable in script/qux changed';
- is $step->changed_version_section->{'Foo.pm'}, 1, 'VERSION section in Foo.pm';
- is $step->changed_version_section->{'Bar.pm'}, 1, 'VERSION section in Bar.pm';
- is $step->changed_version_section->{'Baz.pod'}, 1, 'VERSION section in Baz.pod';
+ ok $step->changed_version_section->{f 'lib/Foo.pm'}, 'VERSION section in Foo.pm changed';
+ ok $step->changed_version_section->{'Bar.pm'}, 'VERSION section in Bar.pm changed';
+ ok $step->changed_version_section->{'Baz.pod'}, 'VERSION section in Baz.pod changed';
}
}
like $stdout, qr/^Update \s+ \$VERSION/xms;
like $stdout, qr/^Update \s+ the \s+ VERSION \s+ section/xms;
- require './Foo.pm';
+ require './lib/Foo.pm';
+ require './script/qux';
require './Bar.pm';
if($new_version eq '0.001_01'){ # on the first step
no warnings 'once';
is $Foo::VERSION, $new_version, '$Foo::VERSION has been updated';
is $Bar::VERSION, $new_version, '$Bar::VERSION has been updated';
+ is $App::qux::VERSION, $new_version, '$App::qux::VERSION has been updated';
isnt $Bar::version, $new_version, '$version is not touched';
isnt $Bar::Version, $new_version, '$Version is not touched';
}
}
+
+done_testing;
+
View
13 t/02_collect_files.t
@@ -0,0 +1,13 @@
+#!perl -w
+
+use strict;
+use Test::More;
+
+use ShipIt::Step::ChangeAllVersions;
+
+use File::Spec;
+
+my @files = ShipIt::Step::ChangeAllVersions->collect_files;
+is_deeply \@files, [File::Spec->catfile(qw(lib ShipIt Step ChangeAllVersions.pm))];
+
+done_testing;
View
2 t/test/Makefile.PL
@@ -1,5 +1,5 @@
# for testing
use Module::Install;
-version_from 'Foo.pm';
+version_from 'lib/Foo.pm';
View
0 t/test/Foo.pm → t/test/lib/Foo.pm
File renamed without changes.
View
10 t/test/script/qux
@@ -0,0 +1,10 @@
+#!perl -w
+package App::qux;
+
+use strict;
+
+our $VERSION = qq(0.001);
+
+sub App::qux::qux { 42 }
+
+1;

0 comments on commit 9aff18f

Please sign in to comment.
Something went wrong with that request. Please try again.