eval cage for the shell
[scpubgit/DKit.git] / lib / DX / Lib / FS / Action / RewriteFile.pm
CommitLineData
8c3eab7b 1package DX::Lib::FS::Action::RewriteFile;
2
3use DX::Lib::FS::Fact::FileContent;
4use Moo;
5
6with 'DX::Role::Action';
7
8has from => (is => 'ro', required => 1);
9
10has add_lines => (is => 'ro', default => sub { [] });
11
12has remove_lines => (is => 'ro', default => sub { {} });
13
14has final_content => (is => 'lazy', init_arg => undef, builder => sub {
15 my ($self) = @_;
16 my %remove = %{$self->remove_lines};
17 join("\n",
18 (grep !$remove{$_}, $self->from->lines->all),
19 @{$self->add_lines},
20 ''
21 );
22});
23
24sub but_add {
25 $_[0]->but(add_lines => [ @{$_[0]->add_lines}, $_[1] ]);
26}
27
28sub but_remove {
29 $_[0]->but(remove_lines => [ %{$_[0]->remove_lines}, $_[1] => 1 ]);
30}
31
32sub expected_effect {
33 my ($self) = @_;
34 +(file_content => DX::Lib::FS::Fact::FileContent->new(
35 path => $self->from->path,
36 data => $self->final_content
37 ));
38}
39
40sub _do_run { die }
41
421;