AFS-Command

 view release on metacpan or  search on metacpan

util/bin/check_version  view on Meta::CPAN


if ( @missing ) {
    warn("The following modules have no \$VERSION:\n\t" .
	 join("\n\t",@missing) . "\n");
}

if ( ! $args{update} && @old ) {
    warn("The following modules or test suites have an old \$VERSION:\n\t" .
	 join("\n\t",@old) . "\n");
}

exit 0 unless $args{update};

#
# Update the $VERSION if asked to.
#
foreach my $old ( @old) {

    warn "Updating \$VERSION to $newversion in $old\n";

    #
    # If the file is in RCS, we have to check it out/in.
    #
    my $rcs = rcs($old);

    if ( $rcs ) {
	system("co -l $old > /dev/null");
	die "Unable to co -l $old\n" if $? >> 8;
    }

    open(NEW,">$old.new") || die "Unable to write to $old.new: $!\n";
    open(OLD,$old) || die "Unable to read $old: $!\n";

    while ( <OLD> ) {

	if ( $old =~ /\.pm(\.in)?$/ ) {
	    #
	    # Fix the module version
	    #
	    if ( /\$VERSION\s+=\s+\'([\d\.]+)\'/ ) {
		print NEW "our \$VERSION = '$newversion';\n";
	    } else {
		print NEW;
	    }
	} else {
	    #
	    # Fix the use statements for tests
	    #
	    if ( /use\s+\S+\s+([\d\.]+)/ ) {
		$oldversion = $1;
		s/$oldversion/$newversion/;
	    }
	    print NEW;
	}

    }

    close(OLD) || die "Unable to close $old: $!\n";
    close(NEW) || die "Unable to close $old.new: $!\n";

    rename("$old.new",$old) || die "Unable to rename $old.new to $old: $!\n";

    if ( $rcs ) {
	system("echo 'Updated \$VERSION to $newversion' | ci -u $old > /dev/null");
	die "Unable to ci -u $old\n" if $? >> 8;
    }

}

exit 0;

sub rcs {

    my ($file) = @_;

    my $dirname = dirname($file);
    my $basename = basename($file);

    return -f "$dirname/RCS/$basename,v" ? "$dirname/RCS/$basename,v" : "";

}



( run in 1.159 second using v1.01-cache-2.11-cpan-39bf76dae61 )