Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit acca33520fe3f9caf9816bcca86898e76f40263f @gfx committed Oct 9, 2009
Showing with 405 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +7 −0 .shipit
  3. +4 −0 Changes
  4. +43 −0 MANIFEST.SKIP
  5. +23 −0 Makefile.PL
  6. +27 −0 README
  7. +119 −0 lib/ShipIt/Step/ChangeAllVersions.pm
  8. +18 −0 t/00_load.t
  9. +79 −0 t/01_basic.t
  10. +2 −0 t/test/.shipit
  11. +14 −0 t/test/Bar.pm
  12. +10 −0 t/test/Baz.pod
  13. +11 −0 t/test/Foo.pm
  14. +5 −0 t/test/Makefile.PL
  15. +19 −0 xt/01_podspell.t
  16. +9 −0 xt/02_pod.t
15 .gitignore
@@ -0,0 +1,15 @@
+.*
+!.gitignore
+!.shipit
+*.o
+*.obj
+*.bs
+Makefile*
+!Makefile.PL
+*blib
+META.yml
+inc/
+MANIFEST
+*.out
+*.bak
+ShipIt-Step-ChangeAllVersions-*
7 .shipit
@@ -0,0 +1,7 @@
+# auto-generated shipit config file.
+steps = FindVersion, ChangeAllVersions, CheckVersionsMatch, CheckChangeLog, DistTest, Commit, Tag, MakeDist
+
+git.tagpattern = %v
+git.push_to = origin
+
+CheckChangeLog.files = Changes
4 Changes
@@ -0,0 +1,4 @@
+Revision history for Perl extension ShipIt::Step::ChangeAllVersions
+
+0.001 Fri Oct 9 09:44:18 2009
+ - original version; created by Module::Setup
43 MANIFEST.SKIP
@@ -0,0 +1,43 @@
+
+#!start included /usr/local/lib/perl5/5.10.0/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$ # 6.18 through 6.25 generated this
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# Avoid Devel::Cover files.
+\bcover_db\b
+#!end included /usr/local/lib/perl5/5.10.0/ExtUtils/MANIFEST.SKIP
+
+
+# skip dot files
+^\.
+
+# skip author's files
+\bauthor\b
+
23 Makefile.PL
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use inc::Module::Install;
+
+all_from 'lib/ShipIt/Step/ChangeAllVersions.pm';
+
+requires 'ShipIt' => 0.52;
+
+test_requires 'Test::More' => 0.88; # done_testing()
+
+tests 't/*.t';
+author_tests 'xt';
+
+auto_set_repository() if -d '.git';
+
+clean_files qw(
+ ShipIt-Step-ChangeAllVersions-* *.stackdump
+ cover_db
+ nytprof
+ *.out
+);
+
+WriteAll check_nmake => 0;
27 README
@@ -0,0 +1,27 @@
+This is Perl module ShipIt::Step::ChangeAllVersions.
+
+INSTALLATION
+
+ShipIt::Step::ChangeAllVersions installation is straightforward. If your CPAN shell is set up,
+you should just be able to do
+
+ $ cpan ShipIt::Step::ChangeAllVersions
+
+Download it, unpack it, then build it as per the usual:
+
+ $ perl Makefile.PL
+ $ make && make test
+
+Then install it:
+
+ $ make install
+
+DOCUMENTATION
+
+ShipIt::Step::ChangeAllVersions documentation is available as in POD. So you can do:
+
+ $ perldoc ShipIt::Step::ChangeAllVersions
+
+to read the documentation online with your favorite pager.
+
+Goro Fuji (gfx)
119 lib/ShipIt/Step/ChangeAllVersions.pm
@@ -0,0 +1,119 @@
+package ShipIt::Step::ChangeAllVersions;
+
+use 5.008_001;
+use strict;
+use warnings;
+
+our $VERSION = '0.001';
+
+use parent qw(ShipIt::Step);
+use ExtUtils::Manifest qw(maniread);
+use Fatal qw(open close rename);
+
+sub run {
+ my ($self, $state) = @_;
+
+ my $current_version = quotemeta $state->pt->{version};
+ my $new_version = $state->version;
+
+ # get all modules
+ my @modules =
+ grep { -f && / \.(?: p[lm]c? | pod ) \z/xms } keys %{maniread()};
+
+ foreach my $module (@modules) {
+ open my $in, '<', $module;
+ open my $out, '>', "$module.tmp";
+
+ while (<$in>) {
+
+ # update $VERSION variable
+ if (s/(\$VERSION .+) \b $current_version \b/$1$new_version/xms) {
+ $self->{changed_version_variable}{$module}++;
+ $self->log("Update \$VERSION in $module.");
+ }
+
+ # update the VERSION section whic say,
+ # "This is Foo version $ver.",
+ # or "This document descrives Foo version $ver."
+ if (/\A =head1 \s+ VERSION/xms ... /\A =\w+/xms) {
+ if (s/(version \s+) $current_version/$1$new_version/xms) {
+ $self->{changed_version_section}{$module}++;
+ $self->log("Update the VERSION section in $module.");
+ }
+ }
+
+ print $out $_;
+ }
+
+ close $in;
+ close $out;
+
+ rename $module => "$module~";
+ rename "$module.tmp" => $module;
+ }
+
+ return 1;
+}
+
+sub changed_version_variable {
+ return $_[0]->{changed_version_variable};
+}
+
+sub changed_version_section {
+ return $_[0]->{changed_version_section};
+}
+
+sub log {
+ my $self = shift;
+ print @_, "\n";
+}
+
+1;
+__END__
+
+=head1 NAME
+
+ShipIt::Step::ChangeAllVersions - Changes versions in all the modules
+
+=head1 VERSION
+
+This document describes ShipIt::Step::ChangeAllVersions version 0.001.
+
+=head1 SYNOPSIS
+
+ # .shipit
+ steps = FindVersion, ChangeAllVersions, ...
+
+=head1 DESCRIPTION
+
+C<ShipIt::Step::ChangeVersion> updates the version variable in the main module.
+C<ShipIt::Step::ChangeAllVersions> provides another way to update versions not
+only in the main module, but in all the modules and scripts in your
+distribution. It will also updates versions in the VERSION sections in pods.
+
+=head1 DEPENDENCIES
+
+Perl 5.8.1 or later.
+
+=head1 BUGS
+
+No bugs have been reported.
+
+Please report any bugs or feature requests to the author.
+
+=head1 AUTHOR
+
+Goro Fuji (gfx) E<lt>gfuji(at)cpan.orgE<gt>
+
+=head1 SEE ALSO
+
+L<ShipIt>.
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright (c) 2009, Goro Fuji (gfx). Some rights reserved.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
18 t/00_load.t
@@ -0,0 +1,18 @@
+#!perl -w
+
+use strict;
+use Test::More tests => 1;
+
+BEGIN{ # Fake Term::ReadLine, which is hard coded in ShipIt::Util
+ package Term::ReadLine;
+ sub new{ bless {}, shift }
+ sub readline{ '' };
+ $INC{'Term/ReadLine.pm'} = __FILE__;
+}
+
+use ShipIt;
+
+BEGIN { use_ok 'ShipIt::Step::ChangeAllVersions' }
+
+diag "Testing ShipIt::Step::ChangeAllVersions/$ShipIt::Step::ChangeAllVersions::VERSION";
+diag "under ShipIt $ShipIt::VERSION";
79 t/01_basic.t
@@ -0,0 +1,79 @@
+#!perl -w
+
+use strict;
+use Test::More tests => 16;
+
+use constant new_version => '0.001_01';
+
+BEGIN{ # Fake Term::ReadLine, which is hard coded in ShipIt::Util
+ package Term::ReadLine;
+ sub new{ bless {}, shift }
+ sub readline{ ::new_version() };
+ $INC{'Term/ReadLine.pm'} = __FILE__;
+}
+
+use ShipIt;
+use ShipIt::VC;
+use ShipIt::Step::ChangeAllVersions;
+
+chdir 't/test' or die "Cannot chdir: $!";
+
+{
+ package ShipIt::VC::Dummy;
+
+ sub new { bless {} } # intentinaly one-arg bless
+ sub exists_tagged_version{ 0 }
+
+ no warnings 'redefine';
+ *ShipIt::VC::new = \&ShipIt::VC::Dummy::new;
+}
+
+my $conf = ShipIt::Conf->parse('.shipit');
+my $state = ShipIt::State->new($conf);
+
+close STDOUT;
+
+my $stdout = '';
+open STDOUT, '>', \$stdout;
+
+foreach my $step( $conf->steps ){
+ 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';
+
+ 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';
+ }
+}
+
+like $stdout, qr/^Update \s+ \$VERSION/xms;
+like $stdout, qr/^Update \s+ the \s+ VERSION \s+ section/xms;
+
+require './Foo.pm';
+require './Bar.pm';
+
+{
+ no warnings 'once';
+
+ is $Foo::VERSION, new_version, '$Foo::VERSION has been updated';
+ is $Bar::VERSION, new_version, '$Bar::VERSION has been updated';
+
+ isnt $Bar::version, new_version, '$version is not touched';
+ isnt $Bar::Version, new_version, '$Version is not touched';
+}
+
+# revert chnages for the next test :)
+
+if($ENV{DONT_REMOVE_CHANGED_FILES}){
+ rename 'Foo.pm' => 'Foo.pm.bak';
+ rename 'Bar.pm' => 'Bar.pm.bak';
+ rename 'Baz.pod' => 'Baz.pod.bak';
+}
+
+ok rename 'Foo.pm~' => 'Foo.pm';
+ok rename 'Bar.pm~' => 'Bar.pm';
+ok rename 'Baz.pod~' => 'Baz.pod';
+
2 t/test/.shipit
@@ -0,0 +1,2 @@
+# A shipit config file for testing
+steps = FindVersion, ChangeAllVersions
14 t/test/Bar.pm
@@ -0,0 +1,14 @@
+package Bar;
+
+our $VERSION = q(0.001);
+
+$version = '0.001'; # Don't touch this
+$Version = '0.001'; # Don't touch this
+
+=head1 VERSION
+
+This is Bar version 0.001.
+
+=cut
+
+1;
10 t/test/Baz.pod
@@ -0,0 +1,10 @@
+=head1 VERSION
+
+This is Baz version 0.001.
+
+=head1 OTHER SECTION
+
+We care only the VERSION section. The version 0.001 should not be changed.
+
+=cut
+
11 t/test/Foo.pm
@@ -0,0 +1,11 @@
+package Foo;
+
+our $VERSION = '0.001';
+
+=head1 VERSION
+
+This document describes Foo version 0.001.
+
+=cut
+
+1;
5 t/test/Makefile.PL
@@ -0,0 +1,5 @@
+# for testing
+use Module::Install;
+
+version_from 'Foo.pm';
+
19 xt/01_podspell.t
@@ -0,0 +1,19 @@
+#!perl -w
+
+use strict;
+use Test::More;
+
+eval q{ use Test::Spelling };
+
+plan skip_all => q{Test::Spelling is not installed.}
+ if $@;
+
+add_stopwords(map { split /[\s\:\-]/ } <DATA>);
+$ENV{LANG} = 'C';
+all_pod_files_spelling_ok('lib');
+
+__DATA__
+Goro Fuji (gfx)
+gfuji(at)cpan.org
+ShipIt::Step::ChangeAllVersions
+gfx
9 xt/02_pod.t
@@ -0,0 +1,9 @@
+#!perl -w
+
+use strict;
+use Test::More;
+eval q{use Test::Pod 1.14};
+plan skip_all => 'Test::Pod 1.14 required for testing POD'
+ if $@;
+
+all_pod_files_ok();

0 comments on commit acca335

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