Doit

 view release on metacpan or  search on metacpan

lib/Doit.pod  view on Meta::CPAN

Make sure that the listed directories exist, together with any missing
intermediate directories. Additional options may be specified as
key-value pairs in a hashref, and will be passed to
L<File::Path::make_path|File::Path/make_path>.

Note that it's possible to set the directory permissions with the
C<mode> option, but the C<make_path> command does not check if an
already existing directory has these permission bits set.

See also L</mkdir>.

=head3 mkdir

    $doit->mkdir($directory);
    $doit->mkdir($directory, $mode);

Make sure that the given I<$directory> exist. The I<$mode> will be
used only if creating a new directory and not effective if the
directory already exists. See L<perlfunc/mkdir> for more details. See
L</make_path> for a command which will also create mising intermediate
directories.

=head3 move

    $doit->move($from, $to);

Move file I<$from> to I<$to>. This command probably cannot be used in
converging scripts without an accompanying condition. See
L<File::Copy::move|File::Copy/move> for details. For an alternative
command see L</rename>.

Always returns C<1> (unless there's an exception).

=head3 remove_tree

    $doit->remove_tree($directory ...);
    $doit->remove_tree($directory ..., { key => $val ... });

Make sure that the listed directories don't exist anymore, together
with containing files and sub-directories. See
L<File::Path::remove_tree|File::Path/remove_tree> for details.

=head3 rename

    $doit->rename($from, $to);

Rename I<$from> to I<$to>. This command probably cannot be used in
converging scripts without an accompanying condition. See
L<perlfunc/rename> for details. See L</move> for a command which can
move a file between different filesystems.

Always returns C<1> (unless there's an exception).

=head3 rmdir

    $doit->rmdir($directory);

Make sure that the given I<$directory> is removed. Fails if this
directory is not empty. See L<perlfunc/rmdir> for details.

=head3 setenv

    $doit->setenv($key, $val);

Make sure that I<%ENV> contains a key I<$key> set to I<$value>.

=head3 symlink

    $doit->symlink($oldfile, $newfile);

Make sure that I<$newfile> is a symlink pointing to I<$oldfile>.
Contrary to L</ln_nsf> it does not change an existing symlink. See
L<perlfunc/symlink> for more details.

=head3 touch

    $doit->touch($file ...);

"Touches" the given files. Loosely modelled after the system command
L<touch(1)>. Non-existent files are created as empty files, and for
existent files the access and modification are updated. This command
does not converge; for a converging command see
L</create_file_if_nonexisting>.

Always returns the number of given files (unless there's an exception).

=head3 unlink

    $doit->unlink($file ...);

Make sure that the given files are deleted. See L<perlfunc/unlink>.

=head3 unsetenv

    $doit->unsetenv($key);

Make sure that I<%ENV> does not contain the key I<$key> anymore.

=head3 utime

    $doit->utime($atime, $mtime, $file ...);

Make sure that access time and modification time of the listed files
is set to the given values. Undefined time values are replaced by
current time. Fails if not all files could be changed. See
L<perlfunc/utime> for details.

=head2 FILE CREATION AND MODIFICATION

=head3 change_file

    $doit->change_file({debug => $bool, check => $code}, $file, { change ... } ...);

Modify an existing I<$file> using the set of change specifications.
Return the number of changes made. Depending on the changes the
command call can be converging or not. The following change
specifications exist:

=over

=item C<< { add_if_missing => $line } >>

Add the specified I<$line> to the end of file if it is missing.

=item C<< { add_if_missing => $line, add_after => $rx } >>

Add the specified I<$line> after a the last line mathing I<$rx>. If no
line matches, then an exception will be thrown.

=item C<< { add_if_missing => $line, add_after_first => $rx } >>

Add the specified I<$line> after a the first line mathing I<$rx>. If
no line matches, then an exception will be thrown.

=item C<< { add_if_missing => $line, add_before => $rx } >>

Add the specified I<$line> before a the first line mathing I<$rx>. If
no line matches, then an exception will be thrown.

=item C<< { add_if_missing => $line, add_before_last => $rx } >>

Add the specified I<$line> before a the last line mathing I<$rx>. If
no line matches, then an exception will be thrown.

=item C<< { match => $rx_or_string, replace => $line } >>

Substitute all lines matching I<$rx_or_string> with I<$line>.
I<$rx_or_string> may be a regexp, or a string. In the latter case the
complete line has to match.

=item C<< { match => $rx_or_string, delete => $bool } >>

All lines matching I<$rx_or_string> will be deleted if C<delete> is
set to a true value.



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