move the actual doing stuff code for FS lib into a Guts.pm
[scpubgit/DKit.git] / lib / DX / Lib / FS / Observation / PathStatus.pm
index ac397a1..a7b05cf 100644 (file)
@@ -2,28 +2,21 @@ package DX::Lib::FS::Observation::PathStatus;
 
 use aliased 'DX::Lib::FS::Fact::PathStatus';
 use aliased 'DX::Lib::FS::Fact::PathStatusInfo';
-use POSIX qw(ENOENT);
-use File::stat;
+use DX::Lib::FS::Guts;
 use Moo;
 
 has path => (is => 'ro', required => 1);
 
 sub run {
   my ($self) = @_;
-  if (my $stat = stat(my $path = $self->path)) {
-    (path_status => PathStatus->new(
-      path => $path,
-      info => PathStatusInfo->new(
-        is_directory => -d _,
-        is_file => -f _,
-        mode => sprintf("%04o", ($stat->mode & 07777)),
-      )
-    ));
-  } elsif ($! == ENOENT) {
-    (path_status => PathStatus->new(path => $path));
-  } else {
-    die "Couldn't stat ${path}: $!";
-  }
+  my $info = DX::Lib::FS::Guts->path_status_info($self->path);
+  (path_status => PathStatus->new(
+    path => $self->path,
+    ($info
+      ? (info => PathStatusInfo->new($info))
+      : ()
+    )
+  ));
 }
 
 1;