So it sounds like you recognize the impracticality of a "solution" that involves overriding core functions and modules -- even though the "dream module" that you describe in the OP probably couldn't be implemented any other way (as near as I can tell).

Yet at the same time, it sounds like you are hoping to avoid the alternative of altering every line of existing code (or including a bunch of repetitive stuff with every line of new code) involving any sort of file-system change, so that it can be made conditional on the value of the "preview" option.

Alas, I don't think there's a third way. The best you can do is find ways to minimize the overhead of making all those file-system operations conditional. Ideally, this is something you plan out for before actually writing any code for the given application.

In that regard, my personal preference would probably fall toward a module that builds a stack of operations, then, you just check your option setting once at the end of the process, to decide whether to print the stack, or execute it, or present it for approval, or store it as a script file, or ...

If you're adapting existing code to provide this new functionality, it means editing every line that does a file system call, to turn that into a call to the module's "push" method -- no way around that. If you're starting a new app, it's not that much overhead to write $stack->push( "rename", $arg1, $arg2 ); instead of rename $arg1, $arg2; -- maybe there are ways to make the method call even easier.


In reply to Re^3: File operations "preview" mode? by graff
in thread File operations "preview" mode? by jh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.