clobber - pragma to optionally prevent over-writing files
no clobber; #Fails if /tmp/xyzzy exists open(HNDL, '>/tmp/xyzzy'); { use clobber; #It's clobberin' time open(HNDL, '>/tmp/xyzzy'); }
Do you occasionally get +> and +< mixed up, or accidentally leave off an > in the mode of an open? Want to run some relatively trustworthy code--such as some spaghetti monster you created in the days of yore--but can't be bothered to check it's semantics? Or perhaps you'd like to add a level of protection to operations on user-supplied files without coding the logic yourself.
+>
+<
open
Yes? Then this pragma could help you from blowing away valuable data.
Like the noclobber variable of some shells, this module will prevent the use of open modes which truncate if a file already exists. This behavior can be controlled at the block level, as demonstrated in the "SYNOPSIS".
The pragma may throw the following exceptions:
We saved data!
The module could not figure out what mode was used, and decided to bail for safety.
This shouldn't happen.
You may disable clobber protection at compile-time by setting the environment variable clobber.pm to 1. This allows you to include clobber.pm in PERL5OPT as -M-clobber for general protection, but override it as needed for programs invoked via a pipeline.
I've done some basic-testing with 2- and 3-arg forms of read/write/append, but more thorough testing of mode-parsing and/or invocation needs to be done.
Interactive ask to run the more complex tests, with timeout to skip them.
as optional "imports"
Jerrad Pierce <JPIERCE circle-a CPAN full-stop ORG>
Thou shalt not claim ownership of unmodified materials.
Thou shalt not claim whole ownership of modified materials.
Thou shalt grant the indemnity of the provider of materials.
Thou shalt use and dispense freely without other restrictions.
Or, if you prefer:
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.0 or, at your option, any later version of Perl 5 you may have available.
To install clobber, copy and paste the appropriate command in to your terminal.
cpanm
cpanm clobber
CPAN shell
perl -MCPAN -e shell install clobber
For more information on module installation, please visit the detailed CPAN module installation guide.