Rex-Endpoint-HTTP

 view release on metacpan or  search on metacpan

lib/Rex/Endpoint/HTTP/Interface/Fs/Base.pm  view on Meta::CPAN


   CORE::rename($old, $new) or die($!);

   return 1;
}

sub glob {
   my ($self, $glob) = @_;

   my @ret = CORE::glob($glob);

   return @ret;
}

sub upload {
   my ($self, $path, $upload) = @_;

   open(my $fh, ">", $path) or die($!);
   print $fh $upload->slurp;
   close($fh);

   return 1;
}

sub download {
   my ($self, $path) = @_;

   if(! -f $path) {
      die("File not found.");
   }

   my $content = eval { local(@ARGV, $/) = ($path); <>; };

   return $content;
}

sub ln {
   my ($self, $from, $to) = @_;

   if(-f $to) {
      CORE::unlink($to) or die($!);
   }

   CORE::symlink($from, $to) or die($!);

   return 1;
}

sub rmdir {
   my ($self, $path) = @_;

   system("rm -rf " . $path);

   if($? == 0) {
      return 1;
   }

   die("Error deleting directory.");
}

sub chown {
   my ($self, $user, $file, $options) = @_;

   my $recursive = "";
   if(exists $options->{"recursive"} && $options->{"recursive"} == 1) {
      $recursive = " -R ";
   }

   system("chown $recursive $user $file");

   if($? == 0) {
      return 1;
   }

   die("Error changing ownership of file");
}

sub chgrp {
   my ($self, $group, $file, $options) = @_;

   my $recursive = "";
   if(exists $options->{"recursive"} && $options->{"recursive"} == 1) {
      $recursive = " -R ";
   }

   system("chgrp $recursive $group $file");

   if($? == 0) {
      return 1;
   }

   die("Error chaning group ownership of file");
}

sub chmod {
   my ($self, $mode, $file, $options) = @_;

   my $recursive = "";
   if(exists $options->{"recursive"} && $options->{"recursive"} == 1) {
      $recursive = " -R ";
   }

   system("chmod $recursive $mode $file");

   if($? == 0) {
      return 1;
   }

   die("Error changing file permission");
}

sub cp {
   my ($self, $source, $dest) = @_;

   system("cp -R $source $dest");

   if($? == 0) {
      return 1;
   }

   die("Error copying file");
}

1;



( run in 0.457 second using v1.01-cache-2.11-cpan-5511b514fd6 )