File::Slurper::Shortcuts - Some convenience additions for File::Slurper
This document describes version 0.005 of File::Slurper::Shortcuts (from Perl distribution File-Slurper-Shortcuts), released on 2021-08-02.
use File::Slurper::Shortcuts qw(modify_text modify_binary); modify_text("dist.ini", sub { s/One/Two/ });
Usage:
$orig_content = modify_text($filename, $code, $encoding, $crlf);
This is File::Slurper's read_text and write_text combined. First, read_text is performed then the content of file is put into $_. Then $code will be called and should modify $_ to modify the content of file. Finally, write_text is called to write the new content. If content ($_) does not change, file will not be written.
read_text
write_text
$_
$code
If file can't be read with read_text() an exception will be thrown by File::Slurper.
read_text()
This function will also die if code does not return true.
If file can't be written with write_text() an exception will be thrown by File::Slurper.
write_text()
Return the original content of file.
Note that no locking is performed and file is opened twice, so there might be race condition etc.
Please visit the project's homepage at https://metacpan.org/release/File-Slurper-Shortcuts.
Source repository is at https://github.com/perlancar/perl-File-Slurper-Shortcuts.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=File-Slurper-Shortcuts
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
File::Slurper::Temp also provides modify_text and modify_binary.
modify_text
modify_binary
File::Slurper
perlancar <perlancar@cpan.org>
This software is copyright (c) 2021, 2019, 2018 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install File::Slurper::Shortcuts, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Slurper::Shortcuts
CPAN shell
perl -MCPAN -e shell install File::Slurper::Shortcuts
For more information on module installation, please visit the detailed CPAN module installation guide.