beginnings of FS lib
[scpubgit/DKit.git] / lib / DX / Lib / FS / Observation / PathStatus.pm
CommitLineData
4d2ad771 1package DX::Lib::FS::Observation::PathStatus;
2
3use aliased 'DX::Lib::FS::Fact::PathStatus';
4use aliased 'DX::Lib::FS::Fact::PathStatusInfo';
5use POSIX qw(ENOENT);
6use File::stat;
7use Moo;
8
9has path => (is => 'ro', required => 1);
10
11sub run {
12 my ($self) = @_;
13 if (my $stat = stat(my $path = $self->path)) {
14 (path_status => PathStatus->new(
15 path => $path,
16 info => PathStatusInfo->new(
17 is_directory => -d _,
18 is_file => -f _,
19 mode => sprintf("%04o", ($stat->mode & 07777)),
20 )
21 ));
22 } elsif ($! == ENOENT) {
23 (path_status => PathStatus->new(path => $path));
24 } else {
25 die "Couldn't stat ${path}: $!";
26 }
27}
28
291;