use DX::Lib::FS::Action::CreateDirectory;
use DX::Lib::FS::Action::CreateFile;
use DX::Lib::FS::Action::SetPathMode;
+use DX::Lib::FS::Observation::FileContent;
+use DX::Lib::FS::Action::RewriteFile;
use File::Spec;
use DX::SetOver;
use Moo;
path_status => $_[0], mode => $_[1]
)
} ] ],
+ [ file_content => [ qw(FC) ],
+ [ member_of => 'FC', \'file_content' ] ],
+ [ file_content_at => [ qw(FC P) ],
+ [ file_content => 'FC' ],
+ [ path => qw(FC P) ],
+ [ 'cut' ] ],
+ [ file_content_at => [ qw(FC P) ],
+ [ observe => [ 'P' ], sub {
+ DX::Lib::FS::Observation::FileContent->new(
+ path => $_[0]
+ )
+ } ],
+ [ file_content => 'FC' ],
+ [ path => qw(FC P) ] ],
+ [ file_data => [ qw(FC D) ], [ prop => 'FC', \'data', 'D' ] ],
+ [ file_content_line => [ qw(FC L) ],
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ] ],
+ [ contains_line => [ qw(PS L) ],
+ [ is_file => 'PS' ],
+ [ exists => [ qw(FC P) ],
+ [ path => qw(PS P) ],
+ [ file_content_at => qw(FC P) ],
+ [ file_content_line => qw(FC L) ] ] ],
+ [ file_content_line => [ qw(FC L) ],
+ [ not =>
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ] ],
+ [ exists => [ 'A' ],
+ [ has_action => qw(FC A) ],
+ [ does => 'A' => \'DX::Lib::FS::Action::RewriteFile' ] ],
+ [ react => [ qw(FC L) ], sub { $_[0]->but_add($_[1]) } ],
+ [ 'cut' ] ],
+ [ file_content_line => [ qw(FC L) ],
+ [ not =>
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ] ],
+ [ act => [ qw(FC L) ], sub {
+ DX::Lib::FS::Action::RewriteFile->new(
+ from => $_[0],
+ add_lines => [ $_[1] ]
+ );
+ } ],
+ [ 'cut' ] ],
+ [ not_file_content_line => [ qw(FC L) ],
+ [ not =>
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ] ] ],
+ [ not_contains_line => [ qw(PS L) ],
+ [ is_file => 'PS' ],
+ [ exists => [ qw(FC P) ],
+ [ path => qw(PS P) ],
+ [ file_content_at => qw(FC P) ],
+ [ not_file_content_line => qw(FC L) ] ] ],
+ [ not_file_content_line => [ qw(FC L) ],
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ],
+ [ exists => [ 'A' ],
+ [ has_action => qw(FC A) ],
+ [ does => 'A' => \'DX::Lib::FS::Action::RewriteFile' ] ],
+ [ react => [ qw(FC L) ], sub { $_[0]->but_remove($_[1]) } ],
+ [ 'cut' ] ],
+ [ not_file_content_line => [ qw(FC L) ],
+ [ exists => [ 'Lines' ],
+ [ prop => 'FC' => \'lines' => 'Lines' ],
+ [ member_of => 'L' => 'Lines' ] ],
+ [ act => [ qw(FC L) ], sub {
+ DX::Lib::FS::Action::RewriteFile->new(
+ from => $_[0],
+ remove_lines => { $_[1] => 1 }
+ );
+ } ],
+ [ 'cut' ] ],
);
sub load_into {
my ($self, $solver) = @_;
$solver->facts->{path_status} = DX::SetOver->new(over => 'path');
+ $solver->facts->{file_content} = DX::SetOver->new(over => 'path');
$solver->add_predicate(
catdir => [ qw(DirPath DirName SubDirPath) ],
[ qw(+ + -) ] => sub {
--- /dev/null
+package DX::Lib::FS::Action::RewriteFile;
+
+use DX::Lib::FS::Fact::FileContent;
+use Moo;
+
+with 'DX::Role::Action';
+
+has from => (is => 'ro', required => 1);
+
+has add_lines => (is => 'ro', default => sub { [] });
+
+has remove_lines => (is => 'ro', default => sub { {} });
+
+has final_content => (is => 'lazy', init_arg => undef, builder => sub {
+ my ($self) = @_;
+ my %remove = %{$self->remove_lines};
+ join("\n",
+ (grep !$remove{$_}, $self->from->lines->all),
+ @{$self->add_lines},
+ ''
+ );
+});
+
+sub but_add {
+ $_[0]->but(add_lines => [ @{$_[0]->add_lines}, $_[1] ]);
+}
+
+sub but_remove {
+ $_[0]->but(remove_lines => [ %{$_[0]->remove_lines}, $_[1] => 1 ]);
+}
+
+sub expected_effect {
+ my ($self) = @_;
+ +(file_content => DX::Lib::FS::Fact::FileContent->new(
+ path => $self->from->path,
+ data => $self->final_content
+ ));
+}
+
+sub _do_run { die }
+
+1;