Directory-Scratch

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        - removed all uses of File::Slurp (RT#92973)
        - add formal deprecation notice

0.15    2013-04-13 00:00:00Z
        - Remove test for Classic Mac, fixing RT#83318

0.14    2008-06-08 00:00:00Z
        - remove auto_install and update Module::Install

0.13    2007-10-19 00:00:00Z
        - add "chmod" and "stat" commands

0.12    2007-01-25 00:00:00Z
        - fix non-hard-coded '/' for Win32 users CORRECTLY; it
	  really works now, I promise!
        - add create_tree for quickly creating directory trees

0.11    2006-12-27 00:00:00Z
	- add environment variable to suppress auto-cleanup
	- fix hard-coded '/' for Win32 users

MANIFEST  view on Meta::CPAN

t/integration/07-delete.t
t/integration/08-exists.t
t/integration/09-clone_object.t
t/integration/10-new-with-arguments.t
t/integration/11-cleanup.t
t/integration/11-stringify.t
t/integration/12-randfile.t
t/integration/other_output_seperator.t
t/os/win32.t
t/unit/append.t
t/unit/chmod.t
t/unit/cleanup.t
t/unit/create_tree.t
t/unit/delete.t
t/unit/invalid_clone.t
t/unit/invalid_directory.t
t/unit/link.t
t/unit/ls.t
t/unit/mkdir.t
t/unit/openfile.t
t/unit/randfile.t

lib/Directory/Scratch.pm  view on Meta::CPAN


    $from = $self->_foreign_file($base, $from);
    $to   = $self->_foreign_file($base, $to);

    symlink($from, $to) 
      or croak "Couldn't link $from to $to: $!";
    
    return $to;
}

sub chmod {
    my $self  = shift;
    my $mode  = shift;
    my @paths = @_;
    
    my @translated = map { $self->_foreign_file($self->base, $_) } @paths;
    return chmod $mode, @translated;
}

sub read {
    my $self = shift;
    my $file = shift;
    my $base = $self->base;
    
    $file = $self->_foreign_file($base, $file);

    croak "Cannot read $file: is a directory" if -d $file;

lib/Directory/Scratch.pm  view on Meta::CPAN

=head2 delete($path)

Deletes the named file or directory at $path.

If the path is removed successfully, the method returns true.
Otherwise, an exception is thrown.

(Note: delete means C<unlink> for a file and C<rmdir> for a directory.
C<delete>-ing an unempty directory is an error.)

=head2 chmod($octal_permissions, @files)

Sets the permissions C<$octal_permissions> on C<@files>, returning the
number of files successfully changed. Note that C<'0644'> is
C<--w----r-T>, not C<-rw-r--r-->.  You need to pass in C<oct('0644')>
or a literal C<0644> for this method to DWIM.  The method is just a
passthru to perl's built-in C<chmod> function, so see C<perldoc -f
chmod> for full details.

=head2 cleanup

Forces an immediate cleanup of the current object's directory.  See
File::Path's rmtree().  It is not safe to use the object after this
method is called.

=head1 ENVIRONMENT

If the C<PERL_DIRECTORYSCRATCH_CLEANUP> variable is set to 0, automatic

t/unit/chmod.t  view on Meta::CPAN

use strict;
use warnings;

my $tmp = Directory::Scratch->new;
ok $tmp, 'created $tmp' ;

my @files = qw/foo bar baz/;
my @paths = map { $tmp->touch($_, "this is $_") } @files;
is scalar @paths, 3, '3 files created';

$tmp->chmod(0666, @files);
is mode($_), 0666, 'mode is 0666' for @paths;

$tmp->chmod(0444, 'foo');
is mode($paths[0]), 0444, 'mode is 0444 for foo';
is mode($paths[1]), 0666, 'mode is 0666 for bar';

sub mode {
    my $mode = [stat $_[0]]->[2];
    $mode &= 0777;
    return $mode;
}



( run in 0.356 second using v1.01-cache-2.11-cpan-8d75d55dd25 )