Ben Bullock

NAME

File::Versions - Emacs-like versioned file names

SYNOPSIS

    use FindBin '$Bin';
    use File::Versions 'make_backup';
    my $backup = make_backup ("$Bin/file");
    # If the environment variable 'VERSION_CONTROL' is set to
    # 'numbered', 'file' is moved to 'file.~1~'. The value of the new
    # file name is put into '$backup'.
    

VERSION

This documents File::Versions version 0.09 corresponding to git commit 7d641410d8d898ad7292d9eaf531614fea033e59 released on Sat May 12 10:40:28 2018 +0900.

DESCRIPTION

This module duplicates the behaviour of programs like the Emacs text editor under Unix, where the environment variables VERSION_CONTROL and SIMPLE_VERSION_CONTROL allow one to make numbered backups of a file.

FUNCTIONS

backup_name

     my $backup = backup_name ('file');

Make an appropriate numbered backup name for file. The return value is this name.

make_backup

     make_backup ('file');

Make a backup of the file specified by file, by renaming file to its backup name, as given by "backup_name". If such a file already exists, delete it using unlink before renaming $file.

This subroutine dies using "croak" in Carp on error. If it succeeds, the return value is the name of the backup file.

SEE ALSO

There is something similar to this module in the source code of the "rename" utility which comes with Perl.

EXPORTS

"backup_name" and "make_backup" are exported on demand. The export tag :all exports everything.

    use utf8;
    use FindBin '$Bin';
    use File::Versions ':all';
    

DEPENDENCIES

"max" in List::Util
Carp

AUTHOR

Ben Bullock, <bkb@cpan.org>

COPYRIGHT & LICENCE

This package and associated files are copyright (C) 2010-2018 Ben Bullock.

You can use, copy, modify and redistribute this package and associated files under the Perl Artistic Licence or the GNU General Public Licence.