File-Path-Tiny-0.7/000755 000765 000765 00000000000 12221144751 014373 5ustar00dmueydmuey000000 000000 File-Path-Tiny-0.7/Changes000644 000765 000765 00000001366 12221144166 015674 0ustar00dmueydmuey000000 000000 Revision history for File-Path-Tiny 0.7 2013-09-26 18:46:19 - add =encoding to POD due to test failure on certain boxes - add several perl, pkg, and pod tests 0.6 2013-09-24 05:51:54 add mk_parent() 0.5 2012-09-06 07:38:06 rt 79472 (thanks Lachlan!) fix absolute path bug introduced in 0.4 0.4 2012-09-03 17:50:41 rt 79345 (thanks Gian!): Failed to recursively create dir if the first part solves to false 0.3 2013-04-06 19:39:52 rt 76061 No LICENSE in META.yml rt 68950 break out rm() code into empty() type function, use it in rm() 0.2 2012-03-11 16:50:44 rt 51728 Missing colon in synopsis rt 75688 using deprecated for qw() in 00.load.t perltidy 0.1 2008 -11-17 20:09:59 Initial release. File-Path-Tiny-0.7/MANIFEST000644 000765 000765 00000000545 12221143351 015523 0ustar00dmueydmuey000000 000000 Changes MANIFEST Makefile.PL README lib/File/Path/Tiny.pm lib/File/Path/Tiny.pod t/00.load.t t/perlcritic.t t/perltidy.t t/pkg-changes.t t/pkg-readme.t t/pod-coverage.t t/pod-spelling.t t/pod.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) File-Path-Tiny-0.7/META.json000644 000765 000765 00000001660 12221144751 016017 0ustar00dmueydmuey000000 000000 { "abstract" : "recursive versions of mkdir() and rmdir() without as much overhead as File::Path", "author" : [ "Daniel Muey " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "File-Path-Tiny", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.7" } File-Path-Tiny-0.7/META.yml000644 000765 000765 00000001054 12221144751 015644 0ustar00dmueydmuey000000 000000 --- abstract: 'recursive versions of mkdir() and rmdir() without as much overhead as File::Path' author: - 'Daniel Muey ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: File-Path-Tiny no_index: directory: - t - inc requires: Test::More: 0 version: 0.7 File-Path-Tiny-0.7/Makefile.PL000644 000765 000765 00000000756 12221144656 016361 0ustar00dmueydmuey000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'File::Path::Tiny', AUTHOR => 'Daniel Muey ', VERSION_FROM => 'lib/File/Path/Tiny.pm', ABSTRACT_FROM => 'lib/File/Path/Tiny.pod', PL_FILES => {}, LICENSE => 'perl', PREREQ_PM => { 'Test::More' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'File-Path-Tiny-*' }, ); File-Path-Tiny-0.7/README000644 000765 000765 00000000720 12221144216 015246 0ustar00dmueydmuey000000 000000 File-Path-Tiny version 0.7 DOCUMENTATION See POD for documentation. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install DEPENDENCIES See DEPENDENCIES section in POD, 'requires' key in Build.PL, or 'PREREQ_PM' key in Makefile.PL COPYRIGHT AND LICENCE Copyright (C) 2008, Daniel Muey This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. File-Path-Tiny-0.7/lib/000755 000765 000765 00000000000 12221144751 015141 5ustar00dmueydmuey000000 000000 File-Path-Tiny-0.7/t/000755 000765 000765 00000000000 12221144751 014636 5ustar00dmueydmuey000000 000000 File-Path-Tiny-0.7/t/00.load.t000644 000765 000765 00000011053 12221144657 016165 0ustar00dmueydmuey000000 000000 use Test::More tests => 30; use lib '../lib'; BEGIN { use_ok('File::Path::Tiny'); } diag("Testing File::Path::Tiny $File::Path::Tiny::VERSION"); # cleanup from last time for my $path ( qw( foo/bar/mode foo/bar/mode2 foo/bar/mode3 foo/bar/mode_mkdir foo/bar/mode_mkdir2 foo/bar/dir foo/bar/file foo/bar foo zib/dib zib parent_mode parent_oct parent_str ) ) { if ( !-l $path && -d $path ) { rmdir $path; } else { unlink $path; } } SKIP: { skip 'Stale testing files exist', 5 if -d 'foo/bar'; ok( File::Path::Tiny::mk("foo/bar"), "make simple path - return true" ); ok( -d "foo/bar", "make simple path - path recursively created" ); ok( File::Path::Tiny::mk("foo") == 2, "make already existing dir" ); if ( open my $fh, '>', 'foo/bar/file' ) { print {$fh} "test"; close $fh; } SKIP: { skip 'test file not created', 2 if !-e 'foo/bar/file'; ok( !File::Path::Tiny::mk("foo/bar/file"), "make already existing non dir - return false" ); ok( $! == 20, "make already existing file - errno" ); } my $file = "zib/dib/kib"; ok( File::Path::Tiny::mk_parent($file), "mk_parent() simple path returns true" ); ok( -d "zib/dib", "mk_parent() simple path - parent recursively created" ); ok( !-e $file, "mk_parent() simple path - file not created" ); ok( File::Path::Tiny::mk_parent($file) == 2, "mk_parent() already existing simple path dir" ); } SKIP: { eval 'require File::Temp;'; skip 'Absolute path test/mk_parent requires File::Temp', 3 if $@; my $dir = File::Temp->newdir(); my $new = "$dir/foo/bar/baz"; ok( File::Path::Tiny::mk($new), "make absolute path - return true" ); ok( -d $new, "make absolute path - path recursively created" ); ok( File::Path::Tiny::mk($new) == 2, "make already existing absolute path dir" ); my $file = "$dir/zib/dib/kib"; ok( File::Path::Tiny::mk_parent($file), "mk_parent() absolute path returns true" ); ok( -d "$dir/zib/dib", "mk_parent() absolute path - parent recursively created" ); ok( !-e $file, "mk_parent() absolute path - file not created" ); ok( File::Path::Tiny::mk_parent($file) == 2, "mk_parent() already existing absolute path dir" ); } mkdir 'foo/bar/dir'; my $mk_mode = ( stat('foo/bar') )[2]; # $mk_mode = sprintf('%04o', $mk_mode & 07777); my $mkdir_mode = ( stat('foo/bar/dir') )[2]; # $mkdir_mode = sprintf('%04o', $mkdir_mode & 07777); # diag("mk: $mk_mode, mkdir: $mkdir_mode"); ok( $mk_mode == $mkdir_mode, 'MASK logic gets same results as mkdir()' ); File::Path::Tiny::mk( "foo/bar/mode", 0700 ); File::Path::Tiny::mk_parent( "parent_mode/x", 0700 ); mkdir 'foo/bar/mode_mkdir', 0700; ok( ( stat('foo/bar/mode') )[2] == ( stat('foo/bar/mode_mkdir') )[2], 'MASK arg OCT gets same results as mkdir()' ); ok( ( stat('parent_mode') )[2] == ( stat('foo/bar/mode_mkdir') )[2], 'MASK arg OCT gets same results as mkdir() - mk_parent()' ); File::Path::Tiny::mk( "foo/bar/mode2", oct('0700') ); File::Path::Tiny::mk_parent( "parent_oct/x", oct('0700') ); mkdir 'foo/bar/mode_mkdir2', oct('0700'); ok( ( stat('foo/bar/mode2') )[2] == ( stat('foo/bar/mode_mkdir2') )[2], 'MASK arg oct(STR) gets same results as mkdir()' ); ok( ( stat('parent_oct') )[2] == ( stat('foo/bar/mode_mkdir2') )[2], 'MASK arg oct(STR) gets same results as mkdir() - mk_parent()' ); File::Path::Tiny::mk( "foo/bar/mode3", "0700" ); File::Path::Tiny::mk_parent( "parent_str/x", "0700" ); # mkdir 'foo/bar/mode_mkdir3', "0700"; # this breaks permissions so we compare with previous one ok( ( stat('foo/bar/mode3') )[2] == ( stat('foo/bar/mode2') )[2], 'MASK arg STR gets detected and handled - different results as mkdir()' ); ok( ( stat('parent_str') )[2] == ( stat('foo/bar/mode2') )[2], 'MASK arg STR gets detected and handled - different results as mkdir() - mk_parent()' ); ok( !File::Path::Tiny::rm("foo/bar/file"), "remove existing non dir - return false" ); ok( $! == 20, "remove existing non dir - errno" ); undef $!; ok( File::Path::Tiny::rm('foo/bar'), "empty and remove simple path - return true" ); ok( !-d 'foo/bar', "remove simple path - path recursively removed" ); ok( File::Path::Tiny::rm('foo/bar') == 2, "remove already non-existing dir" ); ok( File::Path::Tiny::rm('foo'), 'remove empty dir' ); File-Path-Tiny-0.7/t/perlcritic.t000644 000765 000765 00000000424 12221144657 017170 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'Critic tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::Perl::Critic'; plan skip_all => 'Test::Perl::Critic required for testing PBP compliance' if $@; Test::Perl::Critic::all_critic_ok(); File-Path-Tiny-0.7/t/perltidy.t000644 000765 000765 00000000405 12221144660 016655 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'PerlTidy tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::PerlTidy'; plan skip_all => 'Test::PerlTidy required for testing PerlTidy-ness' if $@; Test::PerlTidy::run_tests(); File-Path-Tiny-0.7/t/pkg-changes.t000644 000765 000765 00000000455 12221144660 017215 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'pkg/Changes tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::CPAN::Changes 0.23'; plan skip_all => 'Test::CPAN::Changes 0.23 required for testing the pkg/Changes file' if $@; changes_ok(); # this does the plan File-Path-Tiny-0.7/t/pkg-readme.t000644 000765 000765 00000000460 12221144660 017036 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'pkg/README tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::CPAN::README'; plan skip_all => 'Test::CPAN::README required for testing the pkg/README file' if $@; readme_ok('File::Path::Tiny'); # this does the plan File-Path-Tiny-0.7/t/pod-coverage.t000644 000765 000765 00000000416 12221144660 017376 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'POD tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::Pod::Coverage 1.04'; plan skip_all => 'Test::Pod::Coverage v1.04 required for testing POD coverage' if $@; all_pod_coverage_ok(); File-Path-Tiny-0.7/t/pod-spelling.t000644 000765 000765 00000000577 12221144660 017430 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'POD tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::Spelling 0.19'; plan skip_all => 'Test::Spelling v0.19 required for testing POD' if $@; add_stopwords( map { split /[\s\:\-]/ } readline(*DATA) ); $ENV{LANG} = 'C'; all_pod_files_spelling_ok(); __DATA__ MERCHANTABILITY Muey LICENCE app baz File-Path-Tiny-0.7/t/pod.t000644 000765 000765 00000000356 12221144661 015611 0ustar00dmueydmuey000000 000000 #!perl use Test::More; plan skip_all => 'POD tests are only run in RELEASE_TESTING mode.' unless $ENV{'RELEASE_TESTING'}; eval 'use Test::Pod 1.14'; plan skip_all => 'Test::Pod v1.14 required for testing POD' if $@; all_pod_files_ok(); File-Path-Tiny-0.7/lib/File/000755 000765 000765 00000000000 12221144751 016020 5ustar00dmueydmuey000000 000000 File-Path-Tiny-0.7/lib/File/Path/000755 000765 000765 00000000000 12221144751 016714 5ustar00dmueydmuey000000 000000 File-Path-Tiny-0.7/lib/File/Path/Tiny.pm000644 000765 000765 00000003675 12221144657 020215 0ustar00dmueydmuey000000 000000 package File::Path::Tiny; use strict; use warnings; $File::Path::Tiny::VERSION = 0.7; sub mk { my ( $path, $mask ) = @_; return 2 if -d $path; if ( -e $path ) { $! = 20; return; } $mask ||= '0777'; # Perl::Critic == Integer with leading zeros at ... $mask = oct($mask) if substr( $mask, 0, 1 ) eq '0'; require File::Spec; my ( $progressive, @parts ) = File::Spec->splitdir($path); if ( !defined $progressive || $progressive eq '' ) { $progressive = File::Spec->catdir( $progressive, shift(@parts) ); } if ( !-d $progressive ) { mkdir( $progressive, $mask ) or return; } for my $part (@parts) { $progressive = File::Spec->catdir( $progressive, $part ); if ( !-d $progressive ) { mkdir( $progressive, $mask ) or return; } } return 1 if -d $path; return; } sub rm { my ($path) = @_; if ( -e $path && !-d $path ) { $! = 20; return; } return 2 if !-d $path; empty_dir($path) or return; rmdir($path) or return; return 1; } sub empty_dir { my ($path) = @_; if ( -e $path && !-d $path ) { $! = 20; return; } opendir( DIR, $path ) or return; my @contents = grep { $_ ne '.' && $_ ne '..' } readdir(DIR); closedir DIR; require File::Spec if @contents; for my $thing (@contents) { my $long = File::Spec->catdir( $path, $thing ); if ( !-l $long && -d $long ) { rm($long) or return; } else { unlink $long or return; } } return 1; } sub mk_parent { my ( $path, $mode ) = @_; $path =~ s{/+$}{}; require File::Spec; my ( $v, $d, $f ) = File::Spec->splitpath( $path, 1 ); my @p = File::Spec->splitdir($d); # pop() is probably cheaper here, benchmark? $d = File::Spec->catdir(@p[0--$#p-1]); pop @p; $d = File::Spec->catdir(@p); my $parent = File::Spec->catpath( $v, $d, $f ); return mk( $parent, $mode ); } 1; File-Path-Tiny-0.7/lib/File/Path/Tiny.pod000644 000765 000765 00000017027 12221144612 020346 0ustar00dmueydmuey000000 000000 =encoding utf8 =head1 NAME File::Path::Tiny - recursive versions of mkdir() and rmdir() without as much overhead as File::Path =head1 VERSION This document describes File::Path::Tiny version 0.7 =head1 SYNOPSIS use File::Path::Tiny; if(!File::Path::Tiny::mk($path)) { die "Could not make path '$path': $!"; } if(!File::Path::Tiny::rm($path)) { die "Could not remove path '$path': $!"; } =head1 DESCRIPTION The goal here is simply to provide recursive versions of L() and L() with as little code and overhead as possible. This module is in no way meant to derogate L and is in no way an endorsement to go out and replace all use of L with L. L is very good at what it does but there's simply a lot happening that we can do without much of the time. Here are some things L has/does that this module attempts to do without: =over 4 =item * multiple interfaces Backwards compatibility brings in a lot of code and logic that we don't need from here on out. =item * chdir()s It does a ton of chdir()s which could leave you somewhere you're not planning on being and requires much more overhead to do. =item * can croak not allowing you to detect and handle failure Just let me handle errors how I want. Don't make my entire app die or have to wrap it in an eval =item * A well intentioned output system Just let me do the output how I want. (Nothing, As HTML, print to a filehandle, etc...) =item * A well intentioned and experimental (IE subject to change) error handling system. Just keep it simple and detect failure via a boolean check and do what I want with the error. See L =item * According to its POD, removing a tree is apparently not safe unless you tell it to be with the ‘safe’ or 'keep_root' attributes. Seems like that should just happen, I don't want to worry about accidentally removing / when I pass it /tmp =back =head1 INTERFACE Nothing in exported or exportable, that helps keep it '::Tiny'. =head2 File::Path::Tiny::mk() Takes a single path (like L()) to recursively create and, optionally, a mask (like L()) for all subsequent L() calls. Mask defaults to 0700 (also like L()) Returns false if it could not be made, true otherwise (returns ‘2’ if it is -d already) It is recursive in the sense that given “foo/bar/baz” as the path to create all 3 will be created if necessary. =head2 File::Path::Tiny::rm() Takes a single path (like L()) to recursively empty and remove. Returns false if it could not be emptied or removed, true otherwise. (returns ‘2’ if it is !-d already) It is recursive in the sense that given “/foo/bar/baz” as the path to remove it will recursively empty ‘baz’ and then remove it from /foo/bar. Its parents, /, /foo, and /foo/bar are *not* touched. =head2 File::Path::Tiny::empty_dir() Takes a single path to recursively empty but not remove. Returns false when there is a problem. =head2 File::Path::Tiny::mk_parent() Like mk() but recursively creates the parent. e.g. given “foo/bar/baz.txt” creates foo/bar. =head1 DIAGNOSTICS Throws no warnings or errors of its own If the functions ever return false, $! will have been set either explicitly or by the L(), L(), L(), or L() that ultimately returned false. =head1 MISC =head2 How can I make/remove multiple paths? For simplicity sake && ::Tiny status this module must be very very very simple. That said it is also very simple to do multiple paths: for my $path (@paths) { File::Path::Tiny::::mk($path) or _my_handle_failed_mk($path, $!); } for my $path (@paths) { File::Path::Tiny::::rm($path) or _my_handle_failed_rm($path, $!); } That also lets you keep going or short circuit it or handle errors however you like: PATH: for my $path qw(foo/bar bar/rat) { if (!File::Path::Tiny::mk($path)) { print "problem unlinking '$path': $!\n"; last PATH; } else { print "No error encountered with '$path'\n" } } =head2 About the '::Tiny' status See L for information on the ::Tiny suffix. #3 is almost there (< 1/5th +/-), a bit more trimming and I think we'll have it! #8 is N/A since part of the "sub set" is to do single paths like their non-recursive core counterparts and there are so many ways to invoke it with different consequences [ -- RSS Memory -- ] Baseline perl 1168 File::Path 1808 (+640) File::Path::Tiny 1288 (+120) Even though "time" isn't really a ::Tiny factor, it does improve loading a bit: [ -- time -- ] Baseline perl real 0m0.007s user 0m0.002s sys 0m0.004s File::Path real 0m0.017s user 0m0.011s sys 0m0.005s File::Path::Tiny real 0m0.007s user 0m0.003s sys 0m0.004s As time allows and more tests are added I'll try to include more comprehensive benchmark results. =head2 How do I make sure the path is safe to create or remove? Of course the answer depends on what you mean by "safe". This module makes no assumptions on interpreting the "safeness" of a path, just like L() and L(). Also like L() and L() typically you'll find that filesystem permissions are a pretty reliable tool (of course if the code will be run as root you would want to setuid first...) You might use Cwd::abs_path() to sanitize a path before sending it to be made or removed. Even after that it might not be "safe" so you'll need to discern what your particular definition of "safe" is and take appropriate action. =head1 DEPENDENCIES L of course but its only loaded if needed =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Daniel Muey C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2008, Daniel Muey C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.