Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
CIP_TAG: ${{ matrix.cip_tag }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Bootstrap CIP
run: |
Expand All @@ -47,7 +47,7 @@ jobs:
cip cache-key

- name: Cache CPAN modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cip
key: ${{ runner.os }}-build-${{ steps.cache-key.outputs.key }}
Expand Down
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- The update_file method will replace the content in an existing file
rather than creating a new one. A backup of the original file is
made while the new content is being written, in the unlikely event
of an error during content replacement. The backup will be removed
if the replacement succeeds. A new file will be created if one does
not exist, as before. (gh#6)

0.04 2024-12-15 20:35:06 -0700
- I somehow forgot how to write POD and had to fix some (gh#5)
Expand Down
16 changes: 14 additions & 2 deletions lib/Data/Section/Writer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The name of the Perl source file. If not provided then the source for the calle
use Class::Tiny qw( perl_filename _files _same _formats );
use Ref::Util qw( is_coderef is_blessed_ref is_plain_arrayref );
use MIME::Base64 qw(encode_base64);
use File::Temp ();

sub BUILD ($self, $) {

Expand Down Expand Up @@ -161,8 +162,19 @@ Starting with version 0.02, this method will not write to the file if the conten
$self->_same(0);
}

# re-write the perl with the
$self->perl_filename->spew_utf8($perl);
if(-f $self->perl_filename) {
use autodie qw( truncate close );
# re-write the perl to the file, using the existing inode
my $backup = Path::Tiny->new(File::Temp::tempnam($self->perl_filename->parent, $self->perl_filename->basename));
$self->perl_filename->copy($backup) if -f $self->perl_filename;
my $fh = $self->perl_filename->openrw_utf8;
truncate $fh, 0;
print $fh $perl or die "unable to write to @{[ $self->perl_filename ]} $!";
close $fh;
$backup->remove if -f $backup;
Comment on lines +166 to +174

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh man, this is the kind of stuff I relied on Path::Tiny to hide from me!!!! 😭

} else {
$self->perl_filename->spew_utf8($perl);
}

return $self;
}
Expand Down
Loading