Codebase list libfile-path-tiny-perl / e98d34d
Imported Upstream version 0.2 Alessandro Ghedini 12 years ago
5 changed file(s) with 81 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
00 Revision history for File-Path-Tiny
1
2 0.2 Sun Mar 11 16:50:44 2012
3 rt 51728 Missing colon in synopsis
4 rt 75688 using deprecated for qw() in 00.load.t
5 perltidy
16
27 0.1 Mon Nov 17 20:09:59 2008
38 Initial release.
0 # http://module-build.sourceforge.net/META-spec.html
1 #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
2 name: File-Path-Tiny
3 version: 0.1
4 version_from: lib/File/Path/Tiny.pm
5 installdirs: site
0 --- #YAML:1.0
1 name: File-Path-Tiny
2 version: 0.2
3 abstract: recursive versions of mkdir() and rmdir() without as much overhead as File::Path
4 author:
5 - Daniel Muey <http://drmuey.com/cpan_contact.pl>
6 license: unknown
7 distribution_type: module
8 configure_requires:
9 ExtUtils::MakeMaker: 0
10 build_requires:
11 ExtUtils::MakeMaker: 0
612 requires:
7 Test::More: 0
8
9 distribution_type: module
10 generated_by: ExtUtils::MakeMaker version 6.30
13 Test::More: 0
14 no_index:
15 directory:
16 - t
17 - inc
18 generated_by: ExtUtils::MakeMaker version 6.56
19 meta-spec:
20 url: http://module-build.sourceforge.net/META-spec-v1.4.html
21 version: 1.4
00 package File::Path::Tiny;
11
2 $File::Path::Tiny::VERSION = 0.1;
2 $File::Path::Tiny::VERSION = 0.2;
33
44 sub mk {
5 my ($path,$mask) = @_;
5 my ( $path, $mask ) = @_;
66 return 2 if -d $path;
7 if (-e $path) { $! = 20;return; }
8 $mask ||= '0777'; # Perl::Critic == Integer with leading zeros at ...
9 $mask = oct($mask) if substr($mask,0,1) eq '0';
7 if ( -e $path ) { $! = 20; return; }
8 $mask ||= '0777'; # Perl::Critic == Integer with leading zeros at ...
9 $mask = oct($mask) if substr( $mask, 0, 1 ) eq '0';
1010 require File::Spec;
11 my ($progressive, @parts) = File::Spec->splitdir($path);
12 if (!$progressive) {
13 $progressive = File::Spec->catdir($progressive, shift(@parts));
11 my ( $progressive, @parts ) = File::Spec->splitdir($path);
12 if ( !$progressive ) {
13 $progressive = File::Spec->catdir( $progressive, shift(@parts) );
1414 }
15 if(!-d $progressive) {
16 mkdir($progressive, $mask) or return;
15 if ( !-d $progressive ) {
16 mkdir( $progressive, $mask ) or return;
1717 }
1818 for my $part (@parts) {
19 $progressive = File::Spec->catdir($progressive,$part);
20 if (!-d $progressive) {
21 mkdir($progressive, $mask) or return;
19 $progressive = File::Spec->catdir( $progressive, $part );
20 if ( !-d $progressive ) {
21 mkdir( $progressive, $mask ) or return;
2222 }
2323 }
2424 return 1 if -d $path;
2727
2828 sub rm {
2929 my ($path) = @_;
30 if (-e $path && !-d $path) { $! = 20;return; }
30 if ( -e $path && !-d $path ) { $! = 20; return; }
3131 return 2 if !-d $path;
32 opendir(DIR, $path) or return;
32 opendir( DIR, $path ) or return;
3333 my @contents = grep { $_ ne '.' && $_ ne '..' } readdir(DIR);
3434 closedir DIR;
3535 require File::Spec if @contents;
3636 for my $thing (@contents) {
37 my $long = File::Spec->catdir($path, $thing);
38 if (!-l $long && -d $long) {
37 my $long = File::Spec->catdir( $path, $thing );
38 if ( !-l $long && -d $long ) {
3939 rm($long) or return;
4040 }
4141 else {
4646 return 1;
4747 }
4848
49 1;
49 1;
33
44 =head1 VERSION
55
6 This document describes File::Path::Tiny version 0.1
6 This document describes File::Path::Tiny version 0.2
77
88 =head1 SYNOPSIS
99
1010 use File::Path::Tiny;
1111
12 if(!File::Path::Tiny:mk($path)) {
12 if(!File::Path::Tiny::mk($path)) {
1313 die "Could not make path '$path': $!";
1414 }
1515
16 if(!File::Path::Tiny:rm($path)) {
16 if(!File::Path::Tiny::rm($path)) {
1717 die "Could not remove path '$path': $!";
1818 }
1919
22 use lib '../lib';
33
44 BEGIN {
5 use_ok( 'File::Path::Tiny' );
5 use_ok('File::Path::Tiny');
66 }
77
8 diag( "Testing File::Path::Tiny $File::Path::Tiny::VERSION" );
8 diag("Testing File::Path::Tiny $File::Path::Tiny::VERSION");
99
1010 # cleanup from last time
1111
12 for my $path qw(
13 foo/bar/mode foo/bar/mode2 foo/bar/mode3
14 foo/bar/mode_mkdir foo/bar/mode_mkdir2 foo/bar/dir
12 for my $path (
13 qw(
14 foo/bar/mode foo/bar/mode2 foo/bar/mode3
15 foo/bar/mode_mkdir foo/bar/mode_mkdir2 foo/bar/dir
1516 foo/bar/file foo/bar foo
16 ) {
17 if (!-l $path && -d $path) {
17 )
18 ) {
19 if ( !-l $path && -d $path ) {
1820 rmdir $path;
1921 }
2022 else {
2426
2527 SKIP: {
2628 skip 'Stale testing files exist', 5 if -d 'foo/bar';
27 ok(File::Path::Tiny::mk("foo/bar"), "make simple path - return true");
28 ok(-d "foo/bar", "make simple path - path recursively created");
29 ok(File::Path::Tiny::mk("foo") == 2, "make already existing dir");
30 if( open my $fh, '>', 'foo/bar/file') {
29 ok( File::Path::Tiny::mk("foo/bar"), "make simple path - return true" );
30 ok( -d "foo/bar", "make simple path - path recursively created" );
31 ok( File::Path::Tiny::mk("foo") == 2, "make already existing dir" );
32 if ( open my $fh, '>', 'foo/bar/file' ) {
3133 print {$fh} "test";
3234 close $fh;
3335 }
34 SKIP: {
36 SKIP: {
3537 skip 'test file not created', 2 if !-e 'foo/bar/file';
36 ok(!File::Path::Tiny::mk("foo/bar/file"), "make already existing non dir - return false");
37 ok($! == 20, "make already existing file - errno");
38 ok( !File::Path::Tiny::mk("foo/bar/file"), "make already existing non dir - return false" );
39 ok( $! == 20, "make already existing file - errno" );
3840 }
3941 }
4042
4143 mkdir 'foo/bar/dir';
4244
43 my $mk_mode = (stat('foo/bar'))[2];
45 my $mk_mode = ( stat('foo/bar') )[2];
46
4447 # $mk_mode = sprintf('%04o', $mk_mode & 07777);
45 my $mkdir_mode = (stat('foo/bar/dir'))[2];
48 my $mkdir_mode = ( stat('foo/bar/dir') )[2];
49
4650 # $mkdir_mode = sprintf('%04o', $mkdir_mode & 07777);
4751 # diag("mk: $mk_mode, mkdir: $mkdir_mode");
48 ok($mk_mode == $mkdir_mode, 'MASK logic gets same results as mkdir()');
52 ok( $mk_mode == $mkdir_mode, 'MASK logic gets same results as mkdir()' );
4953
50 File::Path::Tiny::mk("foo/bar/mode",0700);
54 File::Path::Tiny::mk( "foo/bar/mode", 0700 );
5155 mkdir 'foo/bar/mode_mkdir', 0700;
52 ok((stat('foo/bar/mode'))[2] == (stat('foo/bar/mode_mkdir'))[2], 'MASK arg OCT gets same results as mkdir()');
56 ok( ( stat('foo/bar/mode') )[2] == ( stat('foo/bar/mode_mkdir') )[2], 'MASK arg OCT gets same results as mkdir()' );
5357
54 File::Path::Tiny::mk("foo/bar/mode2",oct('0700'));
58 File::Path::Tiny::mk( "foo/bar/mode2", oct('0700') );
5559 mkdir 'foo/bar/mode_mkdir2', oct('0700');
56 ok((stat('foo/bar/mode2'))[2] == (stat('foo/bar/mode_mkdir2'))[2], 'MASK arg oct(STR) gets same results as mkdir()');
60 ok( ( stat('foo/bar/mode2') )[2] == ( stat('foo/bar/mode_mkdir2') )[2], 'MASK arg oct(STR) gets same results as mkdir()' );
5761
58 File::Path::Tiny::mk("foo/bar/mode3", "0700");
62 File::Path::Tiny::mk( "foo/bar/mode3", "0700" );
63
5964 # mkdir 'foo/bar/mode_mkdir3', "0700"; # this breaks permissions so we compare with previous one
60 ok((stat('foo/bar/mode3'))[2] == (stat('foo/bar/mode2'))[2], 'MASK arg STR gets detected and handled - different results as mkdir()');
65 ok( ( stat('foo/bar/mode3') )[2] == ( stat('foo/bar/mode2') )[2], 'MASK arg STR gets detected and handled - different results as mkdir()' );
6166
62 ok(!File::Path::Tiny::rm("foo/bar/file"), "remove existing non dir - return false");
63 ok($! == 20, "remove existing non dir - errno");
67 ok( !File::Path::Tiny::rm("foo/bar/file"), "remove existing non dir - return false" );
68 ok( $! == 20, "remove existing non dir - errno" );
6469 undef $!;
65 ok(File::Path::Tiny::rm('foo/bar'), "empty and remove simple path - return true");
66 ok(!-d 'foo/bar', "remove simple path - path recursively removed");
67 ok(File::Path::Tiny::rm('foo/bar') == 2, "remove already non-existing dir");
68 ok(File::Path::Tiny::rm('foo'), 'remove empty dir');
70 ok( File::Path::Tiny::rm('foo/bar'), "empty and remove simple path - return true" );
71 ok( !-d 'foo/bar', "remove simple path - path recursively removed" );
72 ok( File::Path::Tiny::rm('foo/bar') == 2, "remove already non-existing dir" );
73 ok( File::Path::Tiny::rm('foo'), 'remove empty dir' );