move Author.PL to maint/Makefile.PL.include to prevent it being run at build time
[p5sagit/Module-Metadata.git] / maint / bump-version
1 #!/usr/bin/env perl
2
3 use 5.010;
4 use strict;
5 use warnings FATAL => 'all';
6 use autodie;
7
8 chomp(my $LATEST = qx(grep '^[0-9]' Changes | head -1 | awk '{print \$1}'));
9
10 my @parts = split /\./, $LATEST;
11
12 my $OLD_DECIMAL = sprintf('%i.%03i%03i', @parts);
13
14 my %bump_part = (major => 0, minor => 1, bugfix => 2);
15
16 my $bump_this = 
17   $bump_part{$ARGV[0]||'bugfix'}
18     // die "no idea which part to bump - $ARGV[0] means nothing to me";
19
20 my @new_parts = @parts;
21
22 $new_parts[$bump_this]++;
23
24 my $NEW_DECIMAL = sprintf('%i.%03i%03i', @new_parts);
25
26 warn "Bumping $OLD_DECIMAL -> $NEW_DECIMAL\n";
27
28 my $PM_FILE = 'lib/Module/Metadata.pm';
29
30 my $file = do { local (@ARGV, $/) = ($PM_FILE); <> };
31
32 $file =~ s/(?<=\$VERSION = ')${\quotemeta $OLD_DECIMAL}/${NEW_DECIMAL}/;
33
34 open my $out, '>', $PM_FILE;
35
36 print $out $file;