Data-ShowTable
view release on metacpan or search on metacpan
bump-version view on Meta::CPAN
sub chatf($@) {
&talkf if $verbose;
}
sub chat($) {
chatf '', shift;
}
sub talkf($@) {
my $fmt = shift;
$fmt = "%s\n" unless $fmt ne '';
printf STDERR $fmt, @_;
}
sub talk($) {
talkf '', shift;
}
sub nvtalkf($@) {
&talkf unless $verbose;
}
# runcmd COMMAND
#
# In $norun mode, print COMMAND prefixed with "(norun) ", and do nothing
# else.
#
# In $verbose mode, print COMMAND prefixed with "--> " before invoking the
# command.
#
# runcmd COMMANDTEXT { BLOCK ; }
#
# COMMANDTEXT is displayed for either $norun and $verbose modes, but
# BLOCK is executed.
#
sub runcmd($;&) {
my $cmd = shift;
my $code = shift;
if ($norun) {
talkf "(norun) %s\n", $cmd;
} else {
chatf "--> %s\n", $cmd;
if ($code) {
unless (&$code) {
nvtalkf "--> %s\n", $cmd;
die "Command block failed: $!\n";
}
} else {
STDERR->flush;
unless (system($cmd)) {
nvtalkf "--> %s\n", $cmd;
die "Command failed: $!\n";
}
}
}
}
sub update_version($) {
my $file = shift;
$new_file = "$file.new";
chatf "Scanning %s for \$VERSION..\n", $file;
my($in, $out);
if (open($in, "<", $file)) {
if (!$norun) {
chatf "Opening %s for output..\n", $new_file;
open($out, ">", $new_file) or die("Cannot open $out for output: $!\n");
}
my $done = '';
my $changes = '';
while (<$in>) {
talkf "%03d: %s", $., $_ if $verbose > 1;
if (/^(\s*)\$VERSION\s*=\s*['"]?(\d+)\.(\d+)['"]?[\s;]/) {
my ($prefix, $cur_major, $cur_minor) = ($1, $2, $3);
talkf "%20s: ", $file if $many_files && !$verbose;
talkf "Found version: %s.%s\n", $cur_major, $cur_minor;
($new_major, $new_minor) = bump_version($cur_major, $cur_minor);
if ($new_major ne $cur_major or $new_minor ne $cur_minor) {
talkf "%20s: ", $file if $many_files && !$verbose;
talkf " New version: %s.%s\n", $new_major, $new_minor;
$_ = sprintf("%s\$VERSION = '%s.%s';\n", $prefix, $new_major, $new_minor);
$changes = 1;
}
print $out $_ if $out ne '';
last;
}
print $out $_ if $out ne '';
}
# finish up reading & writing
if ($out ne '') {
while (<$in>) { print $out $_; } # write the rest of the file
close($out) or die "Close $out failed: $!\n";
}
close($in);
if ($changes && !$norun) {
talk "Saving changes..";
runcmd "mv $file $file.old", sub {
rename($file, $file.'.old') or die "mv $file $file.old failed: $!";
};
runcmd "mv $new_file $file", sub {
rename($new_file, $file) or die "mv $new_file $file: $!";
};
talkf "%s updated.\n", $file;
} elsif (!$changes) {
talk "No changes.";
}
} else {
warn "Cannot open and read $file: $!";
}
}
# bump_version($input_major_version, $input_minor_version)
#
# Increment the version numbers, according to $bump_major or $bump_minor.
#
# if $major and $minor are already set (by option), they override.
sub bump_version($$) {
( run in 1.311 second using v1.01-cache-2.11-cpan-39bf76dae61 )