Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 97 lines (75 sloc) 1.981 kB
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
no warnings 'syntax';
use autodie;
use POSIX 'strftime';
use Fcntl 'SEEK_CUR';
sub find;
sub fix;
my $CHANGES = "Changes";
my $README = "README";
my @MODULES = `find lib -type f -name "*.pm"`;
chomp @MODULES;
my $VERSION = shift;
die "Illegal version" unless
$VERSION =~ /^(?<year>20[0-9]{2})(?<month>[01][0-9])(
?<date>[0-3][0-9])(?<seq>[0-9][0-9])$/x;
my ($year, $month, $date, $seq) = @+ {qw [year month date seq]};
my $TODAY = strftime "%Y%m%d" => localtime;
die "Will only set versions matching today's date [$TODAY/$year$month$date]"
unless $TODAY eq "$year$month$date";
die "Will not set a sequence number to 00" if $seq eq "00";
unless (find $VERSION, $README, 2) {
say "Going to change $README";
fix $VERSION, $README, 2;
}
unless (find $VERSION, $CHANGES, 1) {
say "Going to change $CHANGES";
fix $VERSION, $CHANGES, 1, 1;
}
foreach my $module (@MODULES) {
unless (find $VERSION, $module, "VERSION =") {
say "Going to change $module";
fix $VERSION, $module, "VERSION =";
}
}
sub find {
my ($VERSION, $FILE, $TARGET) = @_;
open my $fh, "<", $FILE;
my $line = "";
if ($TARGET =~ /^[0-9]+$/) {
$line = <$fh> for 1 .. $TARGET;
}
else {{
$line = <$fh>;
redo unless $line =~ /$TARGET/;
}}
$line =~ /\b$VERSION\b/;
}
sub fix {
my ($VERSION, $FILE, $TARGET, $date) = @_;
open my $fh, "+<", $FILE;
my $line = "";
if ($TARGET =~ /^[0-9]+$/) {
$line = <$fh> for 1 .. $TARGET;
}
else {{
$line = <$fh>;
redo unless $line =~ /$TARGET/;
}}
my $pat = '\b[0-9]{10}\b';
my $repl = $VERSION;
if ($date) {
$pat .= " .*";
$repl .= " " . `date`;
chomp $repl;
}
if ($line =~ s/$pat/$repl/) {
seek $fh, - length ($line), SEEK_CUR;
print $fh $line;
}
close $fh;
}
__END__
Jump to Line
Something went wrong with that request. Please try again.