1 package DX::Lib::FS::Action::RewriteFile;
3 use DX::Lib::FS::Fact::FileContent;
6 with 'DX::Role::Action';
7 with 'DX::Lib::FS::Role::RunOn';
9 has from => (is => 'ro', required => 1, handles => [ 'path' ]);
11 has add_lines => (is => 'ro', default => sub { [] });
13 has remove_lines => (is => 'ro', default => sub { {} });
15 has final_content => (is => 'lazy', init_arg => undef, builder => sub {
17 my %remove = %{$self->remove_lines};
19 (grep !$remove{$_}, $self->from->lines->all),
26 $_[0]->but(add_lines => [ @{$_[0]->add_lines}, $_[1] ]);
30 $_[0]->but(remove_lines => [ %{$_[0]->remove_lines}, $_[1] => 1 ]);
35 +(file_content => DX::Lib::FS::Fact::FileContent->new(
37 data => $self->final_content
43 $self->_call_guts(rewrite_file => $self->final_content);
44 return +(file_content => $self->path);