#!/usr/bin/perl
# 1 UP!

use strict;
use Tie::File;
use Cwd qw(abs_path);

our $VERSION = '0.016';


{
  no strict;
  $SIG{__DIE__} = sub { untie( @ver ) };
}

my $file;
$file = shift or do {
  print "No file given - should I operate on myself? [y/N] ";
  chomp(my $destiny = <>);
  if(lc($destiny) ne 'y') {
    die("Bailing out...\n");
  }
  $file = abs_path( $0 );
};

warn "Trying to bump $file VERSION...\n";

tie(my @ver, 'Tie::File', $file) or die("Cant tie $file: $!\n");

my($version, $pre, $post, $i) = ( (undef) x 3, 0 );
for my $l(@ver) {
  if($l =~ m{ (.+VERSION\s*=\s*['"]?)(.+)(['"].+) }x) {
    ($pre, $version, $post) = ($1, $2, $3);

    warn "Current VERSION determined as $version\n";
    warn "Pre is [[$pre]] and Post is [[$post]]\n";
    last;
  }
  $i++;
}


print ">  Bump version number to: ";
chomp(my $new = <STDIN>);

if($new !~ /[0-9]/) {
  die("Please be sensitive, I can not accept a version _number_ like this.\n");
}

$ver[$i] = "$pre$new$post";  # our $VERSION = '0.004';
print "    Version bumped to $new\n";
print "    Statement changed to $pre$new$post\n";


untie(@ver) or die("Cant untie $file: $!\n");