5 use Carp qw/carp confess/;
7 use Data::Dump qw/dump/;
13 my $dir = $1 if $file =~ s{(^.+)/[^/]+}{$1};
14 if ( $dir && ! -d $dir ) {
16 File::Path::mkpath $dir;
21 my ( $file, $content ) = @_;
25 write_file $file, $content;
27 carp "## append created $size bytes in $file";
31 my $on_disk = read_file $file;
33 my $relaxed_content = $content;
34 $relaxed_content =~ s{\s+}{\\s+}gs;
36 if ( $on_disk !~ m{$relaxed_content} ) {
38 # $content =~ s{^[\n\r]+}{\n}s;
39 # $content =~ s{[\n\r]*$}{\n}s;
41 if ( $on_disk =~ s{([\s+]exit[\s\d]*)$}{\n$content\n$1}s ) {
42 warn "# insert $file\n$on_disk" if $debug;
43 write_file $file, $on_disk;
45 warn "# append $file\n$content\n" if $debug;
46 open($fh, '>>', $file);
51 carp "## append to $file" if $debug;
54 warn "## $file not modified" if $debug;
59 my ( $file, $from, $to ) = @_;
61 my $content = read_file $file;
62 if ( $content =~ s{$from}{$to}s ) {
63 write_file $file, $content;
64 carp "## change $file $from => $to" if $debug;
66 } elsif ( $content !~ m{$to}s ) {
67 confess "can't find $from to change into $to in $file in ",dump( $content );
72 my ( $file, $content ) = @_;
74 write_file $file, $content;
78 my ( $from, $to ) = @_;
79 die "no destination" unless $to;
82 my $perm = (stat $from)[2];
83 carp "# copy_once $from => $to $perm";
84 write_file $to, read_file($from);