1 package DX::Lib::FS::Action::RewriteFile;
3 use DX::Lib::FS::Fact::FileContent;
6 with 'DX::Role::Action';
8 has from => (is => 'ro', required => 1);
10 has add_lines => (is => 'ro', default => sub { [] });
12 has remove_lines => (is => 'ro', default => sub { {} });
14 has final_content => (is => 'lazy', init_arg => undef, builder => sub {
16 my %remove = %{$self->remove_lines};
18 (grep !$remove{$_}, $self->from->lines->all),
25 $_[0]->but(add_lines => [ @{$_[0]->add_lines}, $_[1] ]);
29 $_[0]->but(remove_lines => [ %{$_[0]->remove_lines}, $_[1] => 1 ]);
34 +(file_content => DX::Lib::FS::Fact::FileContent->new(
35 path => $self->from->path,
36 data => $self->final_content