package DX::Lib::FS::Action::CreateFile;
+use aliased 'DX::Lib::FS::Fact::FileContent';
use aliased 'DX::Lib::FS::Fact::PathStatus';
use aliased 'DX::Lib::FS::Fact::PathStatusInfo';
use Moo;
with 'DX::Role::Action';
+with 'DX::Lib::FS::Role::RunOn';
has path => (is => 'ro', required => 1);
+has mode => (is => 'ro', predicate => 1);
+
+has data => (is => 'ro', default => sub { '' });
+
sub expected_effect {
my ($self) = @_;
return +(path_status => PathStatus->new(
path => $self->path,
- info => PathStatusInfo->new(is_file => 1, mode => '')
+ info => PathStatusInfo->new(
+ is_file => 1,
+ mode => ($self->has_mode ? $self->mode : '')
+ )
+ ), file_content => FileContent->new(
+ path => $self->path,
+ data => $self->data,
));
}
sub _do_run {
my ($self) = @_;
- open my $fh, '>>', $self->path or die "Couldn't create ${\$self->path}: $!";
- +(path_status => PathStatus->new(path => $self->path));
+ $self->_call_guts(create_file => $self->mode, $self->data);
+ +(path_status => $self->path);
+}
+
+sub but_add {
+ $_[0]->but(data => $_[0]->data.$_[1]."\n")
}
1;