View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Jerrad Pierce > clobber-0.04 > clobber



Annotate this POD

View/Report Bugs
Source   Latest Release: clobber-0.10_1


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.

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:

%s: File exists

We saved data!

Failed to parse EXPR of 2-arg open: %s

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 to 1. This allows you to include 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.

wrap other data-damaging functions such as unlink and truncate?

as optional "imports"


Jerrad Pierce <JPIERCE circle-a CPAN full-stop ORG>


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.

syntax highlighting: