?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/Path-Tiny-0.146-0.tar
???????
xt/author/pod-coverage.t 0000644 00000000365 15125124546 0011252 0 ustar 00 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use strict; use warnings; use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); xt/author/pod-syntax.t 0000644 00000000252 15125124546 0011000 0 ustar 00 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); xt/author/distmeta.t 0000644 00000000223 15125124546 0010502 0 ustar 00 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use strict; use warnings; use Test::CPAN::Meta; meta_yaml_ok(); xt/author/test-version.t 0000644 00000000637 15125124546 0011343 0 ustar 00 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 1.09 use Test::Version; my @imports = qw( version_all_ok ); my $params = { is_strict => 0, has_version => 1, multiple => 0, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; xt/author/critic.t 0000644 00000000201 15125124546 0010141 0 ustar 00 #!perl use strict; use warnings; use Test::Perl::Critic (-profile => "perlcritic.rc") x!! -e "perlcritic.rc"; all_critic_ok(); xt/author/00-compile.t 0000644 00000002656 15125124546 0010551 0 ustar 00 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058 use Test::More; plan tests => 2; my @module_files = ( 'Path/Tiny.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L<perlfaq8/How can I capture STDERR from an external command?> my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ); xt/author/portability.t 0000644 00000000163 15125124546 0011235 0 ustar 00 use strict; use warnings; use Test::More; use Test::Portability::Files; options(test_one_dot => 0); run_tests(); xt/author/pod-spell.t 0000644 00000002324 15125124546 0010573 0 ustar 00 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.007005 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(<DATA>); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ AIX Alex Andrade Aristotle Aslanov BENCHMARKING Bell BooK Book Bruhat CRLF Champoux Chris Continsouzas Dan Dave David Doug Efros Ehlers Ellis Elvin Etheridge Fish Flavio Fuji Gabor Gabriel George Geraud Golden Goro Graham Gregoire Hartzell Hunt IEC III Ian Inkster Ivy James John Karen Karr Keedi KiB Kim Kjeldsen Knop Lustre Mark Martin Mary MiB Michael Miyagawa NFS Nicolas Nigel Ollis Pagaltzis Path Philippe Poletti Rochelemagne Rolsky Roy SHA Schwern Shlomi Sillitoe Sluka Smylers Steinbrunner Szabo Tatsuhiko Tiny Toby UNC Williams Yanick autarch bingos book brainbuz canonpath chainable codepoints cwd dagolden dirname dsteinbrunner ether fany fatalize flavio gabiruh geraud gfuji grinnz haarg hartzell ian iec james kB keedi lib lstat madcityzen mark miyagawa mk mkdir mkpath mschwern nicolas nigelgregoire opena openr openrw openw pagaltzis perms plicease powerman realpath regina rivy rochelemagne rwp shlomif si stat stringifying subclasses szabgab tobyink touchpath unlinked utf yanick 김도형 xt/author/minimum-version.t 0000644 00000000152 15125124546 0012027 0 ustar 00 use strict; use warnings; use Test::More; use Test::MinimumVersion; all_minimum_version_ok( qq{5.010} ); CONTRIBUTING.mkdn 0000644 00000006604 15125124546 0007341 0 ustar 00 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means that many of the usual files you might expect are not in the repository, but are generated at release time, as is much of the documentation. Some generated files are kept in the repository as a convenience (e.g. Makefile.PL or cpanfile). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball. See below for guidance. ### Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, look for either a `Makefile.PL` or `cpanfile` file for a list of dependencies to satisfy. ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Some is generated boilerplate; other documentation is built from pseudo-POD directives in the source like C<=method> or C<=func>. If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Where to send patches and pull requests If you found this distribution on Github, sending a pull-request is the best way to contribute. If a pull-request isn't possible, a bug ticket with a patch file is the next best option. As a last resort, an email to the author(s) is acceptable. ## Installing and using Dist::Zilla Dist::Zilla is not required for contributing, but if you'd like to learn more, this section will get you up to speed. Dist::Zilla is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ pm_to_blib 0000644 00000000000 15125124546 0006570 0 ustar 00 Changes 0000644 00000074065 15125124546 0006060 0 ustar 00 Revision history for Path-Tiny 0.146 2024-05-08 08:27:52-04:00 America/New_York - No changes from 0.145-TRIAL 0.145 2024-05-01 22:26:26-04:00 America/New_York (TRIAL RELEASE) [Changes] - Improved error message spewing to a file in a non-existent directory. 0.144 2022-12-01 11:36:19-05:00 America/New_York - No changes from 0.143-TRIAL 0.143 2022-11-26 17:46:59-05:00 America/New_York (TRIAL RELEASE) [Testing] - Fixed tilde expansion tests where ~root expands to '/'. 0.142 2022-11-09 07:06:36-05:00 America/New_York No changes from 0.141; all changes since last stable release are summarized below. [*** DEPRECATIONS ***] - Tilde expansion is deprecated due to inconsistent and bug-prone behavior. [Bug fixes] - Prevent expansion of tildes that are not the very first character (e.g. "./~foo"). Prevent unintentional tilde expansion during internal path processing. Escape non-tilde glob characters before tilde expansion. - Fixed spew/edit to a long filename approaching the filesystem length limit. - Internal calls to `print` are checked for possible errors. - Internal read calls are checked for errors. [Changes] - Path stringification now adds "./" in front of paths starting with literal tilde so they will round-trip. FREEZE updated to use this stringification rule as well. - `move` now uses File::Copy::move internally instead of the built-in `rename`, allowing it to work across filesystems. It also returns an object for the moved location, allowing chaining. - edit_lines_raw now uses a buffered raw I/O layer. edit_lines_utf8 now prefers PerlIO::utf8_strict, if available. - lines_utf8 now consistently uses a buffered I/O layer. - open*_utf8 now prefers PerlIO::utf8_strict, if available. - slurp_utf8 now consistently uses an unbuffered I/O layer. [Documented] - Changed all raw/UTF-8 layer descriptions in method documentation to match the code. - Fixed SYNOPSIS syntax. - Documented how to disable TMPDIR when making temp files/dirs. [Testing] - Add additional tilde stringification testing. - Fixed tilde expansion tests on Windows. - Skip a problematic test case on cygwin. 0.141 2022-11-07 12:47:25-05:00 America/New_York (TRIAL RELEASE) [Testing] - Add additional tilde expansion tests 0.139 2022-11-03 15:44:46-04:00 America/New_York (TRIAL RELEASE) [Testing] - Skip a problematic test case on cygwin 0.137 2022-11-02 09:50:26-04:00 America/New_York (TRIAL RELEASE) [Testing] - Add additional tilde stringification testing. 0.135 2022-11-01 22:27:21-04:00 America/New_York (TRIAL RELEASE) [Testing] - Fixed additional issues with tilde expansion tests on Windows for testers with lowercase drive letters in their userprofile. 0.133 2022-10-31 23:55:01-04:00 America/New_York (TRIAL RELEASE) [Bug fixes] - Path stringification now adds "./" in front of paths starting with literal tilde so they will round-trip. FREEZE updated to use this stringification rule as well. [Changes] - `move` now uses File::Copy::move internally instead of the built-in `rename`, allowing it to work across filesystems. It also returns an object for the moved location, allowing chaining. [Testing] - Fixed tilde expansion tests on Windows. 0.131 2022-10-31 10:42:46-04:00 America/New_York (TRIAL RELEASE) [*** DEPRECATIONS ***] - Tilde expansion is deprecated due to inconsistent and bug-prone behavior. [Bug fixes] - Fixed spew/edit to a long filename approaching the filesystem length limit. - Internal calls to `print` are checked for possible errors. - Internal read calls are checked for errors. - Prevent expansion of tildes that are not the very first character (e.g. "./~foo"). Prevent unintentional tilde expansion during internal path processing. Escape non-tilde glob characters before tilde expansion. [Changes] - edit_lines_raw now uses a buffered raw I/O layer. edit_lines_utf8 now prefers PerlIO::utf8_strict, if available. - lines_utf8 now consistently uses a buffered I/O layer. - open*_utf8 now prefers PerlIO::utf8_strict, if available. - slurp_utf8 now consistently uses an unbuffered I/O layer. [Documented] - Changed all raw/UTF-8 layer descriptions in method documentation to match the code. - Fixed SYNOPSIS syntax. - Documented how to disable TMPDIR when making temp files/dirs. 0.130 2022-10-20 07:08:01-04:00 America/New_York [Bug fixes] - mkdir no longer fails when applied to an existing directory. 0.128 2022-10-19 15:32:39-04:00 America/New_York - No changes from 0.127-TRIAL. 0.127 2022-10-05 17:17:36-04:00 America/New_York (TRIAL RELEASE) [Testing] - Fixed has_same_bytes test for Windows. 0.125 2022-09-30 17:08:36-04:00 America/New_York (TRIAL RELEASE) [*** DEPRECATIONS ***] - The 'mkpath' method is deprecated in favor of 'mkdir'. [Additions] - Added 'mkdir' to replace 'mkpath', but returning the path object for chaining. - Added `has_same_bytes` to efficiently compare the contents of two files. [Documentation] - Edited SYNOPSIS 0.124 2022-09-02 11:06:12-04:00 America/New_York - No changes from 0.123-TRIAL. 0.123 2022-08-29 11:06:49-04:00 America/New_York (TRIAL RELEASE) [Documentation] - Added link to `touchpath` in the `mkpath` docs. - Fixed example in `tempfile` docs. 0.122 2022-01-16 10:05:08-05:00 America/New_York - No changes from 0.121-TRIAL. 0.121 2022-01-08 11:05:33-05:00 America/New_York (TRIAL RELEASE) [Additions] - Adds `size` and `size_human` methods. The latter gives `ls -lh` style output, with options to choose base2 or base10 forms. 0.120 2021-10-24 12:12:57-04:00 America/New_York - No changes from 0.119-TRIAL. 0.119 2021-10-20 18:15:24-04:00 America/New_York (TRIAL RELEASE) [Changes] - The `tempdir` and `tempfile` methods may be called on a Path::Tiny object representing a directory, in which case the directory will be used as the container for the temporary object (as if the `DIR` argument were used). 0.118 2021-02-04 19:09:58-05:00 America/New_York - No changes from 0.117-TRIAL. 0.117 2021-01-31 21:22:29-05:00 America/New_York (TRIAL RELEASE) [Tests] - Skip symlink tests on Windows by actually testing symlinks, as Perl 5.33.5 adds notional support but it's not possible without elevated privileges. 0.116 2021-01-22 10:32:22-05:00 America/New_York - No changes from 0.115-TRIAL. 0.115 2021-01-19 12:01:33-05:00 America/New_York (TRIAL RELEASE) [Tests] - Fixes tests on MSYS without symlinks enabled. 0.114 2020-04-26 10:10:29-04:00 America/New_York - No changes from 0.113-TRIAL. 0.113 2020-04-14 16:06:58-04:00 America/New_York (TRIAL RELEASE) [Fixes] - Uses \z instead of $ in regular expressions 0.112 2020-01-28 22:12:16-05:00 America/New_York - No changes from 0.111-TRIAL. 0.111 2020-01-23 10:54:48-05:00 America/New_York (TRIAL RELEASE) - Another test fix on Windows, possibly due to a behavior change in Cwd::getdcwd. 0.110 2020-01-13 13:11:38-05:00 America/New_York - No changes from 0.109-TRIAL. 0.109 2020-01-02 12:24:25-05:00 America/New_York (TRIAL RELEASE) - Fixes tests on Windows, particularly with newer File::Spec. 0.108 2018-07-30 15:35:23-04:00 America/New_York - No changes from 0.107-TRIAL. 0.107 2018-07-24 15:10:36-04:00 America/New_York (TRIAL RELEASE) [Fixes] - Fixed a bug where failure to load optional modules would trigger an external $SIG{__DIE__} handler. 0.106 2018-07-14 09:37:00-04:00 America/New_York [Tests] - Protected t/locking.t from PERL_PATH_TINY_NO_FLOCK already in the environment. 0.105 2018-07-07 10:09:04-04:00 America/New_York (TRIAL RELEASE) [Additions] - The PERL_PATH_TINY_NO_FLOCK environment variable has been added to allow users to disable file locking (and any associated warnings). [Changes] - Detection of unsupported 'flock' is no longer BSD-specific. This allows detecting and warning, for example, with the Luster filesystem on Linux. [Tests] - Improve reliability and diagnostics of tests run via 'do'. 0.104 2017-02-17 07:17:00-05:00 America/New_York - No changes from 0.103-TRIAL. 0.103 2017-02-10 17:25:06-05:00 America/New_York (TRIAL RELEASE) [Bug fixes] - Path::Tiny 0.101 on Windows made `$path->absolute("/foo")` return an absolute path starting with 'C:/foo', which was an unintentional behavior change. This release now uses any absolute base without further normalization. 0.101 2017-02-05 09:56:46-05:00 America/New_York (TRIAL RELEASE) [Changes] - The 'absolute' method now always returns an absolute path, even if a user provided a relative path for the base path. The old, odd behavior was documented, but people often don't read docs. The new behavior avoids suprises. [Additions] - Added 'cached_temp' method. 0.100 2017-01-14 22:47:55-05:00 America/New_York - No changes from 0.099-TRIAL. 0.099 2017-01-10 15:12:13-05:00 America/New_York (TRIAL RELEASE) [Tests] - Fixed tests for eventual removal of '.' from `@INC` in Perl. [Documentation] - Fixed filehandle mode typo. - Fixed typo in relative() that mentioned rel2abs instead of abs2rel. 0.098 2016-10-09 23:25:11-04:00 America/New_York - No changes from 0.097-TRIAL. 0.097 2016-09-30 22:03:10-04:00 America/New_York (TRIAL RELEASE) [Additions] - Added 'realpath' option for 'tempfile' and 'tempdir' for situations where an absolute temporary path just isn't enough. 0.096 2016-07-02 21:25:33-04:00 America/New_York - No changes from 0.095 0.095 2016-06-28 12:05:03-04:00 America/New_York (TRIAL RELEASE) [Tests] - Improved method for hiding some modules during tests. 0.094 2016-05-23 12:45:19-04:00 America/New_York - Fixed Changes note typo in 0.092. 0.092 had no changes since 0.091, not 0.090, meaning that all 0.091 changes were (and are) included. 0.092 2016-05-23 11:36:54-04:00 America/New_York - No changes from 0.091 0.091 2016-05-17 13:32:21-04:00 America/New_York (TRIAL RELEASE) [Changes] - Path::Tiny will prefer PerlIO::utf8_strict over encoding(UTF-8) if available and Unicode::UTF8 is not installed. [Fixes] - The 'touch' method can now set the current time on files that aren't owned, as long as they are writeable. [Tests] - Improved consistency of symlink support inspection; now always looks at $Config{d_symlink}. - Skips impossible test on 'msys' platform. 0.090 2016-05-02 07:08:58-04:00 America/New_York - No changes from 0.089 0.089 2016-04-26 22:21:00-04:00 America/New_York (TRIAL RELEASE) [Fixes] - Fix spew_utf8 to allow array references as input. 0.088 2016-04-15 08:41:07-04:00 America/New_York - No changes from 0.087 0.087 2016-04-12 12:13:14-04:00 America/New_York (TRIAL RELEASE) [Fixes] - Fixed bugs in relative symlink resolution for realpath, spew and edit_lines. [Changes] - Symlink resolution will detect circular loops and throw an error. 0.086 2016-04-03 13:49:37-04:00 America/New_York [Documented] - Improved documentation of copy and move. 0.084 2016-03-04 07:17:49-05:00 America/New_York [Fixes] - Fixed relative() for the case with regex metacharacters in the path 0.082 2016-03-01 18:23:26-05:00 America/New_York [!!! INCOMPATIBLE CHANGES !!!] - (This warning repeated from 0.079-TRIAL) The relative() method no longer uses File::Spec's buggy abs2rel method. The new Path::Tiny algorithm should be comparable and passes File::Spec abs2rel test cases, except that it correctly accounts for symlinks. For common use, you are not likely to notice any difference. For uncommon use, this should be an improvement. As a side benefit, this change drops the minimum File::Spec version required, allowing Path::Tiny to be fatpacked if desired. [Changes] - no other changes from 0.081 0.081 2016-02-18 16:55:37-05:00 America/New_York (TRIAL RELEASE) [Fixed] - Fixed lines_utf8+chomp and relative() bugs on Windows 0.079 2016-02-15 20:52:10-07:00 America/Mazatlan (TRIAL RELEASE) [!!! INCOMPATIBLE CHANGES !!!] - The relative() method no longer uses File::Spec's buggy rel2bs method. The new Path::Tiny algorithm should be comparable and passes File::Spec abs2rel test cases, except that it correctly accounts for symlinks. For common use, you are not likely to notice any difference. For uncommon use, this should be an improvement. As a side benefit, this change drops the minimum File::Spec version required, allowing Path::Tiny to be fatpacked if desired. [FIXED] - Fixed lines_utf8() with chomping for repeated empty lines. [DOCS] - Documented that subclassing is not supported 0.077 2016-02-10 14:17:32-07:00 America/Mazatlan (TRIAL RELEASE) [ADDED] - Added 'edit' and 'edit_lines' plus _utf8 and _raw variants; this is similar to perl's -i flag (though without backups) 0.076 2015-11-16 10:47:24-05:00 America/New_York - no changes from 0.075 0.075 2015-11-15 21:02:18-05:00 America/New_York (TRIAL RELEASE) [FIXED] - Tilde expansion on Windows was resulting in backslashes. Now they are correctly normalized to forward slashes. [DOCS] - Typos fixed 0.073 2015-10-30 10:36:18-04:00 America/New_York (TRIAL RELEASE) [FIXED] - Fixed spewing to a symlink that crosses a filesystem boundary [PREREQS] - Add Test::MockRandom to META as an recommended test prerequisite. 0.072 2015-07-20 16:07:20-04:00 America/New_York - No changes from 0.071 0.071 2015-07-17 13:40:08-04:00 America/New_York (TRIAL RELEASE) [FIXED] - Fixed incorrect error argument for File::Path functions (mkpath and remove_tree) 0.070 2015-06-28 13:50:16-04:00 America/New_York - No changes from 0.069 0.069 2015-06-18 18:09:44-04:00 America/New_York (TRIAL RELEASE) [CHANGED] - The 'copy' method now returns the object for the copied file [FIXED] - The 'visit' method only dereferences the callback return value for scalar refs, avoiding some common bugs 0.068 2015-03-23 20:42:56-04:00 America/New_York [META] - Jumping to 0.068 to get to an even-version for a stable release [DOCUMENTED] - Noted that 0.66 changed the 'filehandle' method 0.066 2015-03-20 23:59:08-04:00 America/New_York (TRIAL RELEASE) [ADDED] - Added exclusive locking option to filehandle opens; spew now exclusively locks tempfile used for atomic writes 0.065 2015-03-06 05:59:56-05:00 America/New_York [ADDED] - Added 'assert' method - Added 'visit' method - Added support for a negative count for 'lines' to get the last lines of a file [FIXED] - Fixed tilde expansion if path has spaces - Make realpath non-fatal if the parent path exists and only the final path component does not. (Was fatal on Windows and some Unixes.) - Removed rendundant locking on tempfile use for spewing - Work around File::Temp bugs on older ActiveState Windows Perls https://bugs.activestate.com/show_bug.cgi?id=104767 [DOCUMENTED] - Fixed SYNOPSIS example 0.064 2015-03-05 03:58:42-05:00 America/New_York (TRIAL RELEASE) 0.063 2015-03-04 16:00:17-05:00 America/New_York (TRIAL RELEASE) 0.062 2015-03-04 13:59:31-05:00 America/New_York (TRIAL RELEASE) 0.061 2014-11-13 16:50:05-05:00 America/New_York [FIXED] - Fixed append_utf8 and append_raw with 'truncate' option. 0.060 2014-11-04 17:33:39-05:00 America/New_York [ADDED] - Added 'truncate' option to append for in-place replacement of file contents. 0.059 2014-10-14 12:45:46-04:00 America/New_York [FIXED] - Fixed precedence bug in the check for Unicode::UTF8 0.058 2014-09-23 11:00:24-04:00 America/New_York [ADDED] - Added a 'sibling' method as a more efficient form of calling $path->parent->child(...). [DOCUMENTED] - Every method annotated with the version number of the last API change. 0.057 2014-09-19 11:23:05-04:00 America/New_York [FIXED] - On AIX, reads that default to locking would fail without write permissions, because locking needs write permissions. The fix is only to lock reads if write permissions exist; otherwise locking is skipped. 0.056 2014-08-07 15:08:41-04:00 America/New_York [*** DEPRECATIONS ***] - The 'dirname' method is deprecated due to exposing File::Spec inconsistencies [ADDED] - The 'digest' method now takes a 'chunk_size' option to avoid slurping files entirely into memory. [FIXED] - Fixed problem throwing errors from 'remove' 0.055 2014-06-30 10:29:28-04:00 America/New_York [FIXED] - tempfile/tempdir won't warn if used as functions without arguments 0.054 2014-05-04 13:56:11-04:00 America/New_York [ADDED] - The 'basename' method now takes a list of suffixes to remove before returning the name - FREEZE/THAW/TO_JSON serialization helpers [CHANGED] - When constructing a Path::Tiny object from another, the original is returned unless it's a temp dir/file. This significantly speeds up calling path($path) if $path is already a Path::Tiny object. (Thanks to Michael Schwern for prompting such benchmarking.) [FIXED] - Constructing any path -- e.g. with child() -- with undef or zero-length parts throws an error instead of constructing an invalid path 0.053 2014-03-24 09:25:51-04:00 America/New_York (TRIAL RELEASE) [INCOMPATIBLE CHANGES] - The 'is_file' method now does -e && ! -d and not -f because -f is often more restrictive than people intend or expect. [ADDED] - Added 'chmod' method with symbolic chmod support ("a=r,u+rx") 0.052 2014-01-14 15:58:03-05:00 America/New_York [FIXED] - Backslash-to-slash conversion now only happens on Windows (since backslash is legal on Unix, we must allow it) 0.051 2013-12-20 07:34:14 America/New_York [FIXED] - Fixed file order bug in the new test file 0.050 2013-12-20 07:27:20 America/New_York [FIXED] - Recursive iteration won't throw an exception if a directory is removed or unreadable during iteration. 0.049 2013-12-12 00:48:01 America/New_York [FIXED] - Generates filename for atomic writes independent of thread-ID. Fixes crashing bug on Win32 when fork() is called. 0.048 2013-12-11 21:56:23 America/New_York [ADDED] - Added 'subsumes' method [CHANGED] - The 'chomp' option for 'lines' will remove any end-of-line sequences fully instead of just chomping the last character - The 'flock' package will no longer indexed by PAUSE [FIXED] - Hides warnings and fixes possible fatal errors from pure-perl Cwd, particularly on MSWin32 0.047 2013-11-26 15:11:13 America/New_York [FIXED] - Previous lock testing fixes broke on Windows (sigh); now fixed, I hope. 0.046 2013-11-22 17:07:24 America/New_York [FIXED] - Revised locking tests for portability again: locks are now tested from a separate process 0.045 2013-11-22 15:28:50 America/New_York [FIXED] - Fixed locking test on AIX 0.044 2013-10-17 17:00:41 America/New_York [FIXED] - Fixed child path construction against the root path. - Fixed path construction when a relative volume is provided as the first argument on Windows; e.g. path("C:", "lib") must be like path("C:lib"), not path("C:/lib"). - On AIX, shared locking is replaced by exclusive locking on a R/W filehandle, as locking read handles is not supported 0.043 2013-10-14 06:24:06 America/New_York [CHANGED] - Calling 'absolute' on Windows will add the volume if it is missing (E.g. "/foo" will become "C:/foo"). This matches the behavior of File::Spec->rel2abs. [FIXED] - Fixed t/00-report-prereqs.t for use with older versions of CPAN::Meta::Requirements 0.042 2013-10-13 11:02:02 America/New_York [FIXED] - When 'realpath' can't be resolved (because intermediate directories don't exist), the exception now explains the error clearly instead of complaining about path() needing a defined, positive-length argument. - On Windows, fixed resolution of relative paths with a volume. E.g. "C:foo" is now correctly translated into getdcwd on "C:" plus "foo". 0.041 2013-10-11 08:56:31 America/New_York [FIXES] - Removes duplicate test dependency on File::Spec that triggers a CPAN.pm bug 0.040 2013-10-08 22:01:50 America/New_York [FIXES] - Fixed broken locking test on *bsd - When using 'filehandle' to request a locked handle that truncates an existing file and has a binmode starting with ":unix", this fixes a bug where pseudo-layers weren't being cleared properly. 0.039 2013-10-08 16:39:23 America/New_York [ADDITIONS] - The 'filehandle' method now offers an option to return locked handles based on the file mode. Input-output methods now rely on this feature internally. Truncating file modes defer truncation until after an exclusive lock is acquired. [FIXES] - The 'filehandle' method now respects default encoding set by the caller's open pragma. 0.038 2013-10-01 18:20:05 America/New_York [ADDITIONS] - Added 'is_rootdir' method to simplify testing if a path is the root directory 0.037 2013-09-25 13:00:25 America/New_York [FIXES] - Fixed for v5.8 0.036 2013-09-25 09:34:28 America/New_York [PREREQS] - No longer lists 'threads' as a prerequisite. If you have a threaded perl, you have it and if you're not, Path::Tiny doesn't care. 0.035 2013-09-24 07:21:55 America/New_York [FIXED] - Fixed flock warning on BSD that was broken with the autodie removal; now also applies to all BSD flavors 0.034 2013-09-23 16:16:36 America/New_York [INCOMPATIBLE CHANGE] - Exceptions are now Path::Tiny::Error objects, not autodie exceptions; this removes the last dependency on autodie, which allows us to support Perls as far back as v5.8.1 [FIXED] - BSD/NFS flock fix was not backwards compatible before v5.14. This fixes it harder. [PREREQS] - dropped autodie - lowered ExtUtils::MakeMaker configure_requires version to 6.17 0.033 2013-09-12 08:54:30 America/New_York [FIXED] - Perl on BSD may not support locking on an NFS filesystem. If this is detected, Path::Tiny warns and continues in an unsafe mode. The 'flock' warning category may be fatalized to die instead. [DOCUMENTED] - Added 'iterator' example showing defaults 0.032 2013-09-06 17:52:48 America/New_York [PREREQS] - Removed several test dependencies. Path::Tiny now only needs core modules, though some must be upgraded on old Perls 0.031 2013-08-27 10:03:57 America/New_York [FIXED] - parent() on paths with internal double dots (e.g. /foo..bar.txt) now works correctly 0.030 2013-08-20 16:10:04 America/New_York [FIXED] - t/zzz-spec.t used getcwd() instead of getdcwd(), which breaks on Windows if the build directory isn't on the 'C' drive 0.029 2013-08-19 11:52:24 America/New_York [FIXED] - On Win32, "C:/" no longer is changed to "C:". Also, "C:" is converted to the absolute path of cwd on the "C:" volume. UNC paths ("//server/share/") now retain their trailing slash to correctly distinguish volume and directory paths when split 0.028 2013-08-14 13:12:49 America/New_York [ADDED] - The 'children()' method now takes an optional regular expression to filter the results 0.027 2013-07-25 19:38:44 America/New_York [ADDED] - Added the 'digest' method to produce a hexadecimal SHA-256 (or user-specified) digest of a file 0.026 2013-07-14 21:25:22 America/New_York [FIXED] - Fixed bug where lines() with a count longer than the file would return undef for the extra lines. Now returns only the lines in the file if the count is greater than the number of lines. 0.025 2013-07-10 09:32:13 America/New_York [FIXED] - Spew to an existing symlink now atomically replaces the resolved destination, not the symlink 0.024 2013-06-17 18:12:36 America/New_York [FIXED] - Win32 pseudo-forks don't load threads.pm, so we do that in CLONE to ensure we get the thread ID 0.023 2013-06-12 07:18:31 America/New_York [FIXED] - Removing dangling symlinks now works 0.022 2013-05-28 11:57:15 America/New_York [ADDED] - The 'touch' method can now take an epoch secs argument 0.021 2013-05-17 22:53:18 America/New_York [FIXED] - Fixed fatal bug with lines_utf8 using chomp [DOCS] - Pod typos fixed 0.020 2013-04-13 06:58:11 Europe/London [FIXED] - More descriptive error message if copy() fails 0.019 2013-04-12 06:58:18 Europe/London [FIXED] - Fixed warning about -l on dirhandle in iterator() 0.018 2013-04-08 12:44:31 America/New_York [ADDED] - cwd, rootdir, tempfile and tempdir can now be exported on request and used as functions instead of as methods [FIXED] - Fixed regression in lines() where it no longer returned count of lines in scalar context 0.017 2013-03-28 16:49:15 America/New_York [ADDED] - path() constructor now glob-expands tildes (~) [CHANGED] - Improved options validation; invalid options now throw errors 0.016 2013-03-26 14:59:36 America/New_York [ADDED] - The iterator now has an optional recursive mode [CHANGED] - We no longer use autodie directly, but we throw our own autodie::exceptions on error. This avoids the overhead of wrapping built-ins with function calls. - Most dependencies are now loaded on demand, reducing startup time. 0.015 2013-03-13 13:20:38 America/New_York [CHANGED] - touch and touchpath now return the object to allow easy chaining with spew 0.014 2013-03-09 08:54:26 America/New_York [ADDED] - parent now takes an optional argument to look upwards multiple times in one call. e.g. $path->parent(2) 0.013 2013-02-22 10:58:05 America/New_York [CHANGED] - remove_tree now defaults to safe mode and will not attempt to chmod and remove directories with insufficient permissions - Temporary files and directories are always created with an absolute path. [FIXED] - Failures from autodie are reported from our caller's location (as if we called croak()); bumped autodie prereq to 2.14 for this feature - Failures from mkpath and remove_tree are now trapped and thrown as exceptions. (Making an existing path or removing a non-existant path return false and are not errors); 0.012 2013-02-20 09:34:50 America/New_York [REMOVED] - The 'remove' function no longer works on directories. The new 'remove_tree' method should be used instead. [CHANGED] - path() now requires a defined, positive-length argument to keep you safe from subtle bugs in your code that pass an undef or empty argument to path suddenly having you operating in the current directory. [ADDED] - Added Path::Tiny->cwd as a constructor to give an absolute path to the current working directory - Added 'remove_tree' as a method for recursively removing a directory 0.011 2013-02-19 11:08:44 America/New_York [CHANGED] - slurp/spew/etc and openr/openw/etc now repect default layers set by -C or the open pragma - spew and append can now be given array references to output to avoid extra copying 0.010 2013-02-16 10:26:38 America/New_York [FIXED] - The 'tempdir' and 'tempfile' methods can now both take either leading templates or a TEMPLATE option, so you don't have to remember which one File::Temp wants 0.009 2013-02-15 16:05:39 America/New_York [CHANGED] - Dropped use of '//' to allow Path::Tiny to run on Perl 5.008 0.008 2013-02-15 13:49:54 America/New_York [ADDED] - Added 'touchpath' method combining 'mkpath' and 'touch' 0.007 2013-02-12 17:41:44 America/New_York [FIXED] - Unicode::UTF8 0.58 is necessary for optional faster Unicode processing 0.006 2013-02-11 13:22:18 America/New_York [FIXED] - t/parent.t is amended to work on Windows - new() now correctly takes multiple path arguments, like path() 0.005 2013-02-07 15:41:32 America/New_York [FIXED] - Fixed test for platforms with /sbin symlinked to /usr/sbin 0.004 2013-02-05 19:19:46 America/New_York [ADDED] - Added slurp_raw and other *_raw helper methods - Added realpath method (with thanks to ether) - Added canonpath method (with thanks to sjmiller) [FIXED] - slurp/lines/spew/append now do appropriate flocking - Fixed test that fails if run as root (bingos) - Fixed test that fails if cwd/getcwd don't agree [CHANGED] - internal optimizations 0.003 2013-01-31 06:59:50 America/New_York [FIXED] - lstat was calling the wrong stat [rt.cpan.org #83063] - make atomic writes thread-safe [rt.cpan.org #83064] [CHANGED] - updated bugtracker to point to github 0.002 2013-01-30 22:09:37 America/New_York [FIXED] - s/File::Stat/File::stat/; # OMG! I hate case insensitivity 0.001 2013-01-30 19:36:22 America/New_York - First release cpanfile 0000644 00000004716 15125124546 0006265 0 ustar 00 # This file is generated by Dist::Zilla::Plugin::CPANFile v6.031 # Do not edit this file directly. To change prereqs, edit the `dist.ini` file. requires "Carp" => "0"; requires "Cwd" => "0"; requires "Digest" => "1.03"; requires "Digest::SHA" => "5.45"; requires "Encode" => "0"; requires "Exporter" => "5.57"; requires "Fcntl" => "0"; requires "File::Compare" => "0"; requires "File::Copy" => "0"; requires "File::Glob" => "0"; requires "File::Path" => "2.07"; requires "File::Spec" => "0.86"; requires "File::Temp" => "0.19"; requires "File::stat" => "0"; requires "constant" => "0"; requires "overload" => "0"; requires "perl" => "5.008001"; requires "strict" => "0"; requires "warnings" => "0"; requires "warnings::register" => "0"; recommends "Unicode::UTF8" => "0.58"; on 'test' => sub { requires "Digest::MD5" => "0"; requires "ExtUtils::MakeMaker" => "0"; requires "File::Basename" => "0"; requires "File::Spec" => "0.86"; requires "File::Spec::Functions" => "0"; requires "File::Spec::Unix" => "0"; requires "File::Temp" => "0.19"; requires "Test::More" => "0.96"; requires "lib" => "0"; requires "open" => "0"; requires "perl" => "5.008001"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; recommends "Test::FailWarnings" => "0"; recommends "Test::MockRandom" => "0"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; requires "perl" => "5.008001"; }; on 'configure' => sub { suggests "JSON::PP" => "2.27300"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::Plugin::MinimumPerl" => "0"; requires "Dist::Zilla::Plugin::OnlyCorePrereqs" => "0"; requires "Dist::Zilla::Plugin::Prereqs" => "0"; requires "Dist::Zilla::Plugin::ReleaseStatus::FromVersion" => "0"; requires "Dist::Zilla::Plugin::RemovePrereqs" => "0"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.072"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Pod::Wordlist" => "0"; requires "Software::License::Apache_2_0" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::MinimumVersion" => "0"; requires "Test::More" => "0"; requires "Test::Perl::Critic" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; requires "Test::Portability::Files" => "0"; requires "Test::Spelling" => "0.12"; requires "Test::Version" => "1"; }; tidyall.ini 0000644 00000000240 15125124546 0006710 0 ustar 00 ; Install Code::TidyAll ; run "tidyall -a" to tidy all files ; run "tidyall -g" to tidy only files modified from git [PerlTidy] select = {lib,t}/**/*.{pl,pm,t} Makefile 0000644 00000103633 15125124546 0006217 0 ustar 00 # This Makefile is for the Path::Tiny extension to perl. # # It was generated automatically by MakeMaker version # 7.60 (Revision: 76000) from the contents of # Makefile.PL. Don't edit this file, edit Makefile.PL instead. # # ANY CHANGES MADE HERE WILL BE LOST! # # MakeMaker ARGV: () # # MakeMaker Parameters: # ABSTRACT => q[File path utility] # AUTHOR => [q[David Golden <dagolden@cpan.org>]] # BUILD_REQUIRES => { } # CONFIGURE_REQUIRES => { ExtUtils::MakeMaker=>q[6.17] } # DISTNAME => q[Path-Tiny] # LICENSE => q[apache] # MIN_PERL_VERSION => q[5.008001] # NAME => q[Path::Tiny] # PREREQ_PM => { Carp=>q[0], Cwd=>q[0], Digest=>q[1.03], Digest::MD5=>q[0], Digest::SHA=>q[5.45], Encode=>q[0], Exporter=>q[5.57], ExtUtils::MakeMaker=>q[0], Fcntl=>q[0], File::Basename=>q[0], File::Compare=>q[0], File::Copy=>q[0], File::Glob=>q[0], File::Path=>q[2.07], File::Spec=>q[0.86], File::Spec::Functions=>q[0], File::Spec::Unix=>q[0], File::Temp=>q[0.19], File::stat=>q[0], Test::More=>q[0.96], constant=>q[0], lib=>q[0], open=>q[0], overload=>q[0], strict=>q[0], warnings=>q[0], warnings::register=>q[0] } # TEST_REQUIRES => { Digest::MD5=>q[0], ExtUtils::MakeMaker=>q[0], File::Basename=>q[0], File::Spec=>q[0.86], File::Spec::Functions=>q[0], File::Spec::Unix=>q[0], File::Temp=>q[0.19], Test::More=>q[0.96], lib=>q[0], open=>q[0] } # VERSION => q[0.146] # test => { TESTS=>q[t/*.t] } # --- MakeMaker post_initialize section: # --- MakeMaker const_config section: # These definitions are from config.sh (via /usr/lib64/perl5/Config.pm). # They may have been overridden via Makefile.PL or on the command line. AR = ar CC = gcc CCCDLFLAGS = -fPIC CCDLFLAGS = -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 DLEXT = so DLSRC = dl_dlopen.xs EXE_EXT = FULL_AR = /usr/bin/ar LD = gcc LDDLFLAGS = -lpthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -L/usr/local/lib -fstack-protector-strong LDFLAGS = -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fstack-protector-strong -L/usr/local/lib LIBC = /lib/../lib64/libc.so.6 LIB_EXT = .a OBJ_EXT = .o OSNAME = linux OSVERS = 4.18.0-513.18.1.el8_9.x86_64 RANLIB = : SITELIBEXP = /usr/local/share/perl5/5.32 SITEARCHEXP = /usr/local/lib64/perl5/5.32 SO = so VENDORARCHEXP = /usr/lib64/perl5/vendor_perl VENDORLIBEXP = /usr/share/perl5/vendor_perl # --- MakeMaker constants section: AR_STATIC_ARGS = cr DIRFILESEP = / DFSEP = $(DIRFILESEP) NAME = Path::Tiny NAME_SYM = Path_Tiny VERSION = 0.146 VERSION_MACRO = VERSION VERSION_SYM = 0_146 DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\" XS_VERSION = 0.146 XS_VERSION_MACRO = XS_VERSION XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\" INST_ARCHLIB = blib/arch INST_SCRIPT = blib/script INST_BIN = blib/bin INST_LIB = blib/lib INST_MAN1DIR = blib/man1 INST_MAN3DIR = blib/man3 MAN1EXT = 1 MAN3EXT = 3pm MAN1SECTION = 1 MAN3SECTION = 3 INSTALLDIRS = site DESTDIR = PREFIX = $(SITEPREFIX) PERLPREFIX = /usr SITEPREFIX = /usr/local VENDORPREFIX = /usr INSTALLPRIVLIB = /usr/share/perl5 DESTINSTALLPRIVLIB = $(DESTDIR)$(INSTALLPRIVLIB) INSTALLSITELIB = /usr/local/share/perl5/5.32 DESTINSTALLSITELIB = $(DESTDIR)$(INSTALLSITELIB) INSTALLVENDORLIB = /usr/share/perl5/vendor_perl DESTINSTALLVENDORLIB = $(DESTDIR)$(INSTALLVENDORLIB) INSTALLARCHLIB = /usr/lib64/perl5 DESTINSTALLARCHLIB = $(DESTDIR)$(INSTALLARCHLIB) INSTALLSITEARCH = /usr/local/lib64/perl5/5.32 DESTINSTALLSITEARCH = $(DESTDIR)$(INSTALLSITEARCH) INSTALLVENDORARCH = /usr/lib64/perl5/vendor_perl DESTINSTALLVENDORARCH = $(DESTDIR)$(INSTALLVENDORARCH) INSTALLBIN = /usr/bin DESTINSTALLBIN = $(DESTDIR)$(INSTALLBIN) INSTALLSITEBIN = /usr/local/bin DESTINSTALLSITEBIN = $(DESTDIR)$(INSTALLSITEBIN) INSTALLVENDORBIN = /usr/bin DESTINSTALLVENDORBIN = $(DESTDIR)$(INSTALLVENDORBIN) INSTALLSCRIPT = /usr/bin DESTINSTALLSCRIPT = $(DESTDIR)$(INSTALLSCRIPT) INSTALLSITESCRIPT = /usr/local/bin DESTINSTALLSITESCRIPT = $(DESTDIR)$(INSTALLSITESCRIPT) INSTALLVENDORSCRIPT = /usr/bin DESTINSTALLVENDORSCRIPT = $(DESTDIR)$(INSTALLVENDORSCRIPT) INSTALLMAN1DIR = /usr/share/man/man1 DESTINSTALLMAN1DIR = $(DESTDIR)$(INSTALLMAN1DIR) INSTALLSITEMAN1DIR = /usr/local/share/man/man1 DESTINSTALLSITEMAN1DIR = $(DESTDIR)$(INSTALLSITEMAN1DIR) INSTALLVENDORMAN1DIR = /usr/share/man/man1 DESTINSTALLVENDORMAN1DIR = $(DESTDIR)$(INSTALLVENDORMAN1DIR) INSTALLMAN3DIR = /usr/share/man/man3 DESTINSTALLMAN3DIR = $(DESTDIR)$(INSTALLMAN3DIR) INSTALLSITEMAN3DIR = /usr/local/share/man/man3 DESTINSTALLSITEMAN3DIR = $(DESTDIR)$(INSTALLSITEMAN3DIR) INSTALLVENDORMAN3DIR = /usr/share/man/man3 DESTINSTALLVENDORMAN3DIR = $(DESTDIR)$(INSTALLVENDORMAN3DIR) PERL_LIB = /usr/share/perl5 PERL_ARCHLIB = /usr/lib64/perl5 PERL_ARCHLIBDEP = /usr/lib64/perl5 LIBPERL_A = libperl.a FIRST_MAKEFILE = Makefile MAKEFILE_OLD = Makefile.old MAKE_APERL_FILE = Makefile.aperl PERLMAINCC = $(CC) PERL_INC = /usr/lib64/perl5/CORE PERL_INCDEP = /usr/lib64/perl5/CORE PERL = "/usr/bin/perl" FULLPERL = "/usr/bin/perl" ABSPERL = $(PERL) PERLRUN = $(PERL) FULLPERLRUN = $(FULLPERL) ABSPERLRUN = $(ABSPERL) PERLRUNINST = $(PERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" FULLPERLRUNINST = $(FULLPERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" ABSPERLRUNINST = $(ABSPERLRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" PERL_CORE = 0 PERM_DIR = 755 PERM_RW = 644 PERM_RWX = 755 MAKEMAKER = /usr/share/perl5/vendor_perl/ExtUtils/MakeMaker.pm MM_VERSION = 7.60 MM_REVISION = 76000 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle). # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle) # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar) # DLBASE = Basename part of dynamic library. May be just equal BASEEXT. MAKE = make FULLEXT = Path/Tiny BASEEXT = Tiny PARENT_NAME = Path DLBASE = $(BASEEXT) VERSION_FROM = OBJECT = LDFROM = $(OBJECT) LINKTYPE = dynamic BOOTDEP = # Handy lists of source code files: XS_FILES = C_FILES = O_FILES = H_FILES = MAN1PODS = MAN3PODS = lib/Path/Tiny.pm # Where is the Config information that we are using/depend on CONFIGDEP = $(PERL_ARCHLIBDEP)$(DFSEP)Config.pm $(PERL_INCDEP)$(DFSEP)config.h # Where to build things INST_LIBDIR = $(INST_LIB)/Path INST_ARCHLIBDIR = $(INST_ARCHLIB)/Path INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT) INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT) INST_STATIC = INST_DYNAMIC = INST_BOOT = # Extra linker info EXPORT_LIST = PERL_ARCHIVE = PERL_ARCHIVEDEP = PERL_ARCHIVE_AFTER = TO_INST_PM = lib/Path/Tiny.pm # --- MakeMaker platform_constants section: MM_Unix_VERSION = 7.60 PERL_MALLOC_DEF = -DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc -Dfree=Perl_mfree -Drealloc=Perl_realloc -Dcalloc=Perl_calloc # --- MakeMaker tool_autosplit section: # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto AUTOSPLITFILE = $(ABSPERLRUN) -e 'use AutoSplit; autosplit($$$$ARGV[0], $$$$ARGV[1], 0, 1, 1)' -- # --- MakeMaker tool_xsubpp section: # --- MakeMaker tools_other section: SHELL = /bin/sh CHMOD = chmod CP = cp MV = mv NOOP = $(TRUE) NOECHO = @ RM_F = rm -f RM_RF = rm -rf TEST_F = test -f TOUCH = touch UMASK_NULL = umask 0 DEV_NULL = > /dev/null 2>&1 MKPATH = $(ABSPERLRUN) -MExtUtils::Command -e 'mkpath' -- EQUALIZE_TIMESTAMP = $(ABSPERLRUN) -MExtUtils::Command -e 'eqtime' -- FALSE = false TRUE = true ECHO = echo ECHO_N = echo -n UNINST = 0 VERBINST = 0 MOD_INSTALL = $(ABSPERLRUN) -MExtUtils::Install -e 'install([ from_to => {@ARGV}, verbose => '\''$(VERBINST)'\'', uninstall_shadows => '\''$(UNINST)'\'', dir_mode => '\''$(PERM_DIR)'\'' ]);' -- DOC_INSTALL = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'perllocal_install' -- UNINSTALL = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'uninstall' -- WARN_IF_OLD_PACKLIST = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'warn_if_old_packlist' -- MACROSTART = MACROEND = USEMAKEFILE = -f FIXIN = $(ABSPERLRUN) -MExtUtils::MY -e 'MY->fixin(shift)' -- CP_NONEMPTY = $(ABSPERLRUN) -MExtUtils::Command::MM -e 'cp_nonempty' -- # --- MakeMaker makemakerdflt section: makemakerdflt : all $(NOECHO) $(NOOP) # --- MakeMaker dist section: TAR = tar TARFLAGS = cvf ZIP = zip ZIPFLAGS = -r COMPRESS = gzip --best SUFFIX = .gz SHAR = shar PREOP = $(NOECHO) $(NOOP) POSTOP = $(NOECHO) $(NOOP) TO_UNIX = $(NOECHO) $(NOOP) CI = ci -u RCS_LABEL = rcs -Nv$(VERSION_SYM): -q DIST_CP = best DIST_DEFAULT = tardist DISTNAME = Path-Tiny DISTVNAME = Path-Tiny-0.146 # --- MakeMaker macro section: # --- MakeMaker depend section: # --- MakeMaker cflags section: # --- MakeMaker const_loadlibs section: # --- MakeMaker const_cccmd section: # --- MakeMaker post_constants section: # --- MakeMaker pasthru section: PASTHRU = LIBPERL_A="$(LIBPERL_A)"\ LINKTYPE="$(LINKTYPE)"\ PREFIX="$(PREFIX)"\ PASTHRU_DEFINE='$(DEFINE) $(PASTHRU_DEFINE)'\ PASTHRU_INC='$(INC) $(PASTHRU_INC)' # --- MakeMaker special_targets section: .SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT) .PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static # --- MakeMaker c_o section: # --- MakeMaker xs_c section: # --- MakeMaker xs_o section: # --- MakeMaker top_targets section: all :: pure_all manifypods $(NOECHO) $(NOOP) pure_all :: config pm_to_blib subdirs linkext $(NOECHO) $(NOOP) subdirs :: $(MYEXTLIB) $(NOECHO) $(NOOP) config :: $(FIRST_MAKEFILE) blibdirs $(NOECHO) $(NOOP) help : perldoc ExtUtils::MakeMaker # --- MakeMaker blibdirs section: blibdirs : $(INST_LIBDIR)$(DFSEP).exists $(INST_ARCHLIB)$(DFSEP).exists $(INST_AUTODIR)$(DFSEP).exists $(INST_ARCHAUTODIR)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists $(INST_SCRIPT)$(DFSEP).exists $(INST_MAN1DIR)$(DFSEP).exists $(INST_MAN3DIR)$(DFSEP).exists $(NOECHO) $(NOOP) # Backwards compat with 6.18 through 6.25 blibdirs.ts : blibdirs $(NOECHO) $(NOOP) $(INST_LIBDIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_LIBDIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_LIBDIR) $(NOECHO) $(TOUCH) $(INST_LIBDIR)$(DFSEP).exists $(INST_ARCHLIB)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_ARCHLIB) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_ARCHLIB) $(NOECHO) $(TOUCH) $(INST_ARCHLIB)$(DFSEP).exists $(INST_AUTODIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_AUTODIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_AUTODIR) $(NOECHO) $(TOUCH) $(INST_AUTODIR)$(DFSEP).exists $(INST_ARCHAUTODIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_ARCHAUTODIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_ARCHAUTODIR) $(NOECHO) $(TOUCH) $(INST_ARCHAUTODIR)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_BIN) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_BIN) $(NOECHO) $(TOUCH) $(INST_BIN)$(DFSEP).exists $(INST_SCRIPT)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_SCRIPT) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_SCRIPT) $(NOECHO) $(TOUCH) $(INST_SCRIPT)$(DFSEP).exists $(INST_MAN1DIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_MAN1DIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_MAN1DIR) $(NOECHO) $(TOUCH) $(INST_MAN1DIR)$(DFSEP).exists $(INST_MAN3DIR)$(DFSEP).exists :: Makefile.PL $(NOECHO) $(MKPATH) $(INST_MAN3DIR) $(NOECHO) $(CHMOD) $(PERM_DIR) $(INST_MAN3DIR) $(NOECHO) $(TOUCH) $(INST_MAN3DIR)$(DFSEP).exists # --- MakeMaker linkext section: linkext :: dynamic $(NOECHO) $(NOOP) # --- MakeMaker dlsyms section: # --- MakeMaker dynamic_bs section: BOOTSTRAP = # --- MakeMaker dynamic section: dynamic :: $(FIRST_MAKEFILE) config $(INST_BOOT) $(INST_DYNAMIC) $(NOECHO) $(NOOP) # --- MakeMaker dynamic_lib section: # --- MakeMaker static section: ## $(INST_PM) has been moved to the all: target. ## It remains here for awhile to allow for old usage: "make static" static :: $(FIRST_MAKEFILE) $(INST_STATIC) $(NOECHO) $(NOOP) # --- MakeMaker static_lib section: # --- MakeMaker manifypods section: POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--" POD2MAN = $(POD2MAN_EXE) manifypods : pure_all config \ lib/Path/Tiny.pm $(NOECHO) $(POD2MAN) --section=$(MAN3SECTION) --perm_rw=$(PERM_RW) -u \ lib/Path/Tiny.pm $(INST_MAN3DIR)/Path::Tiny.$(MAN3EXT) # --- MakeMaker processPL section: # --- MakeMaker installbin section: # --- MakeMaker subdirs section: # none # --- MakeMaker clean_subdirs section: clean_subdirs : $(NOECHO) $(NOOP) # --- MakeMaker clean section: # Delete temporary files but do not touch installed files. We don't delete # the Makefile here so a later make realclean still has a makefile to use. clean :: clean_subdirs - $(RM_F) \ $(BASEEXT).bso $(BASEEXT).def \ $(BASEEXT).exp $(BASEEXT).x \ $(BOOTSTRAP) $(INST_ARCHAUTODIR)/extralibs.all \ $(INST_ARCHAUTODIR)/extralibs.ld $(MAKE_APERL_FILE) \ *$(LIB_EXT) *$(OBJ_EXT) \ *perl.core MYMETA.json \ MYMETA.yml blibdirs.ts \ core core.*perl.*.? \ core.[0-9] core.[0-9][0-9] \ core.[0-9][0-9][0-9] core.[0-9][0-9][0-9][0-9] \ core.[0-9][0-9][0-9][0-9][0-9] lib$(BASEEXT).def \ mon.out perl \ perl$(EXE_EXT) perl.exe \ perlmain.c pm_to_blib \ pm_to_blib.ts so_locations \ tmon.out - $(RM_RF) \ blib $(NOECHO) $(RM_F) $(MAKEFILE_OLD) - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL) # --- MakeMaker realclean_subdirs section: # so clean is forced to complete before realclean_subdirs runs realclean_subdirs : clean $(NOECHO) $(NOOP) # --- MakeMaker realclean section: # Delete temporary files (via clean) and also delete dist files realclean purge :: realclean_subdirs - $(RM_F) \ $(FIRST_MAKEFILE) $(MAKEFILE_OLD) - $(RM_RF) \ $(DISTVNAME) # --- MakeMaker metafile section: metafile : create_distdir $(NOECHO) $(ECHO) Generating META.yml $(NOECHO) $(ECHO) '---' > META_new.yml $(NOECHO) $(ECHO) 'abstract: '\''File path utility'\''' >> META_new.yml $(NOECHO) $(ECHO) 'author:' >> META_new.yml $(NOECHO) $(ECHO) ' - '\''David Golden <dagolden@cpan.org>'\''' >> META_new.yml $(NOECHO) $(ECHO) 'build_requires:' >> META_new.yml $(NOECHO) $(ECHO) ' Digest::MD5: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' ExtUtils::MakeMaker: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Basename: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Spec: '\''0.86'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Spec::Functions: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Spec::Unix: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Temp: '\''0.19'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Test::More: '\''0.96'\''' >> META_new.yml $(NOECHO) $(ECHO) ' lib: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' open: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) 'configure_requires:' >> META_new.yml $(NOECHO) $(ECHO) ' ExtUtils::MakeMaker: '\''6.17'\''' >> META_new.yml $(NOECHO) $(ECHO) 'dynamic_config: 1' >> META_new.yml $(NOECHO) $(ECHO) 'generated_by: '\''ExtUtils::MakeMaker version 7.60, CPAN::Meta::Converter version 2.150010'\''' >> META_new.yml $(NOECHO) $(ECHO) 'license: apache' >> META_new.yml $(NOECHO) $(ECHO) 'meta-spec:' >> META_new.yml $(NOECHO) $(ECHO) ' url: http://module-build.sourceforge.net/META-spec-v1.4.html' >> META_new.yml $(NOECHO) $(ECHO) ' version: '\''1.4'\''' >> META_new.yml $(NOECHO) $(ECHO) 'name: Path-Tiny' >> META_new.yml $(NOECHO) $(ECHO) 'no_index:' >> META_new.yml $(NOECHO) $(ECHO) ' directory:' >> META_new.yml $(NOECHO) $(ECHO) ' - t' >> META_new.yml $(NOECHO) $(ECHO) ' - inc' >> META_new.yml $(NOECHO) $(ECHO) 'requires:' >> META_new.yml $(NOECHO) $(ECHO) ' Carp: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Cwd: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Digest: '\''1.03'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Digest::SHA: '\''5.45'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Encode: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Exporter: '\''5.57'\''' >> META_new.yml $(NOECHO) $(ECHO) ' Fcntl: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Compare: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Copy: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Glob: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Path: '\''2.07'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Spec: '\''0.86'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::Temp: '\''0.19'\''' >> META_new.yml $(NOECHO) $(ECHO) ' File::stat: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' constant: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' overload: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' perl: '\''5.008001'\''' >> META_new.yml $(NOECHO) $(ECHO) ' strict: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' warnings: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) ' warnings::register: '\''0'\''' >> META_new.yml $(NOECHO) $(ECHO) 'version: '\''0.146'\''' >> META_new.yml $(NOECHO) $(ECHO) 'x_serialization_backend: '\''CPAN::Meta::YAML version 0.018'\''' >> META_new.yml -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml $(NOECHO) $(ECHO) Generating META.json $(NOECHO) $(ECHO) '{' > META_new.json $(NOECHO) $(ECHO) ' "abstract" : "File path utility",' >> META_new.json $(NOECHO) $(ECHO) ' "author" : [' >> META_new.json $(NOECHO) $(ECHO) ' "David Golden <dagolden@cpan.org>"' >> META_new.json $(NOECHO) $(ECHO) ' ],' >> META_new.json $(NOECHO) $(ECHO) ' "dynamic_config" : 1,' >> META_new.json $(NOECHO) $(ECHO) ' "generated_by" : "ExtUtils::MakeMaker version 7.60, CPAN::Meta::Converter version 2.150010",' >> META_new.json $(NOECHO) $(ECHO) ' "license" : [' >> META_new.json $(NOECHO) $(ECHO) ' "apache_2_0"' >> META_new.json $(NOECHO) $(ECHO) ' ],' >> META_new.json $(NOECHO) $(ECHO) ' "meta-spec" : {' >> META_new.json $(NOECHO) $(ECHO) ' "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",' >> META_new.json $(NOECHO) $(ECHO) ' "version" : 2' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "name" : "Path-Tiny",' >> META_new.json $(NOECHO) $(ECHO) ' "no_index" : {' >> META_new.json $(NOECHO) $(ECHO) ' "directory" : [' >> META_new.json $(NOECHO) $(ECHO) ' "t",' >> META_new.json $(NOECHO) $(ECHO) ' "inc"' >> META_new.json $(NOECHO) $(ECHO) ' ]' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "prereqs" : {' >> META_new.json $(NOECHO) $(ECHO) ' "build" : {' >> META_new.json $(NOECHO) $(ECHO) ' "requires" : {' >> META_new.json $(NOECHO) $(ECHO) ' "ExtUtils::MakeMaker" : "0"' >> META_new.json $(NOECHO) $(ECHO) ' }' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "configure" : {' >> META_new.json $(NOECHO) $(ECHO) ' "requires" : {' >> META_new.json $(NOECHO) $(ECHO) ' "ExtUtils::MakeMaker" : "6.17"' >> META_new.json $(NOECHO) $(ECHO) ' }' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "runtime" : {' >> META_new.json $(NOECHO) $(ECHO) ' "requires" : {' >> META_new.json $(NOECHO) $(ECHO) ' "Carp" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "Cwd" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "Digest" : "1.03",' >> META_new.json $(NOECHO) $(ECHO) ' "Digest::SHA" : "5.45",' >> META_new.json $(NOECHO) $(ECHO) ' "Encode" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "Exporter" : "5.57",' >> META_new.json $(NOECHO) $(ECHO) ' "Fcntl" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Compare" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Copy" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Glob" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Path" : "2.07",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Spec" : "0.86",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Temp" : "0.19",' >> META_new.json $(NOECHO) $(ECHO) ' "File::stat" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "constant" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "overload" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "perl" : "5.008001",' >> META_new.json $(NOECHO) $(ECHO) ' "strict" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "warnings" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "warnings::register" : "0"' >> META_new.json $(NOECHO) $(ECHO) ' }' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "test" : {' >> META_new.json $(NOECHO) $(ECHO) ' "requires" : {' >> META_new.json $(NOECHO) $(ECHO) ' "Digest::MD5" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "ExtUtils::MakeMaker" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Basename" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Spec" : "0.86",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Spec::Functions" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Spec::Unix" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "File::Temp" : "0.19",' >> META_new.json $(NOECHO) $(ECHO) ' "Test::More" : "0.96",' >> META_new.json $(NOECHO) $(ECHO) ' "lib" : "0",' >> META_new.json $(NOECHO) $(ECHO) ' "open" : "0"' >> META_new.json $(NOECHO) $(ECHO) ' }' >> META_new.json $(NOECHO) $(ECHO) ' }' >> META_new.json $(NOECHO) $(ECHO) ' },' >> META_new.json $(NOECHO) $(ECHO) ' "release_status" : "stable",' >> META_new.json $(NOECHO) $(ECHO) ' "version" : "0.146",' >> META_new.json $(NOECHO) $(ECHO) ' "x_serialization_backend" : "JSON::PP version 4.06"' >> META_new.json $(NOECHO) $(ECHO) '}' >> META_new.json -$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json # --- MakeMaker signature section: signature : cpansign -s # --- MakeMaker dist_basics section: distclean :: realclean distcheck $(NOECHO) $(NOOP) distcheck : $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck skipcheck : $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck manifest : $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest veryclean : realclean $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old # --- MakeMaker dist_core section: dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE) $(NOECHO) $(ABSPERLRUN) -l -e 'print '\''Warning: Makefile possibly out of date with $(VERSION_FROM)'\''' \ -e ' if -e '\''$(VERSION_FROM)'\'' and -M '\''$(VERSION_FROM)'\'' < -M '\''$(FIRST_MAKEFILE)'\'';' -- tardist : $(DISTVNAME).tar$(SUFFIX) $(NOECHO) $(NOOP) uutardist : $(DISTVNAME).tar$(SUFFIX) uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu $(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)_uu' $(DISTVNAME).tar$(SUFFIX) : distdir $(PREOP) $(TO_UNIX) $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME) $(RM_RF) $(DISTVNAME) $(COMPRESS) $(DISTVNAME).tar $(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)' $(POSTOP) zipdist : $(DISTVNAME).zip $(NOECHO) $(NOOP) $(DISTVNAME).zip : distdir $(PREOP) $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME) $(RM_RF) $(DISTVNAME) $(NOECHO) $(ECHO) 'Created $(DISTVNAME).zip' $(POSTOP) shdist : distdir $(PREOP) $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar $(RM_RF) $(DISTVNAME) $(NOECHO) $(ECHO) 'Created $(DISTVNAME).shar' $(POSTOP) # --- MakeMaker distdir section: create_distdir : $(RM_RF) $(DISTVNAME) $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \ -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');" distdir : create_distdir distmeta $(NOECHO) $(NOOP) # --- MakeMaker dist_test section: disttest : distdir cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL cd $(DISTVNAME) && $(MAKE) $(PASTHRU) cd $(DISTVNAME) && $(MAKE) test $(PASTHRU) # --- MakeMaker dist_ci section: ci : $(ABSPERLRUN) -MExtUtils::Manifest=maniread -e '@all = sort keys %{ maniread() };' \ -e 'print(qq{Executing $(CI) @all\n});' \ -e 'system(qq{$(CI) @all}) == 0 or die $$!;' \ -e 'print(qq{Executing $(RCS_LABEL) ...\n});' \ -e 'system(qq{$(RCS_LABEL) @all}) == 0 or die $$!;' -- # --- MakeMaker distmeta section: distmeta : create_distdir metafile $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'exit unless -e q{META.yml};' \ -e 'eval { maniadd({q{META.yml} => q{Module YAML meta-data (added by MakeMaker)}}) }' \ -e ' or die "Could not add META.yml to MANIFEST: $${'\''@'\''}"' -- $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'exit unless -f q{META.json};' \ -e 'eval { maniadd({q{META.json} => q{Module JSON meta-data (added by MakeMaker)}}) }' \ -e ' or die "Could not add META.json to MANIFEST: $${'\''@'\''}"' -- # --- MakeMaker distsignature section: distsignature : distmeta $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }' \ -e ' or die "Could not add SIGNATURE to MANIFEST: $${'\''@'\''}"' -- $(NOECHO) cd $(DISTVNAME) && $(TOUCH) SIGNATURE cd $(DISTVNAME) && cpansign -s # --- MakeMaker install section: install :: pure_install doc_install $(NOECHO) $(NOOP) install_perl :: pure_perl_install doc_perl_install $(NOECHO) $(NOOP) install_site :: pure_site_install doc_site_install $(NOECHO) $(NOOP) install_vendor :: pure_vendor_install doc_vendor_install $(NOECHO) $(NOOP) pure_install :: pure_$(INSTALLDIRS)_install $(NOECHO) $(NOOP) doc_install :: doc_$(INSTALLDIRS)_install $(NOECHO) $(NOOP) pure__install : pure_site_install $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site doc__install : doc_site_install $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site pure_perl_install :: all $(NOECHO) $(MOD_INSTALL) \ read "$(PERL_ARCHLIB)/auto/$(FULLEXT)/.packlist" \ write "$(DESTINSTALLARCHLIB)/auto/$(FULLEXT)/.packlist" \ "$(INST_LIB)" "$(DESTINSTALLPRIVLIB)" \ "$(INST_ARCHLIB)" "$(DESTINSTALLARCHLIB)" \ "$(INST_BIN)" "$(DESTINSTALLBIN)" \ "$(INST_SCRIPT)" "$(DESTINSTALLSCRIPT)" \ "$(INST_MAN1DIR)" "$(DESTINSTALLMAN1DIR)" \ "$(INST_MAN3DIR)" "$(DESTINSTALLMAN3DIR)" $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ "$(SITEARCHEXP)/auto/$(FULLEXT)" pure_site_install :: all $(NOECHO) $(MOD_INSTALL) \ read "$(SITEARCHEXP)/auto/$(FULLEXT)/.packlist" \ write "$(DESTINSTALLSITEARCH)/auto/$(FULLEXT)/.packlist" \ "$(INST_LIB)" "$(DESTINSTALLSITELIB)" \ "$(INST_ARCHLIB)" "$(DESTINSTALLSITEARCH)" \ "$(INST_BIN)" "$(DESTINSTALLSITEBIN)" \ "$(INST_SCRIPT)" "$(DESTINSTALLSITESCRIPT)" \ "$(INST_MAN1DIR)" "$(DESTINSTALLSITEMAN1DIR)" \ "$(INST_MAN3DIR)" "$(DESTINSTALLSITEMAN3DIR)" $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ "$(PERL_ARCHLIB)/auto/$(FULLEXT)" pure_vendor_install :: all $(NOECHO) $(MOD_INSTALL) \ read "$(VENDORARCHEXP)/auto/$(FULLEXT)/.packlist" \ write "$(DESTINSTALLVENDORARCH)/auto/$(FULLEXT)/.packlist" \ "$(INST_LIB)" "$(DESTINSTALLVENDORLIB)" \ "$(INST_ARCHLIB)" "$(DESTINSTALLVENDORARCH)" \ "$(INST_BIN)" "$(DESTINSTALLVENDORBIN)" \ "$(INST_SCRIPT)" "$(DESTINSTALLVENDORSCRIPT)" \ "$(INST_MAN1DIR)" "$(DESTINSTALLVENDORMAN1DIR)" \ "$(INST_MAN3DIR)" "$(DESTINSTALLVENDORMAN3DIR)" doc_perl_install :: all $(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod" -$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)" -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLPRIVLIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> "$(DESTINSTALLARCHLIB)/perllocal.pod" doc_site_install :: all $(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod" -$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)" -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLSITELIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> "$(DESTINSTALLARCHLIB)/perllocal.pod" doc_vendor_install :: all $(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod" -$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)" -$(NOECHO) $(DOC_INSTALL) \ "Module" "$(NAME)" \ "installed into" "$(INSTALLVENDORLIB)" \ LINKTYPE "$(LINKTYPE)" \ VERSION "$(VERSION)" \ EXE_FILES "$(EXE_FILES)" \ >> "$(DESTINSTALLARCHLIB)/perllocal.pod" uninstall :: uninstall_from_$(INSTALLDIRS)dirs $(NOECHO) $(NOOP) uninstall_from_perldirs :: $(NOECHO) $(UNINSTALL) "$(PERL_ARCHLIB)/auto/$(FULLEXT)/.packlist" uninstall_from_sitedirs :: $(NOECHO) $(UNINSTALL) "$(SITEARCHEXP)/auto/$(FULLEXT)/.packlist" uninstall_from_vendordirs :: $(NOECHO) $(UNINSTALL) "$(VENDORARCHEXP)/auto/$(FULLEXT)/.packlist" # --- MakeMaker force section: # Phony target to force checking subdirectories. FORCE : $(NOECHO) $(NOOP) # --- MakeMaker perldepend section: # --- MakeMaker makefile section: # We take a very conservative approach here, but it's worth it. # We move Makefile to Makefile.old here to avoid gnu make looping. $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP) $(NOECHO) $(ECHO) "Makefile out-of-date with respect to $?" $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..." -$(NOECHO) $(RM_F) $(MAKEFILE_OLD) -$(NOECHO) $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL) $(PERLRUN) Makefile.PL $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <==" $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command. <==" $(FALSE) # --- MakeMaker staticmake section: # --- MakeMaker makeaperl section --- MAP_TARGET = perl FULLPERL = "/usr/bin/perl" MAP_PERLINC = "-Iblib/arch" "-Iblib/lib" "-I/usr/lib64/perl5" "-I/usr/share/perl5" $(MAP_TARGET) :: $(MAKE_APERL_FILE) $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@ $(MAKE_APERL_FILE) : static $(FIRST_MAKEFILE) pm_to_blib $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET) $(NOECHO) $(PERLRUNINST) \ Makefile.PL DIR="" \ MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \ MAKEAPERL=1 NORECURS=1 CCCDLFLAGS= # --- MakeMaker test section: TEST_VERBOSE=0 TEST_TYPE=test_$(LINKTYPE) TEST_FILE = test.pl TEST_FILES = t/*.t TESTDB_SW = -d testdb :: testdb_$(LINKTYPE) $(NOECHO) $(NOOP) test :: $(TEST_TYPE) $(NOECHO) $(NOOP) # Occasionally we may face this degenerate target: test_ : test_dynamic $(NOECHO) $(NOOP) subdirs-test_dynamic :: dynamic pure_all test_dynamic :: subdirs-test_dynamic PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES) testdb_dynamic :: dynamic pure_all PERL_DL_NONLAZY=1 $(FULLPERLRUN) $(TESTDB_SW) "-I$(INST_LIB)" "-I$(INST_ARCHLIB)" $(TEST_FILE) subdirs-test_static :: static pure_all test_static :: subdirs-test_static PERL_DL_NONLAZY=1 $(FULLPERLRUN) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES) testdb_static :: static pure_all PERL_DL_NONLAZY=1 $(FULLPERLRUN) $(TESTDB_SW) "-I$(INST_LIB)" "-I$(INST_ARCHLIB)" $(TEST_FILE) # --- MakeMaker ppd section: # Creates a PPD (Perl Package Description) for a binary distribution. ppd : $(NOECHO) $(ECHO) '<SOFTPKG NAME="Path-Tiny" VERSION="0.146">' > Path-Tiny.ppd $(NOECHO) $(ECHO) ' <ABSTRACT>File path utility</ABSTRACT>' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <AUTHOR>David Golden <dagolden@cpan.org></AUTHOR>' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <IMPLEMENTATION>' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <PERLCORE VERSION="5,008001,0,0" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Carp::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Cwd::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Digest::" VERSION="1.03" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Digest::SHA" VERSION="5.45" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Encode::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Exporter::" VERSION="5.57" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="Fcntl::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Compare" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Copy" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Glob" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Path" VERSION="2.07" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Spec" VERSION="0.86" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::Temp" VERSION="0.19" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="File::stat" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="constant::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="overload::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="strict::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="warnings::" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <REQUIRE NAME="warnings::register" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <ARCHITECTURE NAME="x86_64-linux-thread-multi-5.32" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' <CODEBASE HREF="" />' >> Path-Tiny.ppd $(NOECHO) $(ECHO) ' </IMPLEMENTATION>' >> Path-Tiny.ppd $(NOECHO) $(ECHO) '</SOFTPKG>' >> Path-Tiny.ppd # --- MakeMaker pm_to_blib section: pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM) $(NOECHO) $(ABSPERLRUN) -MExtUtils::Install -e 'pm_to_blib({@ARGV}, '\''$(INST_LIB)/auto'\'', q[$(PM_FILTER)], '\''$(PERM_DIR)'\'')' -- \ 'lib/Path/Tiny.pm' 'blib/lib/Path/Tiny.pm' $(NOECHO) $(TOUCH) pm_to_blib # --- MakeMaker selfdocument section: # here so even if top_targets is overridden, these will still be defined # gmake will silently still work if any are .PHONY-ed but nmake won't static :: $(NOECHO) $(NOOP) dynamic :: $(NOECHO) $(NOOP) config :: $(NOECHO) $(NOOP) # --- MakeMaker postamble section: # End. META.json 0000644 00000013170 15125124546 0006174 0 ustar 00 { "abstract" : "File path utility", "author" : [ "David Golden <dagolden@cpan.org>" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Path-Tiny", "no_index" : { "directory" : [ "corpus", "examples", "t", "xt" ], "package" : [ "DB", "flock" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17", "perl" : "5.008001" }, "suggests" : { "JSON::PP" : "2.27300" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::Plugin::MinimumPerl" : "0", "Dist::Zilla::Plugin::OnlyCorePrereqs" : "0", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::Plugin::ReleaseStatus::FromVersion" : "0", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Pod::Wordlist" : "0", "Software::License::Apache_2_0" : "0", "Test::CPAN::Meta" : "0", "Test::MinimumVersion" : "0", "Test::More" : "0", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Portability::Files" : "0", "Test::Spelling" : "0.12", "Test::Version" : "1" } }, "runtime" : { "recommends" : { "Unicode::UTF8" : "0.58" }, "requires" : { "Carp" : "0", "Cwd" : "0", "Digest" : "1.03", "Digest::SHA" : "5.45", "Encode" : "0", "Exporter" : "5.57", "Fcntl" : "0", "File::Compare" : "0", "File::Copy" : "0", "File::Glob" : "0", "File::Path" : "2.07", "File::Spec" : "0.86", "File::Temp" : "0.19", "File::stat" : "0", "constant" : "0", "overload" : "0", "perl" : "5.008001", "strict" : "0", "warnings" : "0", "warnings::register" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900", "Test::FailWarnings" : "0", "Test::MockRandom" : "0" }, "requires" : { "Digest::MD5" : "0", "ExtUtils::MakeMaker" : "0", "File::Basename" : "0", "File::Spec" : "0.86", "File::Spec::Functions" : "0", "File::Spec::Unix" : "0", "File::Temp" : "0.19", "Test::More" : "0.96", "lib" : "0", "open" : "0", "perl" : "5.008001" } } }, "provides" : { "Path::Tiny" : { "file" : "lib/Path/Tiny.pm", "version" : "0.146" }, "Path::Tiny::Error" : { "file" : "lib/Path/Tiny.pm", "version" : "0.146" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/Path-Tiny/issues" }, "homepage" : "https://github.com/dagolden/Path-Tiny", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/Path-Tiny.git", "web" : "https://github.com/dagolden/Path-Tiny" } }, "version" : "0.146", "x_authority" : "cpan:DAGOLDEN", "x_contributors" : [ "Alex Efros <powerman@powerman.name>", "Aristotle Pagaltzis <pagaltzis@gmx.de>", "Chris Williams <bingos@cpan.org>", "Dan Book <grinnz@grinnz.com>", "Dave Rolsky <autarch@urth.org>", "David Steinbrunner <dsteinbrunner@pobox.com>", "Doug Bell <madcityzen@gmail.com>", "Elvin Aslanov <rwp.primary@gmail.com>", "Flavio Poletti <flavio@polettix.it>", "Gabor Szabo <szabgab@cpan.org>", "Gabriel Andrade <gabiruh@gmail.com>", "George Hartzell <hartzell@cpan.org>", "Geraud Continsouzas <geraud@scsi.nc>", "Goro Fuji <gfuji@cpan.org>", "Graham Knop <haarg@haarg.org>", "Graham Ollis <plicease@cpan.org>", "Ian Sillitoe <ian@sillit.com>", "James Hunt <james@niftylogic.com>", "John Karr <brainbuz@brainbuz.org>", "Karen Etheridge <ether@cpan.org>", "Mark Ellis <mark.ellis@cartridgesave.co.uk>", "Martin H. Sluka <fany@cpan.org>", "Martin Kjeldsen <mk@bluepipe.dk>", "Mary Ehlers <regina.verb.ae@gmail.com>", "Michael G. Schwern <mschwern@cpan.org>", "Nicolas R <nicolas@atoomic.org>", "Nicolas Rochelemagne <rochelemagne@cpanel.net>", "Nigel Gregoire <nigelgregoire@gmail.com>", "Philippe Bruhat (BooK) <book@cpan.org>", "regina-verbae <regina-verbae@users.noreply.github.com>", "Roy Ivy III <rivy@cpan.org>", "Shlomi Fish <shlomif@shlomifish.org>", "Smylers <Smylers@stripey.com>", "Tatsuhiko Miyagawa <miyagawa@bulknews.net>", "Toby Inkster <tobyink@cpan.org>", "Yanick Champoux <yanick@babyl.dyndns.org>", "\uae40\ub3c4\ud615 - Keedi Kim <keedi@cpan.org>" ], "x_generated_by_perl" : "v5.36.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.29", "x_spdx_expression" : "Apache-2.0" } LICENSE 0000644 00000026335 15125124546 0005567 0 ustar 00 This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2014 David Golden Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. t/chmod.t 0000644 00000001774 15125124546 0006304 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $fh = path("t/data/chmod.txt")->openr; while ( my $line = <$fh> ) { chomp $line; my ( $chmod, $orig, $expect ) = split " ", $line; my $got = sprintf( "%05o", Path::Tiny::_symbolic_chmod( oct($orig), $chmod ) ); is( $got, $expect, "$orig -> $chmod -> $got" ); } my $path = Path::Tiny->tempfile; like( exception { $path->chmod("ldkakdfa") }, qr/Invalid mode argument/, "Invalid mode throws exception" ); like( exception { $path->chmod("sdfa=kdajfkl") }, qr/Invalid mode clause/, "Invalid mode clause throws exception" ); ok( exception { path("adljfasldfj")->chmod(0700) }, "Nonexistent file throws exception" ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: t/symlinks.t 0000644 00000003016 15125124546 0007052 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception has_symlinks/; use Path::Tiny; use Cwd 'abs_path'; plan skip_all => "No symlink support" unless has_symlinks(); subtest "relative symlinks with updir" => sub { my $temp = Path::Tiny->tempdir; my $td = $temp->realpath; $td->child(qw/tmp tmp2/)->mkdir; my $foo = $td->child(qw/tmp foo/)->touch; my $bar = $td->child(qw/tmp tmp2 bar/); symlink "../foo", $bar or die "Failed to symlink: $!\n"; ok -f $foo, "it's a file"; ok -l $bar, "it's a link"; is readlink $bar, "../foo", "the link seems right"; is abs_path($bar), $foo, "abs_path gets's it right"; is $bar->realpath, $foo, "realpath get's it right"; }; subtest "symlink loop detection" => sub { my $temp = Path::Tiny->tempdir; my $td = $temp->realpath; $td->child("A")->touch; for my $pair ( [qw/A B/], [qw/B C/], [qw/C A/] ) { my $target = $td->child( $pair->[1] ); $target->remove if -e $target; symlink $pair->[0], $td->child( $pair->[1] ) or die "Failed to symlink @$pair: $!\n"; } diag for $td->children; like( exception { $td->child("A")->realpath }, qr/symlink loop detected/, "symlink loop detected" ); }; done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: set ts=4 sts=4 sw=4 et tw=75: t/recurse.t 0000644 00000007621 15125124546 0006657 0 ustar 00 use 5.006; use strict; use warnings; use Test::More 0.92; use File::Temp; use lib 't/lib'; use TestUtils qw/exception tempd has_symlinks/; use Path::Tiny; #--------------------------------------------------------------------------# subtest 'no symlinks' => sub { my $wd = tempd; my @tree = qw( aaaa.txt bbbb.txt cccc/dddd.txt cccc/eeee/ffff.txt gggg.txt ); my @breadth = qw( aaaa.txt bbbb.txt cccc gggg.txt cccc/dddd.txt cccc/eeee cccc/eeee/ffff.txt ); path($_)->touchpath for @tree; subtest 'iterator' => sub { my $iter = path(".")->iterator( { recurse => 1 } ); my @files; while ( my $f = $iter->() ) { push @files, "$f"; } is_deeply( [ sort @files ], [ sort @breadth ], "Breadth first iteration" ) or diag explain \@files; }; subtest 'visit' => sub { my @files; path(".")->visit( sub { push @files, "$_[0]" }, { recurse => 1 }, ); is_deeply( [ sort @files ], [ sort @breadth ], "Breadth first iteration" ) or diag explain \@files; }; subtest 'visit state' => sub { my $result = path(".")->visit( sub { $_[1]->{$_}++ }, { recurse => 1 }, ); is_deeply( [ sort keys %$result ], [ sort @breadth ], "Breadth first iteration" ) or diag explain $result; }; subtest 'visit abort' => sub { my $result = path(".")->visit( sub { return \0 if ++$_[1]->{count} == 2 }, { recurse => 1 } ); is( $result->{count}, 2, "visitor aborted on false scalar ref" ); }; }; subtest 'with symlinks' => sub { plan skip_all => "No symlink support" unless has_symlinks(); my $wd = tempd; my @tree = qw( aaaa.txt bbbb.txt cccc/dddd.txt cccc/eeee/ffff.txt gggg.txt ); my @follow = qw( aaaa.txt bbbb.txt cccc gggg.txt pppp qqqq.txt cccc/dddd.txt cccc/eeee cccc/eeee/ffff.txt pppp/ffff.txt ); my @nofollow = qw( aaaa.txt bbbb.txt cccc gggg.txt pppp qqqq.txt cccc/dddd.txt cccc/eeee cccc/eeee/ffff.txt ); path($_)->touchpath for @tree; symlink path( 'cccc', 'eeee' ), path('pppp'); symlink path('aaaa.txt'), path('qqqq.txt'); subtest 'no follow' => sub { # no-follow subtest 'iterator' => sub { my $iter = path(".")->iterator( { recurse => 1 } ); my @files; while ( my $f = $iter->() ) { push @files, "$f"; } is_deeply( [ sort @files ], [ sort @nofollow ], "Don't follow symlinks" ) or diag explain \@files; }; subtest 'visit' => sub { my @files; path(".")->visit( sub { push @files, "$_[0]" }, { recurse => 1 }, ); is_deeply( [ sort @files ], [ sort @nofollow ], "Don't follow symlinks" ) or diag explain \@files; }; }; subtest 'follow' => sub { subtest 'iterator' => sub { my $iter = path(".")->iterator( { recurse => 1, follow_symlinks => 1 } ); my @files; while ( my $f = $iter->() ) { push @files, "$f"; } is_deeply( [ sort @files ], [ sort @follow ], "Follow symlinks" ) or diag explain \@files; }; subtest 'visit' => sub { my @files; path(".") ->visit( sub { push @files, "$_[0]" }, { recurse => 1, follow_symlinks => 1 }, ); is_deeply( [ sort @files ], [ sort @follow ], "Follow symlinks" ) or diag explain \@files; }; }; }; done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/parent.t 0000644 00000006100 15125124546 0006467 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; my $DEBUG; BEGIN { $DEBUG = 0 } BEGIN { if ($DEBUG) { require Path::Class; Path::Class->import } } my $IS_WIN32 = $^O eq 'MSWin32'; use Path::Tiny; use File::Spec::Functions qw/canonpath/; sub canonical { my $d = canonpath(shift); $d =~ s{\\}{/}g; $d .= "/" if $d =~ m{//[^/]+/[^/]+$}; return $d; } my @cases = ( #<<< No perltidy "absolute" => [ "/foo/bar" => "/foo" => "/" => "/" ], "relative" => [ "foo/bar/baz" => "foo/bar" => "foo" => "." => ".." => "../.." => "../../.." ], "absolute with .." => [ "/foo/bar/../baz" => "/foo/bar/.." => "/foo/bar/../.." => "/foo/bar/../../.." ], "relative with .." => [ "foo/bar/../baz" => "foo/bar/.." => "foo/bar/../.." => "foo/bar/../../.." ], "relative with leading .." => [ "../foo/bar" => "../foo" => ".." => "../.." ], "absolute with internal dots" => [ "/foo..bar/baz..bam" => "/foo..bar" => "/" ], "relative with internal dots" => [ "foo/bar..baz/wib..wob" => "foo/bar..baz" => "foo" => "." => ".." ], "absolute with leading dots" => [ "/..foo/..bar" => "/..foo" => "/" ], "relative with leading dots" => [ "..foo/..bar/..wob" => "..foo/..bar" => "..foo" => "." => ".." ], "absolute with trailing dots" => [ "/foo../bar.." => "/foo.." => "/" ], "relative with trailing dots" => [ "foo../bar../wob.." => "foo../bar.." => "foo.." => "." => ".." ], #>>> ); my @win32_cases = ( #<<< No perltidy "absolute with drive" => [ "C:/foo/bar" => "C:/foo" => "C:/" => "C:/" ], "absolute with drive and .." => [ "C:/foo/bar/../baz" => "C:/foo" => "C:/" ], "absolute with UNC" => [ "//server/share/foo/bar" => "//server/share/foo" => "//server/share/" => "//server/share/" ], "absolute with drive, UNC and .." => [ "//server/share/foo/bar/../baz" => "//server/share/foo" => "//server/share/" ], #>>> ); push @cases, @win32_cases if $IS_WIN32; while (@cases) { my ( $label, $list ) = splice( @cases, 0, 2 ); subtest $label => sub { my $path = path( shift @$list ); while (@$list) { for my $i ( undef, 0, 1 .. @$list ) { my $n = ( defined $i && $i > 0 ) ? $i : 1; my $expect = $list->[ $n - 1 ]; my $got = $path->parent($i); my $s = defined($i) ? $i : "undef"; is( $got, canonical($expect), "parent($s): $path -> $got" ); is( dir("$path")->parent, canonical($expect), "Path::Class agrees" ) if $DEBUG; } $path = $path->parent; shift @$list; } if ( $path !~ m{\Q..\E} ) { ok( $path->is_rootdir, "final path is root directory" ); } }; } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/rel-abs.t 0000644 00000017605 15125124546 0006537 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception pushd tempd has_symlinks/; use Path::Tiny; # absolute() tests my $rel1 = path("."); my $abs1 = $rel1->absolute; is( $abs1->absolute, $abs1, "absolute of absolute is identity" ); my $rel2 = $rel1->child("t"); my $abs2 = $rel2->absolute; is( $rel2->absolute($abs1), $abs2, "absolute on base" ); # Note: in following relative() tests, capital 'A', 'B' denotes absolute path # and lower case 'a', 'b' denotes relative paths. 'R' denotes the root # directory. When there are multiple # letters together, they indicate how paths relate in the hierarchy: # A subsumes AB, ABC and ABD have a common prefix (referred to as AB). # The presence of an underscore indicates a symlink somewhere in that segment # of a path: ABC_D indicates a symlink somewhere between ABC and ABC_D. my @symlink_free_cases = ( # identical (absolute and relative cases) [ "A->rel(A)", "/foo/bar", "/foo/bar", "." ], [ "a->rel(a)", "foo/bar", "foo/bar", "." ], # descends -- absolute [ "AB->rel(A)", "/foo/bar/baz", "/", "foo/bar/baz" ], [ "AB->rel(A)", "/foo/bar/baz", "/foo", "bar/baz" ], [ "AB->rel(A)", "/foo/bar/baz", "/foo/bar", "baz" ], # descends -- relative [ "ab->rel(a)", "foo/bar/baz", "", "foo/bar/baz" ], [ "ab->rel(a)", "foo/bar/baz", ".", "foo/bar/baz" ], [ "ab->rel(a)", "foo/bar/baz", "foo", "bar/baz" ], [ "ab->rel(a)", "foo/bar/baz", "foo/bar", "baz" ], # common prefix -- absolute (same volume) [ "R->rel(A)", "/", "/bam", ".." ], [ "R->rel(AB)", "/", "/bam/baz", "../.." ], [ "ABC->rel(D)", "/foo/bar/baz", "/bam", "../foo/bar/baz" ], [ "ABC->rel(AD)", "/foo/bar/baz", "/foo/bam", "../bar/baz" ], [ "ABC->rel(ABD)", "/foo/bar/baz", "/foo/bar/bam", "../baz" ], [ "ABC->rel(DE)", "/foo/bar/baz", "/bim/bam", "../../foo/bar/baz" ], [ "ABC->rel(ADE)", "/foo/bar/baz", "/foo/bim/bam", "../../bar/baz" ], [ "ABC->rel(ABDE)", "/foo/bar/baz", "/foo/bar/bim/bam", "../../baz" ], # common prefix -- relative (same volume) [ "abc->rel(d)", "foo/bar/baz", "bam", "../foo/bar/baz" ], [ "abc->rel(ad)", "foo/bar/baz", "foo/bam", "../bar/baz" ], [ "abc->rel(abd)", "foo/bar/baz", "foo/bar/bam", "../baz" ], [ "abc->rel(de)", "foo/bar/baz", "bim/bam", "../../foo/bar/baz" ], [ "abc->rel(ade)", "foo/bar/baz", "foo/bim/bam", "../../bar/baz" ], [ "abc->rel(abde)", "foo/bar/baz", "foo/bar/bim/bam", "../../baz" ], # both paths relative (not identical) [ "ab->rel(a)", "foo/bar", "foo", "bar" ], [ "abc->rel(ab)", "foo/bar/baz", "foo/bim", "../bar/baz" ], [ "a->rel(b)", "foo", "bar", "../foo" ], ); for my $c (@symlink_free_cases) { my ( $label, $path, $base, $result ) = @$c; is( path($path)->relative($base), $result, $label ); } my @one_rel_from_root = ( [ "A->rel(b) from rootdir", "/foo/bar", "baz", "../foo/bar" ], [ "a->rel(B) from rootdir", "foo/bar", "/baz", "../foo/bar" ], ); { my $wd = pushd("/"); for my $c (@one_rel_from_root) { my ( $label, $path, $base, $result ) = @$c; is( path($path)->relative($base), $result, $label ); } } { my $wd = tempd("/"); my $cwd = Path::Tiny::cwd->realpath; # A->rel(b) from tmpdir -- need to find updir from ./b to root my $base = $cwd->child("baz"); my ( undef, @parts ) = split "/", $base; my $up_to_root = path( "../" x @parts ); is( path("/foo/bar")->relative("baz"), $up_to_root->child("foo/bar"), "A->rel(b) from tmpdir" ); # a->rel(B) from tempdir -- path is .. + cwd + a is( path("foo/bar")->relative("/baz"), path( "..", $cwd->_just_filepath, "foo/bar" ), "a->rel(B) from tmpdir" ); } subtest "relative on absolute paths with symlinks" => sub { my $wd = tempd; my $cwd = path(".")->realpath; my $deep = $cwd->child("foo/bar/baz/bam/bim/buz/wiz/was/woz"); $deep->mkdir(); plan skip_all => "No symlink support" unless has_symlinks(); my ( $path, $base, $expect ); # (a) symlink in common path # # A_BCD->rel(A_BEF) - common point A_BC - result: ../../C/D # $cwd->child("A")->mkdir; symlink $deep, "A/B" or die "$!"; $path = $cwd->child("A/B/C/D"); $path->mkdir; is( $path->relative( $cwd->child("A/B/E/F") ), "../../C/D", "A_BCD->rel(A_BEF)" ); $cwd->child("A")->remove_tree; $deep->remove_tree; $deep->mkdir; # (b) symlink in path from common to original path # # ABC_DE->rel(ABFG) - common point AB - result: ../../C/D/E # $cwd->child("A/B/C")->mkdir; symlink $deep, "A/B/C/D" or die "$!"; $path = $cwd->child("A/B/C/D/E"); $path->mkdir; is( $path->relative( $cwd->child("A/B/F/G") ), "../../C/D/E", "ABC_DE->rel(ABC_FG)" ); $cwd->child("A")->remove_tree; $deep->remove_tree; $deep->mkdir; # (c) symlink in path from common to new base; all path exist # # ABCD->rel(ABE_FG) - common point AB - result depends on E_F resolution # $path = $cwd->child("A/B/C/D"); $path->mkdir; $cwd->child("A/B/E")->mkdir; symlink $deep, "A/B/E/F" or die $!; $base = $cwd->child("A/B/E/F/G"); $base->mkdir; $expect = $path->relative( $deep->child("G") ); is( $path->relative($base), $expect, "ABCD->rel(ABE_FG) [real paths]" ); $cwd->child("A")->remove_tree; $deep->remove_tree; $deep->mkdir; # (d) symlink in path from common to new base; paths after symlink # don't exist # # ABCD->rel(ABE_FGH) - common point AB - result depends on E_F resolution # $path = $cwd->child("A/B/C/D"); $path->mkdir; $cwd->child("A/B/E")->mkdir; symlink $deep, "A/B/E/F" or die $!; $base = $cwd->child("A/B/E/F/G/H"); $expect = $path->relative( $deep->child("G/H") ); is( $path->relative($base), $expect, "ABCD->rel(ABE_FGH) [unreal paths]" ); $cwd->child("A")->remove_tree; $deep->remove_tree; $deep->mkdir; # (e) symlink at end of common, with updir at start of new base # # AB_CDE->rel(AB_C..FG) - common point really AB - result depends on # symlink resolution # $cwd->child("A/B")->mkdir; symlink $deep, "A/B/C" or die "$!"; $path = $cwd->child("A/B/C/D/E"); $path->mkdir; $base = $cwd->child("A/B/C/../F/G"); $base->mkdir; $expect = $path->relative( $deep->parent->child("F/G")->realpath ); is( $path->relative($base), $expect, "AB_CDE->rel(AB_C..FG)" ); $cwd->child("A")->remove_tree; $deep->remove_tree; $deep->mkdir; # (f) updirs in new base [files exist] # # ABCDE->rel(ABF..GH) - common point AB - result ../../C/D/E # $path = $cwd->child("A/B/C/D/E"); $path->mkdir; $cwd->child("A/B/F")->mkdir; $cwd->child("A/B/G/H")->mkdir; $base = $cwd->child("A/B/F/../G/H"); $expect = "../../C/D/E"; is( $path->relative($base), $expect, "ABCDE->rel(ABF..GH) [real paths]" ); $cwd->child("A")->remove_tree; # (f) updirs in new base [files don't exist] # # ABCDE->rel(ABF..GH) - common point AB - result ../../C/D/E # $path = $cwd->child("A/B/C/D/E"); $base = $cwd->child("A/B/F/../G/H"); $expect = "../../C/D/E"; is( $path->relative($base), $expect, "ABCDE->rel(ABF..GH) [unreal paths]" ); $cwd->child("A")->remove_tree; }; # XXX need to test common prefix case where both are abs but one # has volume and one doesn't. (Win32: UNC and drive letters) # XXX need to test A->rel(B) where A and B are different volumes, # including UNC and drive letters done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/data/chmod.txt 0000644 00000142261 15125124546 0007566 0 ustar 00 au=w,uo=x,go=wx 00777 00133 augo-rw,ug=rwx 00000 00770 augo-rw,ug=rwx 00777 00771 go+rwx 00000 00077 go+rwx 00777 00777 u=wx,ao=wx,go=rwx 00777 00377 augo=x,aug-rw 00777 00111 ug-w 00000 00000 ug-w 00777 00557 o+rx,uo-rw,au+wx 00777 00373 o+rx,uo-rw,au+wx 00000 00333 ugo=wx,auo=r,augo-x 00777 00444 a-x,u-rw,aug=rw 00777 00666 auo=rwx,u=x,ag-r 00777 00133 ugo+rw 00777 00777 ugo+rw 00000 00666 au=rwx 00777 00777 a-w,auo+r,ag=r 00777 00444 ao=rwx,ago-rwx 00777 00000 g=rwx 00000 00070 g=rwx 00777 00777 auo-w,go+rw 00000 00066 auo-w,go+rw 00777 00577 ao+rx 00777 00777 ao+rx 00000 00555 ugo+rwx,aug=x 00777 00111 auo+rw,o-rwx,ago=rw 00777 00666 uo+x 00777 00777 uo+x 00000 00101 u=w 00000 00200 u=w 00777 00277 ug=rw,ago+x,uo=rx 00777 00575 ag+rw 00000 00666 ag+rw 00777 00777 auo=x 00777 00111 augo+wx,uo+wx,o-w 00777 00775 augo+wx,uo+wx,o-w 00000 00331 a+rw 00000 00666 a+rw 00777 00777 ago-r,ug+wx 00000 00330 ago-r,ug+wx 00777 00333 g=rx,augo=rx 00777 00555 u=rwx,auo+rx,ug+rw 00000 00775 u=rwx,auo+rx,ug+rw 00777 00777 go+w 00000 00022 go+w 00777 00777 ugo=w,aug=rw,auo=rx 00777 00555 ago-r 00777 00333 ago-r 00000 00000 o-wx 00777 00774 o-wx 00000 00000 o+x,a+wx 00777 00777 o+x,a+wx 00000 00333 au-rw,auo+wx,ug+rw 00777 00773 augo=rw,aug=wx 00777 00333 augo+x,ugo-rwx 00777 00000 o-rwx,go+w 00777 00772 o-rwx,go+w 00000 00022 ag-rx 00777 00222 ag-rx 00000 00000 auo=rw,g+rx 00777 00676 aug+rwx,ug-rx,ao+rw 00777 00667 u-x,a-r 00000 00000 u-x,a-r 00777 00233 au+x 00000 00111 au+x 00777 00777 ao=w,augo=rx,aug-rwx 00777 00000 aug-rwx 00777 00000 a+rx,ug-x,ao+rx 00777 00777 a+rx,ug-x,ao+rx 00000 00555 go=x 00000 00011 go=x 00777 00711 ugo-rx,ago+rx 00000 00555 ugo-rx,ago+rx 00777 00777 go-wx,augo-wx,u+x 00777 00544 go-wx,augo-wx,u+x 00000 00100 au-rw,augo+rw 00000 00666 au-rw,augo+rw 00777 00777 ag-rx,au-w,ugo+x 00777 00111 augo=x,auo+wx,u-x 00777 00233 aug+x,auo+rx 00777 00777 aug+x,auo+rx 00000 00555 aug-w,a-rx 00777 00000 ugo=rx 00777 00555 au-wx,ugo-rwx,u+r 00777 00400 ug=rw,au+rwx 00777 00777 go=rw,o=w,ao-rw 00777 00100 go=rw,o=w,ao-rw 00000 00000 ugo+wx 00777 00777 ugo+wx 00000 00333 ug=x,o=rw,uo+r 00777 00516 augo+r,au+x 00777 00777 augo+r,au+x 00000 00555 g=r,ao+w 00777 00767 g=r,ao+w 00000 00262 augo+w,a+w,ug=rx 00000 00552 augo+w,a+w,ug=rx 00777 00557 ugo=rwx,ago+w,aug-rx 00777 00222 aug-rw,augo=w,ago=x 00777 00111 auo=x,ao-w 00777 00111 ug-x,ugo-w 00777 00445 ug-x,ugo-w 00000 00000 ao-rwx,a=rwx,ag-rw 00777 00111 ag=rwx,aug+r 00777 00777 go+rw,uo+x 00000 00167 go+rw,uo+x 00777 00777 ugo+w 00000 00222 ugo+w 00777 00777 ug+r 00000 00440 ug+r 00777 00777 u-r 00000 00000 u-r 00777 00377 ao=rwx,ug=r 00777 00447 o+wx,g-r 00000 00003 o+wx,g-r 00777 00737 uo+w 00000 00202 uo+w 00777 00777 ag-rw,g=r,auo-rx 00777 00000 au=w,ug-rx 00777 00222 a+rw,auo+wx,auo+rx 00777 00777 aug-r 00000 00000 aug-r 00777 00333 uo+r 00000 00404 uo+r 00777 00777 ago-x 00000 00000 ago-x 00777 00666 aug-rwx,augo+r 00777 00444 ag=rw,ao-rw,a=rx 00777 00555 ago=x,ugo=x,aug=rwx 00777 00777 ag+w 00777 00777 ag+w 00000 00222 o=r,ugo=r,ao=r 00777 00444 ao-wx,g-w 00777 00444 ao-wx,g-w 00000 00000 au-r,o-wx 00000 00000 au-r,o-wx 00777 00330 ag=rw,ago=x,aug-rx 00777 00000 aug+r,a-rwx,u-x 00777 00000 u-x,ag+wx,go-x 00000 00322 u-x,ag+wx,go-x 00777 00766 a-rw,a-w,ag=rx 00777 00555 ago-rw,aug=rwx 00777 00777 aug=r,ag=w 00777 00222 g-x,a=rw 00777 00666 ug+rwx 00000 00770 ug+rwx 00777 00777 aug+x,go=x 00777 00711 aug+x,go=x 00000 00111 ago=x,aug+x 00777 00111 go=rwx 00000 00077 go=rwx 00777 00777 au+rw,ugo=w,augo-rw 00777 00000 ag=rwx 00777 00777 augo=rx,go=rw 00777 00566 ag-rwx,o+rx,u=rx 00777 00505 ugo=x,auo+wx,ug-rx 00777 00223 u-wx,u-r,go-r 00000 00000 u-wx,u-r,go-r 00777 00033 au=rwx,aug=rw 00777 00666 au-wx 00777 00444 au-wx 00000 00000 aug=rwx,ao-rw 00777 00111 g+wx 00000 00030 g+wx 00777 00777 auo+wx,ago-x 00777 00666 auo+wx,ago-x 00000 00222 auo-rw,uo=wx 00777 00313 auo-rw,uo=wx 00000 00303 uo-wx,ao-rx 00777 00020 uo-wx,ao-rx 00000 00000 aug+rx,uo-x,ago=r 00777 00444 aug=rwx,g=rwx,aug=wx 00777 00333 ago+rx,ug-rwx,o+w 00777 00007 ago-rw 00777 00111 ago-rw 00000 00000 ao=w,o+rx,u=wx 00777 00327 au+w,ago-w 00777 00555 au+w,ago-w 00000 00000 au+x,aug+wx 00000 00333 au+x,aug+wx 00777 00777 ug=x,u=x 00000 00110 ug=x,u=x 00777 00117 ugo=wx,au=r,au+rwx 00777 00777 ug=wx 00000 00330 ug=wx 00777 00337 o-r,ago=x,a+wx 00777 00333 ago+rx,o-wx,au-rw 00777 00110 o+w,auo=rx 00777 00555 auo=wx,ao-rwx,au=rx 00777 00555 ag+x,ao+w 00000 00333 ag+x,ao+w 00777 00777 u=rw 00000 00600 u=rw 00777 00677 aug+w,o-x 00000 00222 aug+w,o-x 00777 00776 u+wx,ao=rwx,o+w 00777 00777 a+rw,ag+rx 00777 00777 g-rx 00000 00000 g-rx 00777 00727 g-w,au-rx,a+wx 00777 00333 u=r,ago+x,augo+w 00000 00733 u=r,ago+x,augo+w 00777 00777 ug-r,g-x,ago+x 00777 00337 ug-r,g-x,ago+x 00000 00111 u-w,ag-x 00000 00000 u-w,ag-x 00777 00466 go+x 00000 00011 go+x 00777 00777 g+x,ao-x 00777 00666 g+x,ao-x 00000 00000 augo+r,o=rw,aug-rw 00777 00110 augo+r,o=rw,aug-rw 00000 00000 aug+wx,o=r 00000 00334 aug+wx,o=r 00777 00774 u=rwx,o-wx,augo-rw 00777 00110 u=rwx,o-wx,augo-rw 00000 00100 ug-w,a=x,g=rx 00777 00151 g+rx,g+rwx,go-r 00777 00733 g+rx,g+rwx,go-r 00000 00030 au=w 00777 00222 augo-w,auo-x,ao-wx 00000 00000 augo-w,auo-x,ao-wx 00777 00444 ugo-rw,ao+x,ag-x 00777 00000 ugo=w,ago-r 00777 00222 auo-rw,aug=wx,aug-rw 00777 00111 aug-x,o-rx 00777 00662 aug-x,o-rx 00000 00000 ug+rwx,o+rw 00000 00776 ug+rwx,o+rw 00777 00777 auo-rw,augo=rwx,augo=rw 00777 00666 uo=rw,au+x 00000 00717 uo=rw,au+x 00777 00777 ug-r,ago-rx,o+wx 00777 00223 ug-r,ago-rx,o+wx 00000 00003 u=rw,augo=rw,ag+rx 00777 00777 u+wx,o-rw,augo=w 00777 00222 uo=wx,g-r,ao=x 00777 00111 g=w,go-rw,au+x 00777 00711 g=w,go-rw,au+x 00000 00111 auo+x,uo-rwx 00777 00070 auo+x,uo-rwx 00000 00010 o-w 00000 00000 o-w 00777 00775 ugo=w,ao-rw 00777 00000 a=rw 00777 00666 ao-rx,ugo-rw,auo+rwx 00777 00777 ao=rx,au+wx,augo-rw 00777 00111 a=rwx,ao+r,au+w 00777 00777 u+w,u-rwx,augo+r 00777 00477 u+w,u-rwx,augo+r 00000 00444 ugo=rwx 00777 00777 go-w,ug=rw,au+w 00000 00662 go-w,ug=rw,au+w 00777 00667 aug+w,auo=rx 00777 00555 ag=r 00777 00444 ug-r,augo-r,ugo-rx 00000 00000 ug-r,augo-r,ugo-rx 00777 00222 u-rwx,ago=x 00777 00111 u-wx,ugo=wx,ao+x 00777 00333 ao=rw 00777 00666 g=x,auo=r 00777 00444 go=rw 00000 00066 go=rw 00777 00766 a+rx 00000 00555 a+rx 00777 00777 au-rx,go=r 00000 00044 au-rx,go=r 00777 00244 augo-x,ag+rw,ago=rwx 00777 00777 g=rx 00777 00757 g=rx 00000 00050 ug+rwx,augo-wx,aug=wx 00777 00333 ugo-wx,aug=rx 00777 00555 au+r 00777 00777 au+r 00000 00444 au+x,au+w 00000 00333 au+x,au+w 00777 00777 go+x,ug-x,uo+rx 00777 00767 go+x,ug-x,uo+rx 00000 00505 ago-rx,ug+x 00000 00110 ago-rx,ug+x 00777 00332 a=r,ag+r,go+wx 00777 00477 g=r 00000 00040 g=r 00777 00747 ugo+w,ago=r,auo+rx 00777 00555 ago=r,ao+rwx,ugo+wx 00777 00777 a-rw,ag=r 00777 00444 ugo+rwx 00777 00777 a+rx,o-w 00000 00555 a+rx,o-w 00777 00775 ao+r,o+r 00000 00444 ao+r,o+r 00777 00777 o=rw,augo+rwx,au=rw 00777 00666 ago-rw,u=w,ao=rwx 00777 00777 u+rw,go=rx,ag+rw 00777 00777 u+rw,go=rx,ag+rw 00000 00677 u=rx,a+wx 00000 00733 u=rx,a+wx 00777 00777 ugo+rx 00000 00555 ugo+rx 00777 00777 uo=rw 00777 00676 uo=rw 00000 00606 a+rwx,aug=wx,auo-r 00777 00333 uo+wx 00777 00777 uo+wx 00000 00303 a-rw,ao+r 00777 00555 a-rw,ao+r 00000 00444 ugo-rx,au-r,ao+x 00000 00111 ugo-rx,au-r,ao+x 00777 00333 ag-rx,a-rwx 00777 00000 ago+wx,uo-rx 00000 00232 ago+wx,uo-rx 00777 00272 ago-r,g=rw,ao=rwx 00777 00777 ug+x,go=rw 00777 00766 ug+x,go=rw 00000 00166 g+rw,auo=x 00777 00111 augo=rx 00777 00555 ag-r,go=r 00777 00344 ag-r,go=r 00000 00044 aug=x 00777 00111 go-r,u=wx 00000 00300 go-r,u=wx 00777 00333 ugo-wx,a=rw,augo-rx 00777 00222 augo+rwx,au=w 00777 00222 ag=x,aug-w 00777 00111 ug=x,u=r,auo=r 00777 00444 o+rwx,ugo=r,a+rw 00777 00666 ug-wx 00777 00447 ug-wx 00000 00000 uo-x,aug+w 00000 00222 uo-x,aug+w 00777 00676 au+rw,ago-x 00777 00666 ug=rw,go=x 00777 00611 ug=rx,ago=rwx,g-rwx 00777 00707 au=rwx,ugo+w,ao=rwx 00777 00777 augo-rx,ug+w 00000 00220 augo-rx,ug+w 00777 00222 ao+x,ugo=wx,au+rw 00777 00777 ug=wx,u=w 00000 00230 ug=wx,u=w 00777 00237 ago+x,au-rw 00777 00111 augo+r,aug=rx 00777 00555 ao=rw,ug+wx 00777 00776 ag-w,augo-w 00777 00555 ag-w,augo-w 00000 00000 o-rwx 00000 00000 o-rwx 00777 00770 ugo-w 00000 00000 ugo-w 00777 00555 ugo+rw,uo-w,aug=r 00777 00444 ago=rwx,ag-rx 00777 00222 o=x,uo-x,auo-x 00777 00660 o=x,uo-x,auo-x 00000 00000 g-rx,au-x,ago+r 00777 00666 g-rx,au-x,ago+r 00000 00444 go+rw 00777 00777 go+rw 00000 00066 u-wx,augo=w,go-rx 00777 00222 aug=wx,ago=r,auo-r 00777 00000 au+rx,go=wx 00000 00533 au+rx,go=wx 00777 00733 au-rx 00000 00000 au-rx 00777 00222 augo+rw 00000 00666 augo+rw 00777 00777 ao=wx,augo-rx,aug=w 00777 00222 o+wx,o+rx 00777 00777 o+wx,o+rx 00000 00007 o-wx,uo-x 00777 00674 o-wx,uo-x 00000 00000 ao+rw 00777 00777 ao+rw 00000 00666 g+x,ago-rx,a+rwx 00777 00777 ao+rwx,u-wx 00777 00477 aug=r,a-w 00777 00444 ago=x,g+rx,ago=wx 00777 00333 uo+rw,au+r 00000 00646 uo+rw,au+r 00777 00777 aug-wx,o-x 00777 00444 aug-wx,o-x 00000 00000 ao+w 00777 00777 ao+w 00000 00222 u=x,g+rwx,au=x 00777 00111 uo=rw,au=x,g+r 00777 00151 au+rw 00000 00666 au+rw 00777 00777 ao=r,go=rx,ag=rx 00777 00555 ug=rx,ago+w,aug+wx 00000 00773 ug=rx,ago+w,aug+wx 00777 00777 au+rwx,au+rwx,go-rx 00777 00722 uo+wx,ag-wx,augo=rx 00777 00555 o+rx,augo+rw 00000 00667 o+rx,augo+rw 00777 00777 o-rx,ao+wx,ao=wx 00777 00333 uo+rw,a-w 00000 00404 uo+rw,a-w 00777 00555 ug+wx 00000 00330 ug+wx 00777 00777 ago-x,ago=rx,ao-rw 00777 00111 ao-rw,auo=w,ag-x 00777 00222 go+rx,ugo+rwx 00777 00777 o+rwx,o+rx,g-rx 00777 00727 o+rwx,o+rx,g-rx 00000 00007 a=x,augo=r 00777 00444 auo-rw 00000 00000 auo-rw 00777 00111 augo=rx,go=r 00777 00544 ag+r,ugo-rw 00000 00000 ag+r,ugo-rw 00777 00111 auo-rx,a+rx 00000 00555 auo-rx,a+rx 00777 00777 ug+rw 00777 00777 ug+rw 00000 00660 auo=rx,auo-rx 00777 00000 aug+w,aug-rw,ago=x 00777 00111 ugo=r,aug=wx,a-w 00777 00111 ago=rx 00777 00555 u-rw,go+rwx,ugo=x 00777 00111 o=rw,uo+wx,aug=r 00777 00444 ug+wx,aug=rx 00777 00555 u=x,ago-wx,ag=rw 00777 00666 aug=rwx 00777 00777 uo+x,aug-rw,ug=r 00777 00441 uo-r,o-rw 00000 00000 uo-r,o-rw 00777 00371 g+rw 00777 00777 g+rw 00000 00060 uo+rw,au=x 00777 00111 ug-w,ao-wx 00777 00444 ug-w,ao-wx 00000 00000 a=rx,ag-r,ago-w 00777 00111 go-rwx,go=rw 00000 00066 go-rwx,go=rw 00777 00766 o+rw 00000 00006 o+rw 00777 00777 ao+x,a=r,ao+rw 00777 00666 aug+x,ao-x 00777 00666 aug+x,ao-x 00000 00000 uo=r,ug+wx,g+w 00000 00734 uo=r,ug+wx,g+w 00777 00774 o-rw,auo=r,augo=rw 00777 00666 au=w,ago-wx,g=rwx 00777 00070 a+wx,ug-x,aug=x 00777 00111 ug-wx,ugo=r 00777 00444 ag-r,g-r,go=wx 00000 00033 ag-r,g-r,go=wx 00777 00333 ag-x,aug+x 00777 00777 ag-x,aug+x 00000 00111 augo=r 00777 00444 go+wx,ao=x,ao+rw 00777 00777 au+x,ag-rx,o=wx 00000 00003 au+x,ag-rx,o=wx 00777 00223 a+x,ago+rwx,uo=rx 00777 00575 ug-rw 00777 00117 ug-rw 00000 00000 u=w,go-w,ao+wx 00777 00377 u=w,go-w,ao+wx 00000 00333 uo-rwx,g-rwx 00777 00000 ago+r,ago+rwx,ago=r 00777 00444 auo=w,o+rx 00777 00227 go+wx,u+rx,uo-wx 00000 00430 go+wx,u+rx,uo-wx 00777 00474 ao+x 00777 00777 ao+x 00000 00111 ag-rw,a-rw,ao+rx 00777 00555 auo-r 00777 00333 auo-r 00000 00000 o+rw,ag=rw,o=x 00777 00661 go=rwx,go+rwx,ag=rx 00777 00555 aug=rx,auo-rwx,augo=r 00777 00444 ao-rwx,au=w,u+rwx 00777 00722 aug+w 00777 00777 aug+w 00000 00222 o-rw 00000 00000 o-rw 00777 00771 go+rwx,ug=rwx 00777 00777 auo+rx,au-w 00777 00555 a-wx 00777 00444 a-wx 00000 00000 au=rwx,go+rwx 00777 00777 o+rx 00000 00005 o+rx 00777 00777 g=wx 00777 00737 g=wx 00000 00030 ago=r 00777 00444 auo=rw,go-r,go-rx 00777 00622 ugo=wx,ago=rx,o+wx 00777 00557 go=rwx,ago+x,a+r 00000 00577 go=rwx,ago+x,a+r 00777 00777 ag-wx 00000 00000 ag-wx 00777 00444 o-wx,uo-rwx 00000 00000 o-wx,uo-rwx 00777 00070 u-wx 00777 00477 u-wx 00000 00000 u+rwx,ugo-x,u-x 00777 00666 u+rwx,ugo-x,u-x 00000 00600 ugo=rw 00777 00666 au+rx,g=w,auo=w 00777 00222 a-wx,ago-x 00000 00000 a-wx,ago-x 00777 00444 u+rw,au-rwx 00777 00000 augo-wx,aug+wx 00000 00333 augo-wx,aug+wx 00777 00777 g+r 00777 00777 g+r 00000 00040 aug=rwx,augo-rx 00777 00222 ug=w,aug+rwx,uo=rx 00777 00575 a=rwx 00777 00777 ugo=r,g-r,a=wx 00777 00333 g+rwx 00000 00070 g+rwx 00777 00777 au=x,a-wx,au+x 00777 00111 go-x,ao-r,ag=x 00777 00111 ao=r,ao+rx 00777 00555 ag+w,ao-rw,ag+wx 00777 00333 g+r,o-r,augo-rw 00777 00111 g+r,o-r,augo-rw 00000 00000 go+r 00000 00044 go+r 00777 00777 ao=r,o+rwx 00777 00447 ago=r,go=rwx 00777 00477 ao+rwx,ag+r,ugo-rwx 00777 00000 ao=wx 00777 00333 ago+wx,aug+rwx 00777 00777 ao=wx,aug=wx 00777 00333 ao=w,a-r,ao+rx 00777 00777 aug+w,u-x,auo+wx 00000 00333 aug+w,u-x,auo+wx 00777 00777 o=wx,go=rw,ag=x 00777 00111 uo-rwx,uo-rwx 00000 00000 uo-rwx,uo-rwx 00777 00070 o=x 00000 00001 o=x 00777 00771 ao-rwx 00777 00000 o-x,uo-w,ao=w 00777 00222 au+r,u=r 00777 00477 au+r,u=r 00000 00444 go=rx,g+wx 00000 00075 go=rx,g+wx 00777 00775 ag+w,o+rwx,ago=r 00777 00444 auo-w,u-x 00777 00455 auo-w,u-x 00000 00000 ug-rw,uo-w,aug-rx 00777 00000 a+x,ao+r 00777 00777 a+x,ao+r 00000 00555 ag=rwx,aug-wx 00777 00444 au+w,ugo-rw,ugo+rx 00777 00555 g=rw 00000 00060 g=rw 00777 00767 a-rx 00777 00222 a-rx 00000 00000 ugo-x,ag+rx 00777 00777 ugo-x,ag+rx 00000 00555 auo-rwx,au-rwx,ag+x 00777 00111 uo-w 00000 00000 uo-w 00777 00575 o+rwx 00000 00007 o+rwx 00777 00777 ago-rx 00777 00222 ago-rx 00000 00000 ao+rwx,ao+rw 00777 00777 au=w,ao+wx,g-rx 00777 00323 o-x,g+rw 00777 00776 o-x,g+rw 00000 00060 u+rx,uo+rw 00777 00777 u+rx,uo+rw 00000 00706 ugo-rw 00000 00000 ugo-rw 00777 00111 ag-r,ago=x 00777 00111 go=x,a=x,ago=wx 00777 00333 ao-x 00777 00666 ao-x 00000 00000 u+rw,aug=rw,uo=x 00777 00161 uo+w,ago-rwx 00777 00000 augo=x 00777 00111 ug=x,go+rw 00777 00177 ug=x,go+rw 00000 00176 ugo=rw,ag=w 00777 00222 g+rx,u-w,ug+rx 00777 00577 g+rx,u-w,ug+rx 00000 00550 ug=rx,auo-rwx,u+r 00777 00400 a+rwx,go-w 00777 00755 o-x,auo-rwx,go-x 00777 00000 u-rw,ao=w,u+rx 00777 00722 ugo+x,a=rx,ag=wx 00777 00333 auo+x 00777 00777 auo+x 00000 00111 ugo+wx,ugo+w 00777 00777 ugo+wx,ugo+w 00000 00333 ag+x 00777 00777 ag+x 00000 00111 go-rx,au+rx 00777 00777 go-rx,au+rx 00000 00555 ao+rwx,go+x 00777 00777 a=wx 00777 00333 u+rwx,o+r 00777 00777 u+rwx,o+r 00000 00704 auo=rx,u-rwx 00777 00055 u=x,au-w 00000 00100 u=x,au-w 00777 00155 auo+rwx,ago-rw 00777 00111 ao+x,u=w,g-rw 00777 00217 ao+x,u=w,g-rw 00000 00211 a=w,ag+r,g+w 00777 00666 g-rw 00777 00717 g-rw 00000 00000 augo+x 00000 00111 augo+x 00777 00777 o-rx,g-rwx,ag=rx 00777 00555 augo=rw,aug+r 00777 00666 uo+rwx 00000 00707 uo+rwx 00777 00777 aug-rx,ao+x,uo=rw 00777 00636 aug-rx,ao+x,uo=rw 00000 00616 u-r,ago-rx,ug=rw 00777 00662 u-r,ago-rx,ug=rw 00000 00660 au=wx,ugo+rx,go=x 00777 00711 o-rx,ugo+x,ao-rx 00000 00000 o-rx,ugo+x,ao-rx 00777 00222 augo-w,a=rwx,o-rw 00777 00771 o+wx 00000 00003 o+wx 00777 00777 aug-w,aug+wx 00777 00777 aug-w,aug+wx 00000 00333 ug-rwx,aug-r,augo-rwx 00777 00000 aug+rw 00777 00777 aug+rw 00000 00666 augo+rwx,go-w,ao-w 00777 00555 o-w,o=w 00777 00772 o-w,o=w 00000 00002 o-rwx,ao-x 00000 00000 o-rwx,ao-x 00777 00660 au-x,g-rx,u+r 00000 00400 au-x,g-rx,u+r 00777 00626 ao=wx,au+w 00777 00333 ao=rwx,aug-rwx,au=x 00777 00111 aug+x,a-rwx 00777 00000 go-rx,go+x 00000 00011 go-rx,go+x 00777 00733 au-wx,au-w,ugo+wx 00000 00333 au-wx,au-w,ugo+wx 00777 00777 augo-rx,go-x 00000 00000 augo-rx,go-x 00777 00222 go-rx 00000 00000 go-rx 00777 00722 o+rwx,uo-rwx,augo-rwx 00777 00000 auo=w,ago=rwx,g-r 00777 00737 ago-w 00000 00000 ago-w 00777 00555 aug+wx,ugo-rx,go-r 00777 00222 g-x,auo+x 00777 00777 g-x,auo+x 00000 00111 ao-x,uo-rw,aug-rw 00777 00000 go-x,au=rx 00777 00555 a+r 00777 00777 a+r 00000 00444 ao-rw 00777 00111 ao-rw 00000 00000 ug-rx 00777 00227 ug-rx 00000 00000 ago-rwx 00777 00000 uo-rwx 00777 00070 uo-rwx 00000 00000 ag-rw,o+w 00777 00113 ag-rw,o+w 00000 00002 au=rx,augo=w,go-rwx 00777 00200 g=wx,u=x,a=rx 00777 00555 augo-x,u=wx,a+r 00777 00766 augo-x,u=wx,a+r 00000 00744 go+rwx,ag+rx 00000 00577 go+rwx,ag+rx 00777 00777 ago+rw,a=rx,ug-wx 00777 00445 ago-rx,ago+w,uo=r 00777 00424 auo+wx 00000 00333 auo+wx 00777 00777 ago+w,aug=rwx 00777 00777 a-rx,go+wx,ago-rx 00777 00222 a-rx,go+wx,ago-rx 00000 00022 aug+r 00000 00444 aug+r 00777 00777 aug+rw,ugo+rw,u=wx 00777 00377 aug+rw,ugo+rw,u=wx 00000 00366 a-wx,au-rwx,ag-wx 00777 00000 o+wx,a-x,ugo+rw 00777 00666 u=rwx,uo-x,ugo-rwx 00777 00000 aug-rw 00000 00000 aug-rw 00777 00111 uo=x 00777 00171 uo=x 00000 00101 auo-w,ug+wx,ug-wx 00000 00000 auo-w,ug+wx,ug-wx 00777 00445 uo+rwx,uo=wx 00000 00303 uo+rwx,uo=wx 00777 00373 auo=rw 00777 00666 ug-rw,au-rw,o=rwx 00777 00117 ug-rw,au-rw,o=rwx 00000 00007 ugo-x 00000 00000 ugo-x 00777 00666 ao=wx,ug-rw,augo-rwx 00777 00000 o=w 00000 00002 o=w 00777 00772 a=x,uo-w,ugo-wx 00777 00000 ag-rw 00000 00000 ag-rw 00777 00111 uo=rx,ug-rw,g-wx 00777 00105 go=x,ug-w,uo-wx 00777 00410 go=x,ug-w,uo-wx 00000 00010 uo+r,g-r 00000 00404 uo+r,g-r 00777 00737 au+rwx,g=wx,uo+rx 00777 00737 ao=w,g-rw,aug+x 00777 00313 augo=wx,go-rx 00777 00322 augo+w,go-x,u+rx 00777 00766 augo+w,go-x,u+rx 00000 00722 g=x,ago=rwx 00777 00777 a=w,u=r,o-rw 00777 00420 o+x,auo+rwx,ugo+wx 00777 00777 go=wx,ag=r 00777 00444 a+x,aug=rwx 00777 00777 g=rx,uo+rx 00777 00757 g=rx,uo+rx 00000 00555 auo-wx,aug-w 00777 00444 auo-wx,aug-w 00000 00000 g+rx,go+r 00777 00777 g+rx,go+r 00000 00054 a-r 00000 00000 a-r 00777 00333 a=rw,ao-w 00777 00444 u-rx 00000 00000 u-rx 00777 00277 g-r 00777 00737 g-r 00000 00000 a+w 00000 00222 a+w 00777 00777 au-x,ug-r 00000 00000 au-x,ug-r 00777 00226 go-x 00000 00000 go-x 00777 00766 a+w,aug=x 00777 00111 ao-rw,uo+rx,aug-wx 00777 00404 ago=x,uo-rw,auo=rw 00777 00666 o-rx,ag=rwx 00777 00777 au+wx,ugo+x 00000 00333 au+wx,ugo+x 00777 00777 g+rx 00777 00777 g+rx 00000 00050 ag=rx,o=wx 00777 00553 aug-x 00777 00666 aug-x 00000 00000 ag-r,o=rwx,aug=wx 00777 00333 a+w,ugo+rwx,ug-wx 00777 00447 aug=rwx,ao=rwx,ugo+rw 00777 00777 au-rwx,ao=r,go=r 00777 00444 u=wx,ugo+rwx 00777 00777 ao-x,ag-r 00777 00222 ao-x,ag-r 00000 00000 ugo+r 00777 00777 ugo+r 00000 00444 au=wx,aug=w 00777 00222 go-rw,o+rw 00000 00006 go-rw,o+rw 00777 00717 ug=rwx,augo+wx,a+wx 00000 00773 ug=rwx,augo+wx,a+wx 00777 00777 ag+x,uo-x 00777 00676 ag+x,uo-x 00000 00010 uo=rwx,o+rw 00000 00707 uo=rwx,o+rw 00777 00777 auo=rw,go=wx,ao-rwx 00777 00000 au=rw,ug-rwx,aug-w 00777 00004 uo+rw 00777 00777 uo+rw 00000 00606 g-rwx 00000 00000 g-rwx 00777 00707 auo=r,auo-wx,o+rwx 00777 00447 o-r,au=rw,ag+w 00777 00666 o=rw 00777 00776 o=rw 00000 00006 go+r,auo+rw 00000 00666 go+r,auo+rw 00777 00777 ago-rwx,go=wx,ug-rw 00777 00013 ao=r,uo-rx,a-rwx 00777 00000 ag=wx,uo-r 00777 00333 ag+r,ugo+wx 00777 00777 ag-wx,g=rx 00000 00050 ag-wx,g=rx 00777 00454 ug+rx,ag-rwx 00777 00000 augo=rx,o+wx,au=wx 00777 00333 o+rw,go-rwx 00000 00000 o+rw,go-rwx 00777 00700 ago=rw,au=x,ao=r 00777 00444 ug-rw,a=rwx 00777 00777 go+rwx,ao-rw 00777 00111 go+rwx,ao-rw 00000 00011 ugo+rx,au=rwx 00777 00777 ao+wx,uo-rw,augo+w 00777 00373 ao+wx,uo-rw,augo+w 00000 00333 au=x 00777 00111 ugo+w,ag+rwx 00777 00777 ago=rw,go-r,augo=rwx 00777 00777 ago-rx,ao=wx 00777 00333 au=rx,au=x 00777 00111 augo+rx,go+rwx,aug+r 00000 00577 augo+rx,go+rwx,aug+r 00777 00777 ago=rwx,ag-wx 00777 00444 ag=w,augo-wx 00777 00000 g+rx,ag+rw 00777 00777 g+rx,ag+rw 00000 00676 uo+rx,ugo=w,a+r 00777 00666 au-w,auo+x 00777 00555 au-w,auo+x 00000 00111 aug-w,auo-wx,auo=wx 00777 00333 u=wx,g+w,auo-rwx 00777 00000 auo=w,go-r 00777 00222 ugo-r,u+wx,aug=x 00777 00111 g=r,ug=rw 00000 00660 g=r,ug=rw 00777 00667 uo-rwx,augo=r 00777 00444 augo+rx 00000 00555 augo+rx 00777 00777 ao+rx,ago=x 00777 00111 auo+rw,ag=x,aug=x 00777 00111 a+wx 00777 00777 a+wx 00000 00333 au=x,ugo=wx 00777 00333 auo-w 00777 00555 auo-w 00000 00000 ag-rwx,auo-rx,go+w 00777 00022 ug+rx,ago=w 00777 00222 uo-r,g=rwx,ugo=w 00777 00222 ao=w 00777 00222 auo-rwx 00777 00000 a=rw,u=rx,u-rw 00777 00166 aug-rx,au-r 00777 00222 aug-rx,au-r 00000 00000 uo-r,ago=rx 00777 00555 g+x,uo=rx 00777 00575 g+x,uo=rx 00000 00515 ago=rwx,auo-x,ago=rx 00777 00555 ug+x 00777 00777 ug+x 00000 00110 ug=r,uo-x,au-rwx 00777 00000 ao-rw,ug-wx 00777 00001 ao-rw,ug-wx 00000 00000 ug-r,a+rwx 00777 00777 ugo-wx,ug-wx,ug=wx 00000 00330 ugo-wx,ug-wx,ug=wx 00777 00334 u+w,au-wx,ug=r 00000 00440 u+w,au-wx,ug=r 00777 00444 auo+r,g+w,o+r 00777 00777 auo+r,g+w,o+r 00000 00464 ugo+x 00777 00777 ugo+x 00000 00111 ago-w,aug-rw 00000 00000 ago-w,aug-rw 00777 00111 aug-wx,go=rw 00000 00066 aug-wx,go=rw 00777 00466 ago-rw,go+w,a-w 00000 00000 ago-rw,go+w,a-w 00777 00111 au+w,ao=wx,ug=rwx 00777 00773 uo+rwx,uo+r 00000 00707 uo+rwx,uo+r 00777 00777 ugo+rx,au+rwx,ug-x 00777 00667 o=rwx,g-x 00000 00007 o=rwx,g-x 00777 00767 ug-r,au+wx 00777 00337 ug-r,au+wx 00000 00333 ago=w,augo=r 00777 00444 augo+w 00777 00777 augo+w 00000 00222 a=w,uo+wx 00777 00323 g-rw,aug=x,go-rw 00777 00111 augo-rw,aug=r 00777 00444 auo-rw,augo-rw,ao+rw 00777 00777 auo-rw,augo-rw,ao+rw 00000 00666 auo-rx 00777 00222 auo-rx 00000 00000 u+r,uo=rx,ag=wx 00777 00333 ao=x,uo-w 00777 00111 ugo-rx,ago-rwx,ao+rw 00777 00666 augo=wx,o=x 00777 00331 uo+r,ago+x,au-x 00000 00404 uo+r,ago+x,au-x 00777 00666 au=wx,g-wx,o=rw 00777 00306 auo+r 00777 00777 auo+r 00000 00444 ugo-r 00777 00333 ugo-r 00000 00000 aug=r,au-wx,augo-wx 00777 00444 ago+wx,ago=wx,ao-rwx 00777 00000 au+rx,ugo-x,o-rx 00777 00662 au+rx,ugo-x,o-rx 00000 00440 ugo-rwx,a+w 00777 00222 auo+rwx,o+x 00777 00777 ago+x,ago=w,aug-x 00777 00222 ao+w,uo+rw 00000 00626 ao+w,uo+rw 00777 00777 uo-r 00777 00373 uo-r 00000 00000 uo=rw,ao-rx 00777 00222 uo=rw,ao-rx 00000 00202 u-rw 00777 00177 u-rw 00000 00000 au-rx,a=wx 00777 00333 g-wx 00777 00747 g-wx 00000 00000 ago-x,a+rwx 00777 00777 go=w 00777 00722 go=w 00000 00022 ao=x 00777 00111 ago=w 00777 00222 uo=w,ugo-rx,auo+w 00777 00222 auo-rwx,a=rw 00777 00666 go-r,ago+wx 00777 00733 go-r,ago+wx 00000 00333 a-wx,ao=w,augo=x 00777 00111 ago=wx,u+rw 00777 00733 ao=rx 00777 00555 ag+wx 00777 00777 ag+wx 00000 00333 ago=x,augo=rx 00777 00555 ago+wx,uo+rwx,augo=w 00777 00222 auo=wx 00777 00333 ago+rx 00777 00777 ago+rx 00000 00555 uo-wx,ugo+x,ugo-rw 00777 00111 ago-r,ao+rwx,augo+rx 00777 00777 u+rwx 00777 00777 u+rwx 00000 00700 ugo=r 00777 00444 a+rx,go-rwx,ug=rwx 00777 00770 a=x,ugo-x,ug-r 00777 00000 aug=x,ag=x 00777 00111 au=wx,auo-w 00777 00111 aug=rw,go=w,g-w 00777 00602 u-rwx 00777 00077 u-rwx 00000 00000 uo=r,aug-rx,ao=wx 00777 00333 ugo=x,g+rx 00777 00151 ao-x,au+wx,ag+rx 00777 00777 o=r,au+rwx 00777 00777 aug-rwx,ag=wx 00777 00333 ag+rw,g=x,auo=rx 00777 00555 a=rwx,ugo=wx,au=rwx 00777 00777 ao=rwx,augo-w 00777 00555 ugo=w,au-x,uo-rw 00777 00020 ug+x,u=rx 00777 00577 ug+x,u=rx 00000 00510 ugo+rwx,u+rwx,aug-wx 00777 00444 ugo+x,o=r 00777 00774 ugo+x,o=r 00000 00114 au=w,uo=x 00777 00121 ao=rx,go+rw 00777 00577 ag=x 00777 00111 ug-wx,g-wx 00000 00000 ug-wx,g-wx 00777 00447 aug-x,augo+rw,g=wx 00777 00636 ao+rw,ago=w 00777 00222 ug-rw,u+rwx,ao=rwx 00777 00777 o-rw,ugo-rw 00777 00111 o-rw,ugo-rw 00000 00000 aug+wx,auo-w 00000 00111 aug+wx,auo-w 00777 00555 auo=wx,aug-r 00777 00333 auo=r 00777 00444 ug+w,au-wx,aug-w 00777 00444 ug+w,au-wx,aug-w 00000 00000 ao-rw,auo+rwx,g+w 00777 00777 ugo=rx,go=x 00777 00511 auo-rwx,o-x 00777 00000 auo+rw 00000 00666 auo+rw 00777 00777 ago=rx,ago+rwx,augo-rx 00777 00222 g+x 00000 00010 g+x 00777 00777 o-x,aug+w 00000 00222 o-x,aug+w 00777 00776 a=x,uo=r,a-w 00777 00414 augo+rwx,g+wx 00777 00777 au-rx,ago-rx 00777 00222 au-rx,ago-rx 00000 00000 ao-rx 00000 00000 ao-rx 00777 00222 a+x,ag=wx 00777 00333 auo=rwx 00777 00777 ao-r 00000 00000 ao-r 00777 00333 a=r,ug-w 00777 00444 g+x,ago+rwx,u-rw 00777 00177 ug+rx,go=rw,u=rw 00777 00666 ago-r,ag-rwx,au-w 00777 00000 ago=w,u=rwx 00777 00722 ug-wx,ug+rw 00777 00667 ug-wx,ug+rw 00000 00660 o=x,auo+rwx 00777 00777 aug=wx 00777 00333 ag=rx,ao-rw,g+r 00777 00151 ao+wx 00000 00333 ao+wx 00777 00777 augo=w,augo+r,g-rw 00777 00606 auo=rx,au+rwx,a-wx 00777 00444 au-rw,aug+rx 00777 00555 go+rwx,ago+wx,a=w 00777 00222 augo=rwx,ag-rw 00777 00111 a=rx,a=r,ugo=wx 00777 00333 au-w,aug=wx 00777 00333 uo-wx,au-r 00000 00000 uo-wx,au-r 00777 00030 uo-rx,go+x,g+r 00000 00051 uo-rx,go+x,g+r 00777 00273 ag=r,au=rwx 00777 00777 ug+rwx,ug+wx 00777 00777 ug+rwx,ug+wx 00000 00770 a-w 00000 00000 a-w 00777 00555 u+r 00777 00777 u+r 00000 00400 augo=r,augo+w,uo+r 00777 00666 u+rw,go-rx 00777 00722 u+rw,go-rx 00000 00600 ag=rx 00777 00555 augo-w,u=x,augo=wx 00777 00333 aug-wx,go-x 00000 00000 aug-wx,go-x 00777 00444 ao=x,auo=rwx 00777 00777 uo=rwx 00000 00707 uo=rwx 00777 00777 o-w,au=rw 00777 00666 ugo=w 00777 00222 g-wx,aug+wx,u-x 00777 00677 g-wx,aug+wx,u-x 00000 00233 ag=x,u-wx 00777 00011 g=r,ao=rx 00777 00555 ao+r 00777 00777 ao+r 00000 00444 u+wx 00000 00300 u+wx 00777 00777 ag=rwx,ugo+w 00777 00777 u=rx 00777 00577 u=rx 00000 00500 au=rw,o=rwx,o=wx 00777 00663 ago+x,auo-wx 00777 00444 ago+x,auo-wx 00000 00000 ago+rwx 00777 00777 aug-rwx,ao-rwx 00777 00000 a+rwx,u=r 00777 00477 ag+rw,au+x,ug+rx 00777 00777 o+wx,u+r 00000 00403 o+wx,u+r 00777 00777 ag+x,auo-wx,a=rwx 00777 00777 go-w,ugo-w 00777 00555 go-w,ugo-w 00000 00000 ao=rwx 00777 00777 ago=x 00777 00111 uo+w,ao-r,augo-rwx 00777 00000 auo-wx,go-w 00777 00444 auo-wx,go-w 00000 00000 g-rx,u-r 00000 00000 g-rx,u-r 00777 00327 augo-rwx,a=w,a-w 00777 00000 au=r 00777 00444 aug=rw,auo+x,ugo+rx 00777 00777 ag-x,uo+x 00777 00767 ag-x,uo+x 00000 00101 a+w,ugo+wx 00777 00777 a+w,ugo+wx 00000 00333 augo+rwx 00777 00777 augo-r,o+rx 00777 00337 augo-r,o+rx 00000 00005 ao-wx 00777 00444 ao-wx 00000 00000 au-rw 00000 00000 au-rw 00777 00111 go+rw,au+rx 00000 00577 go+rw,au+rx 00777 00777 ugo+w,augo=rw,aug=rx 00777 00555 ag+rwx 00777 00777 a+rwx,uo+r 00777 00777 ug-w,aug-r 00000 00000 ug-w,aug-r 00777 00113 uo+rx,aug-wx 00777 00444 uo+rx,aug-wx 00000 00404 ao=w,o+wx 00777 00223 uo=rwx,g+rw,u+rx 00000 00767 uo=rwx,g+rw,u+rx 00777 00777 aug-rwx,augo=rx,au-wx 00777 00444 ag-rwx 00777 00000 ug=w,u+x 00000 00320 ug=w,u+x 00777 00327 ug=rwx,g+r 00000 00770 ug=rwx,g+r 00777 00777 g-rwx,au-x 00777 00606 g-rwx,au-x 00000 00000 ao-wx,go=rx 00000 00055 ao-wx,go=rx 00777 00455 ao=x,ug-x,ugo+rx 00777 00555 ug+x,u=r,go+w 00000 00432 ug+x,u=r,go+w 00777 00477 go+rx 00000 00055 go+rx 00777 00777 a=rw,ugo+wx,ago=rw 00777 00666 ug+x,o=r 00777 00774 ug+x,o=r 00000 00114 o+w 00777 00777 o+w 00000 00002 ag+w,go-wx 00777 00744 ag+w,go-wx 00000 00200 u-wx,ago=rwx 00777 00777 ago+r 00000 00444 ago+r 00777 00777 go-wx,auo-rx,ag+r 00000 00444 go-wx,auo-rx,ag+r 00777 00644 auo+w 00777 00777 auo+w 00000 00222 uo-rw,ao=rx,ugo-x 00777 00444 aug+w,o-w 00777 00775 aug+w,o-w 00000 00220 ug=r 00777 00447 ug=r 00000 00440 augo-rw 00000 00000 augo-rw 00777 00111 ag+x,aug+w,au=r 00777 00444 o=r,auo+wx,uo-rw 00777 00171 o=r,auo+wx,uo-rw 00000 00131 ugo-rx,ao+rx,ug+rx 00777 00777 ugo-rx,ao+rx,ug+rx 00000 00555 ao+w,ug-rx 00777 00227 ao+w,ug-rx 00000 00222 a+rwx,go-r 00777 00733 uo=x,ago=wx,ugo+rwx 00777 00777 uo=r 00777 00474 uo=r 00000 00404 o+rw,aug+rx,ugo=rwx 00777 00777 uo-rx 00777 00272 uo-rx 00000 00000 u-rwx,ago+rx 00777 00577 u-rwx,ago+rx 00000 00555 ag-rw,o+w,ug=rx 00777 00553 ag-rw,o+w,ug=rx 00000 00552 u=rw,ago+r,ug=x 00000 00114 u=rw,ago+r,ug=x 00777 00117 aug=w 00777 00222 a=x,ago=rwx,au=rx 00777 00555 ago=rx,ago+x 00777 00555 go-r 00777 00733 go-r 00000 00000 aug=x,augo-rwx,uo+rw 00777 00606 auo-wx,g=rwx,o-x 00000 00070 auo-wx,g=rwx,o-x 00777 00474 auo=rw,uo-rw 00777 00060 go=r 00777 00744 go=r 00000 00044 augo-w,ag-rx 00777 00000 o=w,ag=wx,a=wx 00777 00333 aug=rx 00777 00555 o=w,u-rw 00777 00172 o=w,u-rw 00000 00002 ag-rwx,u=x,o-r 00777 00100 ao+wx,uo=wx 00000 00333 ao+wx,uo=wx 00777 00373 u=wx 00777 00377 u=wx 00000 00300 g-x 00000 00000 g-x 00777 00767 au+rw,o+rx 00000 00667 au+rw,o+rx 00777 00777 ago+x,ug=w,u-x 00000 00221 ago+x,ug=w,u-x 00777 00227 auo+w,au-rwx 00777 00000 ag+rw,ao-rx 00777 00222 ug+w 00777 00777 ug+w 00000 00220 t/basename.t 0000644 00000001560 15125124546 0006756 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; use Cwd; my $IS_WIN32 = $^O eq 'MSWin32'; my @cases = ( [ 'foo.txt', [ '.txt', '.png' ], 'foo' ], [ 'foo.png', [ '.txt', '.png' ], 'foo' ], [ 'foo.txt', [ qr/\.txt/, qr/\.png/ ], 'foo' ], [ 'foo.png', [ qr/\.txt/, qr/\.png/ ], 'foo' ], [ 'foo.txt', ['.jpeg'], 'foo.txt' ], [ 'foo/.txt/bar.txt', [ qr/\.txt/, qr/\.png/ ], 'bar' ], ); for my $c (@cases) { my ( $input, $args, $result ) = @$c; my $path = path($input); my $base = $path->basename(@$args); is( $base, $result, "$path -> $result" ); } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/fakelib/PerlIO/utf8_strict.pm 0000644 00000000070 15125124546 0012354 0 ustar 00 package PerlIO::utf8_strict; 0; # make require fail t/fakelib/Unicode/UTF8.pm 0000644 00000000062 15125124546 0011061 0 ustar 00 package Unicode::UTF8; 0; # make require fail t/mutable_tree_while_iterating.t 0000644 00000002674 15125124546 0013120 0 ustar 00 use strict; use warnings; use Test::More 0.88; use Path::Tiny; use lib 't/lib'; use TestUtils qw/exception tempd/; use Path::Tiny; my $wd = tempd; my @tree = qw( base/Bethlehem/XDG/gift_list.txt base/Vancouver/ETHER/.naughty base/Vancouver/ETHER/gift_list.txt base/New_York/XDG/gift_list.txt ); path($_)->touchpath for @tree; subtest 'iterator' => sub { my @files; my $iter = path('base')->iterator( { recurse => 1 } ); my $exception = exception { while ( my $path = $iter->() ) { $path->remove_tree if $path->child('.naughty')->is_file; push @files, $path if $path->is_file; } }; is( $exception, '', 'can remove directories while traversing' ); is_deeply( [ sort @files ], [ 'base/Bethlehem/XDG/gift_list.txt', 'base/New_York/XDG/gift_list.txt' ], 'remaining files', ); }; subtest 'visit' => sub { my @files; my $exception = exception { path('base')->visit( sub { my $path = shift; $path->remove_tree if $path->child('.naughty')->is_file; push @files, $path if $path->is_file; }, { recurse => 1 }, ); }; is( $exception, '', 'can remove directories while traversing' ); is_deeply( [ sort @files ], [ 'base/Bethlehem/XDG/gift_list.txt', 'base/New_York/XDG/gift_list.txt' ], 'remaining files', ); }; done_testing; t/exports.t 0000644 00000001242 15125124546 0006704 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny qw/path cwd rootdir tempdir tempfile/; isa_ok( path("."), 'Path::Tiny', 'path' ); isa_ok( cwd, 'Path::Tiny', 'cwd' ); isa_ok( rootdir, 'Path::Tiny', 'rootdir' ); isa_ok( tempfile( TEMPLATE => 'tempXXXXXXX' ), 'Path::Tiny', 'tempfile' ); isa_ok( tempdir( TEMPLATE => 'tempXXXXXXX' ), 'Path::Tiny', 'tempdir' ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: t/subsumes.t 0000644 00000006242 15125124546 0007053 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; use Cwd; my $IS_WIN32 = $^O eq 'MSWin32'; my @cases = ( # path1 => path2 => path1->subsumes(path2) "identity always subsumes" => [ [ '.' => '.' => 1 ], [ '/' => '/' => 1 ], [ '..' => '..' => 1 ], [ '../..' => '../..' => 1 ], [ '/foo/' => '/foo' => 1 ], [ 'foo/' => 'foo' => 1 ], [ './foo' => 'foo' => 1 ], [ 'foo/.' => 'foo' => 1 ], ], "absolute v. absolute" => [ [ '/foo' => '/foo/bar' => 1 ], [ '/foo' => '/foo/bar/baz' => 1 ], [ '/foo' => '/foo/bar/baz/' => 1 ], [ '/' => '/foo' => 1 ], [ '/foo' => '/bar' => 0 ], [ '/foo/bar' => '/foo/baz' => 0 ], ], "relative v. relative" => [ [ '.' => 'foo' => 1 ], [ 'foo' => 'foo/baz' => 1 ], [ './foo/bar' => 'foo/bar/baz' => 1 ], [ './foo/bar' => './foo/bar' => 1 ], [ './foo/bar' => 'foo/bar' => 1 ], [ 'foo/bar' => './foo/bar' => 1 ], [ 'foo/bar' => 'foo/baz' => 0 ], ], "relative v. absolute" => [ [ path(".")->absolute => 't' => 1 ], [ "." => path('t')->absolute => 1 ], [ "foo" => path('t')->absolute => 0 ], [ path("..")->realpath => 't' => 1 ], [ path("lib")->absolute => 't' => 0 ], ], "updirs in paths" => [ [ '/foo' => '/foo/bar/baz/..' => 1 ], [ '/foo/bar' => '/foo/bar/../baz' => $IS_WIN32 ? 0 : 1 ], [ '/foo/../bar' => '/bar' => $IS_WIN32 ? 1 : 0 ], [ '..' => '../bar' => 1 ], ], ); if ($IS_WIN32) { my $vol = path( Win32::GetCwd() )->volume . "/"; my $other = $vol ne 'Z:/' ? 'Z:/' : 'Y:/'; push @cases, 'Win32 cases', [ [ "C:/foo" => "C:/foo" => 1 ], [ "C:/foo" => "C:/bar" => 0 ], [ "C:/" => "C:/foo" => 1 ], [ "C:/" => "D:/" => 0 ], [ "${vol}foo" => "/foo" => 1 ], [ $vol => "/foo" => 1 ], [ $vol => $other => 0 ], [ "/" => $vol => 1 ], [ "/" => $other => 0 ], [ "/foo" => "${vol}foo" => 1 ], ]; } while (@cases) { my ( $subtest, $tests ) = splice( @cases, 0, 2 ); subtest $subtest => sub { for my $t (@$tests) { my ( $path1, $path2, $subsumes ) = @$t; my $label = join( " ", $path1, ( $subsumes ? "subsumes" : "does not subsume" ), $path2 ); ok( !!path($path1)->subsumes($path2) eq !!$subsumes, $label ) or diag "PATH 1:\n", explain( path($path1) ), "\nPATH2:\n", explain( path($path2) ); } }; } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/mkdir.t 0000644 00000001760 15125124546 0006313 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Temp (); use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $tempdir = File::Temp->newdir; my $path = path($tempdir)->child("foo"); ok( !-e $path, "target directory not created yet" ); ok( $path->mkdir, "mkdir on directory returned true" ); ok( -d $path, "target directory created" ); ok( $path->mkdir, "mkdir on existing directory returned true" ); if ( $^O ne 'MSWin32' ) { my $path2 = path($tempdir)->child("bar"); ok( !-e $path2, "target directory not created yet" ); ok( $path2->mkdir( { mode => 0700 } ), "mkdir on directory with mode" ); if ( $^O ne 'msys' ) { is( $path2->stat->mode & 0777, 0700, "correct mode" ); } ok( -d $path2, "target directory created" ); } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/basic.t 0000644 00000022101 15125124546 0006256 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Spec; use File::Glob; use Path::Tiny; use Cwd; my $IS_WIN32 = $^O eq 'MSWin32'; my $IS_CYGWIN = $^O eq 'cygwin'; use lib 't/lib'; use TestUtils qw/exception/; my $file1 = path('foo.txt'); isa_ok( $file1, "Path::Tiny" ); ok $file1->isa('Path::Tiny'); is $file1, 'foo.txt'; ok $file1->is_relative; is $file1->dirname, '.'; is $file1->basename, 'foo.txt'; my $file2 = path( 'dir', 'bar.txt' ); is $file2, 'dir/bar.txt'; ok !$file2->is_absolute; is $file2->dirname, 'dir/'; is $file2->basename, 'bar.txt'; my $dir = path('tmp'); is $dir, 'tmp'; ok !$dir->is_absolute; is $dir->basename, 'tmp'; my $dir2 = path('/tmp'); is $dir2, '/tmp'; ok $dir2->is_absolute; my $cat = path( $dir, 'foo' ); is $cat, 'tmp/foo'; $cat = $dir->child('foo'); is $cat, 'tmp/foo'; is $cat->dirname, 'tmp/'; is $cat->basename, 'foo'; $cat = path( $dir2, 'foo' ); is $cat, '/tmp/foo'; $cat = $dir2->child('foo'); is $cat, '/tmp/foo'; isa_ok $cat, 'Path::Tiny'; is $cat->dirname, '/tmp/'; $cat = $dir2->child('foo'); is $cat, '/tmp/foo'; isa_ok $cat, 'Path::Tiny'; is $cat->basename, 'foo'; my $sib = $cat->sibling('bar'); is $sib, '/tmp/bar'; isa_ok $sib, 'Path::Tiny'; my $file = path('/foo//baz/./foo'); is $file, '/foo/baz/foo'; is $file->dirname, '/foo/baz/'; is $file->parent, '/foo/baz'; { my $file = path("foo/bar/baz"); is( $file->canonpath, File::Spec->canonpath("$file"), "canonpath" ); } { my $dir = path('/foo/bar/baz'); is $dir->parent, '/foo/bar'; is $dir->parent->parent, '/foo'; is $dir->parent->parent->parent, '/'; is $dir->parent->parent->parent->parent, '/'; $dir = path('foo/bar/baz'); is $dir->parent, 'foo/bar'; is $dir->parent->parent, 'foo'; is $dir->parent->parent->parent, '.'; is $dir->parent->parent->parent->parent, '..'; is $dir->parent->parent->parent->parent->parent, '../..'; } { my $dir = path("foo/"); is $dir, 'foo'; is $dir->parent, '.'; } { # Special cases for my $bad ( [''], [undef], [], [ '', 'var', 'tmp' ], [ 'foo', '', 'bar' ] ) { like( exception { path(@$bad) }, qr/positive-length/, "exception" ); } is( Path::Tiny->cwd, path( Cwd::getcwd() ) ); is( path('.')->absolute, path( Cwd::getcwd() ) ); } { my $file = path('/tmp/foo/bar.txt'); is $file->relative('/tmp'), 'foo/bar.txt'; is $file->relative('/tmp/foo'), 'bar.txt'; is $file->relative('/tmp/'), 'foo/bar.txt'; is $file->relative('/tmp/foo/'), 'bar.txt'; $file = path('one/two/three'); is $file->relative('one'), 'two/three'; $file = path('/one[0/two'); is $file->relative( '/one[0' ), 'two', 'path with regex special char'; } { my $file = Path::Tiny->new( File::Spec->rootdir ); my $root = Path::Tiny->rootdir; is( $file, $root, "rootdir is like path('/')" ); is( $file->child("lib"), "/lib", "child of rootdir is correct" ); } # constructor { is( path(qw/foo bar baz/), Path::Tiny->new(qw/foo bar baz/), "path() vs new" ); is( path(qw/foo bar baz/), path("foo/bar/baz"), "path(a,b,c) vs path('a/b/c')" ); } # tilde processing { # Construct expected paths manually with glob, but normalize with Path::Tiny # to work around windows slashes and drive case issues. Extract the interior # paths with ->[0] rather than relying on stringification, which will escape # leading tildes. my $homedir = path(glob('~'))->[0]; my $username = path($homedir)->basename; my $root_homedir = path(glob('~root'))->[0]; my $missing_homedir = path(glob('~idontthinkso'))->[0]; # remove one trailing slash from a path string, if present # so the result of concatenating a path that starts with a slash will be correct sub S ($) { ( my $p = $_[0] ) =~ s!/\z!!; $p } my @tests = ( # [arg for path(), expected string (undef if eq arg for path()), test string] ['~', $homedir, 'Test my homedir' ], ['~/', $homedir, 'Test my homedir with trailing "/"' ], ['~/foo/bar', S($homedir).'/foo/bar', 'Test my homedir with longer path' ], ['~/foo/bar/', S($homedir).'/foo/bar', 'Test my homedir, longer path and trailing "/"' ], ['~root', $root_homedir, 'Test root homedir' ], ['~root/', $root_homedir, 'Test root homedir with trailing /' ], ['~root/foo/bar', S($root_homedir).'/foo/bar', 'Test root homedir with longer path' ], ['~root/foo/bar/', S($root_homedir).'/foo/bar', 'Test root homedir, longer path and trailing "/"'], ['~idontthinkso', undef, 'Test homedir of nonexistant user' ], ['~idontthinkso', $missing_homedir, 'Test homedir of nonexistant user (via glob)' ], ['~blah blah', undef, 'Test space' ], ['~this is fun', undef, 'Test multiple spaces' ], ['~yikes \' apostrophe!', undef, 'Test spaces and embedded apostrophe' ], ['~hum " quote', undef, 'Test spaces and embedded quote' ], ['~hello ~there', undef, 'Test space-separated tildes' ], ["~fun\ttimes", undef, 'Test tab' ], ["~new\nline", undef, 'Test newline' ], ['~'.$username.' file', undef, 'Test \'~$username file\'' ], ['./~', '~', 'Test literal tilde under current directory' ], ['~idontthinkso[123]', undef, 'Test File::Glob metacharacter ['], ['~idontthinkso*', undef, 'Test File::Glob metacharacter *'], ['~idontthinkso?', undef, 'Test File::Glob metacharacter ?'], ['~idontthinkso{a}', undef, 'Test File::Glob metacharacter {'], ); if (! $IS_WIN32 && ! $IS_CYGWIN ) { push @tests, ['~idontthinkso\\x', undef, 'Test File::Glob metacharacter \\']; } for my $test (@tests) { my $path = path($test->[0]); my $internal_path = $path->[0]; # Avoid stringification adding a "./" prefix my $expected = defined $test->[1] ? $test->[1] : $test->[0]; is($internal_path, $expected, $test->[2]); is($path, $expected =~ /^~/ ? "./$expected" : $expected, '... and its stringification'); } is(path('.')->child('~')->[0], '~', 'Test indirect form of literal tilde under current directory'); is(path('.')->child('~'), './~', '... and its stringification'); $file = path('/tmp/foo/~root'); is $file->relative('/tmp/foo')->[0], '~root', 'relative path begins with tilde'; is $file->relative('/tmp/foo'), "./~root", '... and its stringification is escaped'; # successful tilde expansion of account names with glob metacharacters is # actually untested so far because it would require such accounts to exist # so instead we wrap File::Glob::bsd_glob to mock up certain responses: my %mock = ( '~i[dont]{think}so' => '/home/i[dont]{think}so', '~idont{think}so' => '/home/idont{think}so', '~i{dont,think}so' => '/home/i{dont,think}so', ); if ( ! $IS_WIN32 && ! $IS_CYGWIN ) { $mock{'~i?dont*think*so?'} = '/home/i?dont*think*so?'; } my $orig_bsd_glob = \&File::Glob::bsd_glob; my $do_brace_expansion_only = do { package File::Glob; GLOB_NOCHECK() | GLOB_BRACE() | GLOB_QUOTE() }; sub mock_bsd_glob { my $dequoted = $orig_bsd_glob->( $_[0], $do_brace_expansion_only ); $mock{ $dequoted } || goto &$orig_bsd_glob; } no warnings 'redefine'; local *File::Glob::bsd_glob = \&mock_bsd_glob; is(File::Glob::bsd_glob('{root}'), 'root', 'double-check of mock_bsd_glob dequoting'); is(File::Glob::bsd_glob('~root'), $root_homedir, 'double-check of mock_bsd_glob fallback'); for my $test (sort keys %mock) { is(path($test), $mock{ $test }, "tilde expansion with glob metacharacters in account name: $test"); } } # freeze/thaw { my @cases = qw( /foo/bar/baz" ./~root ); for my $c ( @cases ) { my $path = path($c); is( Path::Tiny->THAW( "fake", $path->FREEZE("fake") ), $path, "FREEZE-THAW roundtrip: $c" ); } } # assertions { my $err = exception { path("aljfakdlfadks")->assert( sub { $_->exists } ) }; like( $err, qr/failed assertion/, "assert exists" ); my $path; $err = exception { $path = path("t")->assert( sub { -d && -r _ } ) }; is( $err, '', "no exception if assertion succeeds" ); isa_ok( $path, "Path::Tiny", "assertion return value" ); $err = exception { path(".")->visit( sub { $_[1]->{$_} = { path => $_ } }, { recurse => 1 }, ); }; is $err, "", 'no exception'; } done_testing(); t/digest.t 0000644 00000002404 15125124546 0006460 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; use Digest; use Digest::MD5; # for dependency detection my $dir = Path::Tiny->tempdir; my $file = $dir->child('foo.bin'); my $chunk = pack( "Z*", "Hello Path::Tiny\nThis is packed binary string\n" ); ok( $file->spew_raw($chunk), "created test file with packed binary string" ); is( $file->digest, 'a98e605049836e8adb36d351abb95a09e9e5e200703576ecdaec0e697d17d626', 'digest SHA-256 (hardcoded)', ); my $sha = Digest->new('SHA-256'); $sha->add($chunk); my $sha_hex = $sha->hexdigest; is( $file->digest, $sha_hex, 'digest SHA-256' ); is( $file->digest( { chunk_size => 10 } ), $sha_hex, 'digest SHA-256 (chunked)' ); is( $file->digest('MD5'), 'ce05aca61c0e58d7396073b668bcafd0', 'digest MD5 (hardcoded)', ); my $md5 = Digest->new('MD5'); $md5->add($chunk); my $md5_hex = $md5->hexdigest; is( $file->digest('MD5'), $md5_hex, 'digest MD5', ); is( $file->digest( { chunk_size => 10 }, 'MD5' ), $md5_hex, 'digest MD5 (chunked)' ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/locking.t 0000644 00000002576 15125124546 0006641 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Spec; use Cwd; use lib 't/lib'; use TestUtils qw/exception/; use Fcntl ':flock'; use Path::Tiny; { # is temp partition lockable? my $file = Path::Tiny->tempfile; open my $fh, ">>", $file; flock $fh, LOCK_EX or plan skip_all => "Can't lock tempfiles on this OS/filesystem"; } # Guard against external environment local $ENV{PERL_PATH_TINY_NO_FLOCK} = 0; subtest 'write locks blocks read lock' => sub { my $rc = check_flock(); is( $rc >> 8, 0, "subprocess failed to get lock" ); }; subtest 'flock ignored if PERL_PATH_TINY_NO_FLOCK=1' => sub { local $ENV{PERL_PATH_TINY_NO_FLOCK} = 1; my $rc = check_flock(); is( $rc >> 8, 1, "subprocess managed to get lock" ); }; sub check_flock { my $file = Path::Tiny->tempfile; ok $file, "Got a tempfile"; my $fh = $file->openw( { locked => 1 } ); ok $fh, "Opened file for writing with lock"; $fh->autoflush(1); print {$fh} "hello"; # check if a different process can get a lock; use RW mode for AIX my $locktester = Path::Tiny->tempfile; $locktester->spew(<<"HERE"); use strict; use warnings; use Fcntl ':flock'; open my \$fh, "+<", "$file"; exit flock( \$fh, LOCK_SH|LOCK_NB ); HERE my $rc = system( $^X, $locktester ); isnt( $rc, -1, "ran process to try to get lock" ); return $rc; } done_testing; t/input_output.t 0000644 00000044502 15125124546 0007765 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $tmp = Path::Tiny->tempdir; sub _lines { return ( "Line1\r\n", "Line2\n" ); } sub _utf8_lines { my $line3 = "\302\261\n"; utf8::decode($line3); return ( _lines(), $line3 ); } sub _no_end_of_newline_lines { return ( _lines(), "No end of newline" ); } sub _utf8_no_end_of_newline_lines { return ( _utf8_lines(), "No end of newline" ); } subtest "spew -> slurp" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "spew -> slurp (empty)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew, "spew" ); is( $file->slurp, '', "slurp" ); }; subtest "spew -> slurp (arrayref)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew( [_lines] ), "spew" ); is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "spew -> slurp (binmode)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew( { binmode => ":utf8" }, _utf8_lines ), "spew" ); is( $file->slurp( { binmode => ":utf8" } ), join( '', _utf8_lines ), "slurp" ); }; subtest "spew -> slurp (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ":utf8"; my $file = Path::Tiny->tempfile; ok( $file->spew(_utf8_lines), "spew" ); my $got = $file->slurp(); is( $got, join( '', _utf8_lines ), "slurp" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "spew -> slurp (UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_lines), "spew" ); my $got = $file->slurp_utf8(); is( $got, join( '', _utf8_lines ), "slurp" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "spew -> slurp (UTF-8, arrayref)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8( [_utf8_lines] ), "spew" ); my $got = $file->slurp_utf8(); is( $got, join( '', _utf8_lines ), "slurp" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "spew -> slurp (raw)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_raw(_lines), "spew" ); is( $file->slurp_raw, join( '', _lines ), "slurp" ); }; subtest "spew -> lines" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); is( join( '', $file->lines ), join( '', _lines ), "lines" ); is( scalar $file->lines, my $cnt =()= _lines, "lines (scalar)" ); }; subtest "spew -> lines (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ":utf8"; my $file = Path::Tiny->tempfile; ok( $file->spew(_utf8_lines), "spew" ); my $got = join( '', $file->lines() ); is( $got, join( '', _utf8_lines ), "slurp" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "spew -> lines (UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_lines), "spew" ); my $got = join( '', $file->lines_utf8() ); is( $got, join( '', _utf8_lines ), "slurp" ); ok( utf8::is_utf8($got), "is UTF8" ); is( scalar $file->lines, my $cnt =()= _utf8_lines, "lines (scalar)" ); }; subtest "spew -> lines (raw)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_raw(_lines), "spew" ); is( join( '', $file->lines_raw ), join( '', _lines ), "lines" ); }; subtest "spew -> lines (count)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); my @exp = _lines; is( join( '', $file->lines( { count => 2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); is( join( '', $file->lines( { count => -2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); }; subtest "spew -> lines (count, less than)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); my @exp = _lines; is( join( '', $file->lines( { count => 1 } ) ), $exp[0], "lines" ); is( join( '', $file->lines( { count => -1 } ) ), $exp[1], "lines" ); }; subtest "spew -> lines (count, more than)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); my @exp = _lines; is( join( '|', $file->lines( { count => 3 } ) ), join( "|", @exp ), "lines" ); is( join( '|', $file->lines( { count => -3 } ) ), join( "|", @exp ), "lines" ); }; subtest "spew -> lines (count, chomp)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_lines), "spew" ); my @exp = map { s/[\r\n]+//; $_ } _lines; is( join( '', $file->lines( { chomp => 1, count => 2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); is( join( '', $file->lines( { chomp => 1, count => -2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); }; subtest "spew -> lines (count, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_no_end_of_newline_lines), "spew" ); my @exp = _no_end_of_newline_lines; is( join( '', $file->lines( { count => 3 } ) ), join( '', @exp[ 0 .. 2 ] ), "lines" ); is( join( '', $file->lines( { count => -3 } ) ), join( '', @exp[ 0 .. 2 ] ), "lines" ); }; subtest "spew -> lines (count, less than, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_no_end_of_newline_lines), "spew" ); my @exp = _no_end_of_newline_lines; is( join( '', $file->lines( { count => 1 } ) ), $exp[0], "lines" ); is( join( '', $file->lines( { count => -1 } ) ), $exp[2], "lines" ); }; subtest "spew -> lines (count, more than, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_no_end_of_newline_lines), "spew" ); my @exp = _no_end_of_newline_lines; is( join( '|', $file->lines( { count => 4 } ) ), join( "|", @exp ), "lines" ); is( join( '|', $file->lines( { count => -4 } ) ), join( "|", @exp ), "lines" ); }; subtest "spew -> lines (count, chomp, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew(_no_end_of_newline_lines), "spew" ); my @exp = map { s/[\r\n]+//; $_ } _no_end_of_newline_lines; is( join( '', $file->lines( { chomp => 1, count => 3 } ) ), join( '', @exp[ 0 .. 2 ] ), "lines" ); is( join( '', $file->lines( { chomp => 1, count => -3 } ) ), join( '', @exp[ 0 .. 2 ] ), "lines" ); }; subtest "spew -> lines (count, UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_lines), "spew" ); my @exp = _utf8_lines; is( join( '', $file->lines_utf8( { count => 3 } ) ), join( '', @exp ), "lines" ); is( join( '', $file->lines_utf8( { count => -3 } ) ), join( '', @exp ), "lines" ); }; subtest "spew -> lines (count, chomp, UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_lines), "spew" ); my @exp = map { s/[\r\n]+//; $_ } _utf8_lines; is( join( '', $file->lines_utf8( { chomp => 1, count => 2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); is( join( '', $file->lines_utf8( { chomp => 1, count => -2 } ) ), join( '', @exp[ 1 .. 2 ] ), "lines" ); }; subtest "spew -> lines (chomp, only newlines)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew( "\n" x 5 ), "spew" ); my @exp = ('') x 5; is( join( '|', $file->lines_utf8( { chomp => 1 } ) ), join( '|', @exp ), "lines" ); }; subtest "spew -> lines (chomp, UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_lines), "spew" ); my @exp = map { s/[\r\n]+//; $_ } _utf8_lines; is( join( '', $file->lines_utf8( { chomp => 1 } ) ), join( '', @exp ), "lines" ); }; subtest "spew -> lines (count, UTF-8, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_no_end_of_newline_lines), "spew" ); my @exp = _utf8_no_end_of_newline_lines; is( join( '', $file->lines_utf8( { count => 4 } ) ), join( '', @exp ), "lines" ); is( join( '', $file->lines_utf8( { count => -4 } ) ), join( '', @exp ), "lines" ); }; subtest "spew -> lines (count, chomp, UTF-8, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_utf8(_utf8_no_end_of_newline_lines), "spew" ); my @exp = map { s/[\r\n]+//; $_ } _utf8_no_end_of_newline_lines; is( join( '', $file->lines_utf8( { chomp => 1, count => 2 } ) ), join( '', @exp[ 0 .. 1 ] ), "lines" ); is( join( '', $file->lines_utf8( { chomp => 1, count => -2 } ) ), join( '', @exp[ 2 .. 3 ] ), "lines" ); }; subtest "spew -> lines (count, raw)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_raw(_lines), "spew" ); my @exp = _lines; is( join( '', $file->lines_raw( { count => 2 } ) ), join( '', @exp ), "lines" ); is( join( '', $file->lines_raw( { count => -2 } ) ), join( '', @exp ), "lines" ); }; subtest "spew -> lines (count, raw, no end of newline)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew_raw(_no_end_of_newline_lines), "spew" ); my @exp = _no_end_of_newline_lines; is( join( '', $file->lines_raw( { count => 3 } ) ), join( '', @exp ), "lines" ); is( join( '', $file->lines_raw( { count => -3 } ) ), join( '', @exp ), "lines" ); }; subtest "append -> slurp" => sub { my $file = Path::Tiny->tempfile; ok( $file->append(_lines), "append" ); is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "append -> slurp (empty)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append, "append" ); is( $file->slurp, "", "slurp" ); }; subtest "append -> slurp (arrayref)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append( [_lines] ), "append" ); is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "append -> slurp (piecemeal)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append($_), "piecemeal append" ) for _lines; is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "append -> slurp (binmode)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append( { binmode => ":utf8" }, _utf8_lines ), "append" ); is( $file->slurp( { binmode => ":utf8" } ), join( '', _utf8_lines ), "slurp" ); }; subtest "append -> slurp (truncate)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append(_lines), "append" ); is( $file->slurp, join( '', _lines ), "slurp" ); ok( $file->append( { truncate => 1 }, _lines ), "append with truncate" ); is( $file->slurp, join( '', _lines ), "slurp" ); }; subtest "append -> slurp (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ':utf8'; my $file = Path::Tiny->tempfile; ok( $file->append(_utf8_lines), "append" ); is( $file->slurp, join( '', _utf8_lines ), "slurp" ); }; subtest "append -> slurp (UTF-8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append_utf8(_utf8_lines), "append" ); is( $file->slurp_utf8, join( '', _utf8_lines ), "slurp" ); }; subtest "append -> slurp (truncate, UTF8)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append_utf8(_utf8_lines), "append" ); is( $file->slurp_utf8, join( '', _utf8_lines ), "slurp" ); ok( $file->append_utf8( { truncate => 1 }, _utf8_lines ), "append with truncate" ); is( $file->slurp_utf8, join( '', _utf8_lines ), "slurp" ); }; subtest "append -> slurp (raw)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append_raw(_lines), "append" ); is( $file->slurp_raw, join( '', _lines ), "slurp" ); }; subtest "append -> slurp (truncate, raw)" => sub { my $file = Path::Tiny->tempfile; ok( $file->append_raw(_lines), "append" ); is( $file->slurp_raw, join( '', _lines ), "slurp" ); ok( $file->append_raw( { truncate => 1 }, _lines ), "append with truncate" ); is( $file->slurp_raw, join( '', _lines ), "slurp" ); }; subtest "openw -> openr" => sub { my $file = Path::Tiny->tempfile; { my $fh = $file->openw; ok( ( print {$fh} _lines ), "openw & print" ); } { my $fh = $file->openr; my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); } }; subtest "openw -> openr (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ':utf8'; my $file = Path::Tiny->tempfile; { my $fh = $file->openw; ok( ( print {$fh} _utf8_lines ), "openw & print" ); } { my $fh = $file->openr; my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); } }; subtest "openw -> openr (UTF-8)" => sub { my $file = Path::Tiny->tempfile; { my $fh = $file->openw_utf8; ok( ( print {$fh} _utf8_lines ), "openw & print" ); } { my $fh = $file->openr_utf8; my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); } }; subtest "openw -> openr (raw)" => sub { my $file = Path::Tiny->tempfile; { my $fh = $file->openw_raw; ok( ( print {$fh} _lines ), "openw & print" ); } { my $fh = $file->openr_raw; my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); } }; subtest "opena -> openr" => sub { my $file = Path::Tiny->tempfile; my @lines = _lines; { my $fh = $file->openw; ok( ( print {$fh} shift @lines ), "openw & print one line" ); } { my $fh = $file->opena; ok( ( print {$fh} @lines ), "opena & print rest of lines" ); } { my $fh = $file->openr; my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); } }; subtest "opena -> openr (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ':utf8'; my $file = Path::Tiny->tempfile; my @lines = _utf8_lines; { my $fh = $file->openw; ok( ( print {$fh} shift @lines ), "openw & print one line" ); } { my $fh = $file->opena; ok( ( print {$fh} @lines ), "opena & print rest of lines" ); } { my $fh = $file->openr; my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); } }; subtest "opena -> openr (UTF-8)" => sub { my $file = Path::Tiny->tempfile; my @lines = _utf8_lines; { my $fh = $file->openw_utf8; ok( ( print {$fh} shift @lines ), "openw & print one line" ); } { my $fh = $file->opena_utf8; ok( ( print {$fh} @lines ), "opena & print rest of lines" ); } { my $fh = $file->openr_utf8; my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); } }; subtest "opena -> openr (raw)" => sub { my $file = Path::Tiny->tempfile; my @lines = _lines; { my $fh = $file->openw_raw; ok( ( print {$fh} shift @lines ), "openw & print one line" ); } { my $fh = $file->opena_raw; ok( ( print {$fh} @lines ), "opena & print rest of lines" ); } { my $fh = $file->openr_raw; my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); } }; subtest "openrw" => sub { my $file = Path::Tiny->tempfile; my $fh = $file->openrw; ok( ( print {$fh} _lines ), "openrw & print" ); ok( seek( $fh, 0, 0 ), "seek back to start" ); my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); }; subtest "openrw (open hint)" => sub { plan skip_all => "Needs 5.10" unless $] >= 5.010; use open IO => ':utf8'; my $file = Path::Tiny->tempfile; my $fh = $file->openrw; ok( ( print {$fh} _utf8_lines ), "openrw & print" ); ok( seek( $fh, 0, 0 ), "seek back to start" ); my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "openrw (UTF-8)" => sub { my $file = Path::Tiny->tempfile; my $fh = $file->openrw_utf8; ok( ( print {$fh} _utf8_lines ), "openrw & print" ); ok( seek( $fh, 0, 0 ), "seek back to start" ); my $got = do { local $/, <$fh> }; is( $got, join( '', _utf8_lines ), "openr & read" ); ok( utf8::is_utf8($got), "is UTF8" ); }; subtest "openrw (raw)" => sub { my $file = Path::Tiny->tempfile; my $fh = $file->openrw_raw; ok( ( print {$fh} _lines ), "openrw & print" ); ok( seek( $fh, 0, 0 ), "seek back to start" ); my $got = do { local $/, <$fh> }; is( $got, join( '', _lines ), "openr & read" ); }; subtest "edit_utf8" => sub { my $file = Path::Tiny->tempfile; $file->spew_utf8(_utf8_lines); $file->edit_utf8( sub { s/^Line/Row/gm; } ); my $line3 = "\302\261\n"; utf8::decode($line3); is( $file->slurp_utf8, ("Row1\r\nRow2\n$line3"), "edit_utf8", ); }; subtest "edit_raw" => sub { my $file = Path::Tiny->tempfile; $file->spew_raw("Foo Bar\nClam Bar\n"); $file->edit_raw( sub { s/Bar/Mangle/; } ); is( $file->slurp_raw, "Foo Mangle\nClam Bar\n", "edit_raw", ); }; subtest "edit" => sub { my $file = Path::Tiny->tempfile; $file->spew_raw("One line\nTwo lines\nThree lines\n"); $file->edit( sub { s/line/row/; }, { binmode => ':raw' }, ); is( $file->slurp_raw, "One row\nTwo lines\nThree lines\n", "edit() was successful.", ); }; subtest "edit_lines_utf8" => sub { my $file = Path::Tiny->tempfile; $file->spew_utf8("Foo\nBar\nBaz\nQuux\n"); $file->edit_lines_utf8( sub { s/\A/prefix = /gm; } ); is( $file->slurp_utf8, ("prefix = Foo\nprefix = Bar\nprefix = Baz\nprefix = Quux\n"), "edit_lines_utf8", ); }; subtest "edit_lines_raw" => sub { my $file = Path::Tiny->tempfile; $file->spew_raw("Foo\nBar\nBaz\nQuux\n"); $file->edit_lines_raw( sub { s/\A/prefix = /gm; } ); is( $file->slurp_raw, ("prefix = Foo\nprefix = Bar\nprefix = Baz\nprefix = Quux\n"), "edit_lines_utf8", ); }; subtest "edit_lines" => sub { my $file = Path::Tiny->tempfile; $file->spew_raw("Foo\nBar\nBaz\nQuux\n"); $file->edit_lines( sub { s/a/[replacement]/; }, { binmode => ':raw' } ); is( $file->slurp_raw, ("Foo\nB[replacement]r\nB[replacement]z\nQuux\n"), "edit_lines", ); }; done_testing; 1; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/sig_die.t 0000644 00000001025 15125124546 0006602 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Temp qw(tmpnam); use Path::Tiny; use lib 't/fakelib'; my $file = path( scalar tmpnam() ); ok $file, 'Got a filename via tmpnam()'; { my $fh = $file->openw; ok $fh, "Opened $file for writing"; ok print( $fh "Foo\n" ), "Printed to $file"; } my $called_handler; { local $SIG{__DIE__} = sub { ++$called_handler }; $file->slurp_utf8; } ok !$called_handler, 'outer $SIG{__DIE__} handler should not be called'; unlink $file; done_testing; t/input_output_no_UU.t 0000644 00000001066 15125124546 0011070 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; # Tiny equivalent of Devel::Hide # Tiny equivalent of Devel::Hide use lib map { my ( $m, $c ) = ( $_, qq{die "Can't locate $_ (hidden)\n"} ); sub { return unless $_[1] eq $m; open my $fh, "<", \$c; return $fh } } qw{Unicode/UTF8.pm}; note "Hiding Unicode::UTF8"; do "./t/input_output.t" or die $@ || $!; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/children.t 0000644 00000002372 15125124546 0006775 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Basename (); use File::Temp (); use File::Spec::Unix; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $tempdir = File::Temp->newdir; my @kids = qw/apple banana carrot/; path($tempdir)->child($_)->touch for @kids; my @expected = map { path( File::Spec::Unix->catfile( $tempdir, $_ ) ) } @kids; is_deeply( [ sort { $a cmp $b } path($tempdir)->children ], [ sort @expected ], "children correct" ); my $regexp = qr/.a/; is_deeply( [ sort { $a cmp $b } path($tempdir)->children($regexp) ], [ sort grep { my $child = File::Basename::basename($_); $child =~ /$regexp/ } @expected ], "children correct with Regexp argument" ); my $arrayref = []; eval { path($tempdir)->children($arrayref) }; like $@, qr/Invalid argument '\Q$arrayref\E' for children()/, 'children with invalid argument'; my $raw_tilde = path(".", "~"); my $tilde_child = $raw_tilde->child("rhubarb"); is( $tilde_child, "./~/rhubarb", "child of literal tilde" ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/00-report-prereqs.dd 0000644 00000011026 15125124546 0010534 0 ustar 00 do { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.17', 'perl' => '5.008001' }, 'suggests' => { 'JSON::PP' => '2.27300' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::Plugin::MinimumPerl' => '0', 'Dist::Zilla::Plugin::OnlyCorePrereqs' => '0', 'Dist::Zilla::Plugin::Prereqs' => '0', 'Dist::Zilla::Plugin::ReleaseStatus::FromVersion' => '0', 'Dist::Zilla::Plugin::RemovePrereqs' => '0', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.072', 'File::Spec' => '0', 'File::Temp' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Coverage::TrustPod' => '0', 'Pod::Wordlist' => '0', 'Software::License::Apache_2_0' => '0', 'Test::CPAN::Meta' => '0', 'Test::MinimumVersion' => '0', 'Test::More' => '0', 'Test::Perl::Critic' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Portability::Files' => '0', 'Test::Spelling' => '0.12', 'Test::Version' => '1' } }, 'runtime' => { 'recommends' => { 'Unicode::UTF8' => '0.58' }, 'requires' => { 'Carp' => '0', 'Cwd' => '0', 'Digest' => '1.03', 'Digest::SHA' => '5.45', 'Encode' => '0', 'Exporter' => '5.57', 'Fcntl' => '0', 'File::Compare' => '0', 'File::Copy' => '0', 'File::Glob' => '0', 'File::Path' => '2.07', 'File::Spec' => '0.86', 'File::Temp' => '0.19', 'File::stat' => '0', 'constant' => '0', 'overload' => '0', 'perl' => '5.008001', 'strict' => '0', 'warnings' => '0', 'warnings::register' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900', 'Test::FailWarnings' => '0', 'Test::MockRandom' => '0' }, 'requires' => { 'Digest::MD5' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Basename' => '0', 'File::Spec' => '0.86', 'File::Spec::Functions' => '0', 'File::Spec::Unix' => '0', 'File::Temp' => '0.19', 'Test::More' => '0.96', 'lib' => '0', 'open' => '0', 'perl' => '5.008001' } } }; $x; } t/00-report-prereqs.t 0000644 00000013601 15125124546 0010411 0 ustar 00 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.029 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if grep { $_ eq $mod } @exclude; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; if ($mod eq 'perl') { push @reports, ['perl', $want, $]]; next; } my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: t/size.t 0000644 00000011415 15125124546 0006155 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception tempd/; use Path::Tiny; subtest "size API tests" => sub { my $wd = tempd(); my $path = path("1025"); $path->spew( "A" x 1025 ); is( $path->size, -s $path, "size() is -s" ); is( $path->size_human, "1.1 K", "size_human() is 1.1 K" ); }; subtest "size_human format" => sub { my $wd = tempd(); my $base2 = path("1024"); $base2->spew( "A" x 1024 ); my $base10 = path("1000"); $base10->spew( "A" x 1000 ); is( $base2->size_human, "1.0 K", "default" ); is( $base2->size_human( { format => "ls" } ), "1.0 K", "explicit ls" ); is( $base2->size_human( { format => "iec" } ), "1.0 KiB", "iec" ); is( $base10->size_human( { format => "si" } ), "1.0 kB", "si" ); is( path("doesnotexist")->size_human, "", "missing file" ); like( exception { $base2->size_human( { format => "fake" } ) }, qr/Invalid format 'fake'/, "bad format exception" ); }; # The rest of the tests use the private function for size conversion # rather than actually creating files of each size. Test cases were # derived from actual `ls -lh` output on Ubuntu 20.04. my $kib = 1024; my %ls_tests = ( 0 => "0", $kib - 1 => "1023", $kib => "1.0 K", $kib + 1 => "1.1 K", int( 1.1 * $kib ) => "1.1 K", int( 1.1 * $kib ) + 1 => "1.2 K", int( 1.9 * $kib ) => "1.9 K", int( 1.9 * $kib ) + 1 => "2.0 K", 9 * $kib => "9.0 K", 9 * $kib + 1 => "9.1 K", int( 9.9 * $kib ) => "9.9 K", int( 9.9 * $kib ) + 1 => "10 K", 10 * $kib => "10 K", 10 * $kib + 1 => "11 K", ( $kib - 1 ) * $kib => "1023 K", ( $kib - 1 ) * $kib + 1 => "1.0 M", $kib**2 - 1 => "1.0 M", $kib**2 => "1.0 M", $kib**2 + 1 => "1.1 M", int( 1.1 * $kib**2 ) => "1.1 M", int( 1.1 * $kib**2 ) + 1 => "1.2 M", int( 1.9 * $kib**2 ) => "1.9 M", int( 1.9 * $kib**2 ) + 1 => "2.0 M", 9 * $kib**2 => "9.0 M", 9 * $kib**2 + 1 => "9.1 M", int( 9.9 * $kib**2 ) => "9.9 M", int( 9.9 * $kib**2 ) + 1 => "10 M", 10 * $kib**2 => "10 M", 10 * $kib**2 + 1 => "11 M", ( $kib - 1 ) * $kib**2 => "1023 M", ( $kib - 1 ) * $kib**2 + 1 => "1.0 G", ); subtest "ls format" => sub { for my $k ( sort { $a <=> $b } keys %ls_tests ) { my $opts = Path::Tiny::_formats("ls"); my $got = Path::Tiny::_human_size( $k, @$opts ); is( $got, $ls_tests{$k}, "ls: $k" ); } }; subtest "iec format" => sub { for my $k ( sort { $a <=> $b } keys %ls_tests ) { my $opts = Path::Tiny::_formats("iec"); my $got = Path::Tiny::_human_size( $k, @$opts ); my $want = $ls_tests{$k}; $want .= "iB" if $want =~ /[a-z]/i; is( $got, $want, "iec: $k" ); } }; my $kb = 1000; my %si_tests = ( 0 => "0", $kb - 1 => "999", $kb => "1.0 kB", $kb + 1 => "1.1 kB", int( 1.1 * $kb ) => "1.1 kB", int( 1.1 * $kb ) + 1 => "1.2 kB", int( 1.9 * $kb ) => "1.9 kB", int( 1.9 * $kb ) + 1 => "2.0 kB", 9 * $kb => "9.0 kB", 9 * $kb + 1 => "9.1 kB", int( 9.9 * $kb ) => "9.9 kB", int( 9.9 * $kb ) + 1 => "10 kB", 10 * $kb => "10 kB", 10 * $kb + 1 => "11 kB", ( $kb - 1 ) * $kb => "999 kB", ( $kb - 1 ) * $kb + 1 => "1.0 MB", $kb**2 - 1 => "1.0 MB", $kb**2 => "1.0 MB", $kb**2 + 1 => "1.1 MB", int( 1.1 * $kb**2 ) => "1.1 MB", int( 1.1 * $kb**2 ) + 1 => "1.2 MB", int( 1.9 * $kb**2 ) => "1.9 MB", int( 1.9 * $kb**2 ) + 1 => "2.0 MB", 9 * $kb**2 => "9.0 MB", 9 * $kb**2 + 1 => "9.1 MB", int( 9.9 * $kb**2 ) => "9.9 MB", int( 9.9 * $kb**2 ) + 1 => "10 MB", 10 * $kb**2 => "10 MB", 10 * $kb**2 + 1 => "11 MB", ( $kb - 1 ) * $kb**2 => "999 MB", ( $kb - 1 ) * $kb**2 + 1 => "1.0 GB", ); subtest "si format" => sub { for my $k ( sort { $a <=> $b } keys %si_tests ) { my $opts = Path::Tiny::_formats("si"); my $got = Path::Tiny::_human_size( $k, @$opts ); is( $got, $si_tests{$k}, "si: $k" ); } }; done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/zzz-spec.t 0000644 00000015174 15125124546 0006776 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; use Cwd; my $IS_WIN32 = $^O eq 'MSWin32'; # tests adapted from File::Spec's t/Spec.t test # Each element in this array is a single test. Storing them this way makes # maintenance easy, and should be OK since perl should be pretty functional # before these tests are run. # the third column has Win32 specific alternative output; this appears to be # collapsing of foo/../bar type structures since Win32 has no symlinks and # doesn't need to keep the '..' part. -- xdg, 2013-01-30 my @tests = ( # [ Function , Expected , Win32-different ] [ "path('a','b','c')", 'a/b/c' ], [ "path('a','b','./c')", 'a/b/c' ], [ "path('./a','b','c')", 'a/b/c' ], [ "path('c')", 'c' ], [ "path('./c')", 'c' ], [ "path('/')", '/' ], [ "path('d1','d2','d3')", 'd1/d2/d3' ], [ "path('/','d2/d3')", '/d2/d3' ], [ "path('/.')", '/' ], [ "path('/./')", '/' ], [ "path('/a/./')", '/a' ], [ "path('/a/.')", '/a' ], [ "path('/../../')", '/' ], [ "path('/../..')", '/' ], [ "path('/t1/t2/t4')->relative('/t1/t2/t3')", '../t4' ], [ "path('/t1/t2')->relative('/t1/t2/t3')", '..' ], [ "path('/t1/t2/t3/t4')->relative('/t1/t2/t3')", 't4' ], [ "path('/t4/t5/t6')->relative('/t1/t2/t3')", '../../../t4/t5/t6' ], [ "path('/')->relative('/t1/t2/t3')", '../../..' ], [ "path('///')->relative('/t1/t2/t3')", '../../..' ], [ "path('/.')->relative('/t1/t2/t3')", '../../..' ], [ "path('/./')->relative('/t1/t2/t3')", '../../..' ], [ "path('/t1/t2/t3')->relative( '/')", 't1/t2/t3' ], [ "path('/t1/t2/t3')->relative( '/t1')", 't2/t3' ], [ "path('t1/t2/t3')->relative( 't1')", 't2/t3' ], [ "path('t1/t2/t3')->relative( 't4')", '../t1/t2/t3' ], [ "path('.')->relative( '.')", '.' ], [ "path('/')->relative( '/')", '.' ], [ "path('../t1')->relative( 't2/t3')", '../../../t1' ], [ "path('t1')->relative( 't2/../t3')", '../t1' ], [ "path('t4')->absolute('/t1/t2/t3')", '/t1/t2/t3/t4' ], [ "path('t4/t5')->absolute('/t1/t2/t3')", '/t1/t2/t3/t4/t5' ], [ "path('.')->absolute('/t1/t2/t3')", '/t1/t2/t3' ], [ "path('///../../..//./././a//b/.././c/././')", '/a/b/../c', '/a/c' ], [ "path('a/../../b/c')", 'a/../../b/c', '../b/c' ], [ "path('..')->absolute('/t1/t2/t3')", '/t1/t2/t3/..', '/t1/t2' ], [ "path('../t4')->absolute('/t1/t2/t3')", '/t1/t2/t3/../t4', '/t1/t2/t4' ], # need to wash through rootdir->absolute->child to pick up volume on Windows [ "path('/t1')->absolute('/t1/t2/t3')", Path::Tiny->rootdir->absolute->child("t1") ], ); my @win32_tests; # this is lazy so we don't invoke any calls unless we're on Windows if ($IS_WIN32) { @win32_tests = ( [ "path('/')", '/' ], [ "path('/', '../')", '/' ], [ "path('/', '..\\')", '/' ], [ "path('\\', '../')", '/' ], [ "path('\\', '..\\')", '/' ], [ "path('\\d1\\','d2')", '/d1/d2' ], [ "path('\\d1','d2')", '/d1/d2' ], [ "path('\\d1','\\d2')", '/d1/d2' ], [ "path('\\d1','\\d2\\')", '/d1/d2' ], [ "path('d1','d2','d3')", 'd1/d2/d3' ], [ "path('\\', 'foo')", '/foo' ], [ "path('a','b','c')", 'a/b/c' ], [ "path('a','b','.\\c')", 'a/b/c' ], [ "path('.\\a','b','c')", 'a/b/c' ], [ "path('c')", 'c' ], [ "path('.\\c')", 'c' ], [ "path('a/..','../b')", '../b' ], [ "path('a\\..\\..\\b\\c')", '../b/c' ], [ "path('//a\\b//c')", '//a/b/c' ], [ "path('/a/..../c')", '/a/..../c' ], [ "path('//a/b\\c')", '//a/b/c' ], [ "path('////')", '/' ], [ "path('//')", '/' ], [ "path('/.')", '/' ], [ "path('//a/b/../../c')", '//a/b/c' ], [ "path('//a/b/c/../d')", '//a/b/d' ], [ "path('//a/b/c/../../d')", '//a/b/d' ], [ "path('/a/b/c/../../d')", '/a/d' ], [ "path('\\../temp\\')", '/temp' ], [ "path('\\../')", '/' ], [ "path('\\..\\')", '/' ], [ "path('/../')", '/' ], [ "path('/../')", '/' ], [ "path('d1/../foo')", 'foo' ], # if there's no C drive, getdcwd will probably return '', so fake it [ "path('C:')", path( eval { Cwd::getdcwd("C:") } || "C:/" ) ], [ "path('\\\\server\\share\\')", '//server/share/' ], [ "path('\\\\server\\share')", '//server/share/' ], [ "path('//server/share/')", '//server/share/' ], [ "path('//server/share')", '//server/share/' ], [ "path('//d1','d2')", '//d1/d2/' ], ); # These test require no "A:" drive mapped my $drive_a_cwd = Cwd::getdcwd("A:"); $drive_a_cwd = "" unless defined $drive_a_cwd; if ( $drive_a_cwd eq "" ) { push @win32_tests, [ "path('A:/d1','d2','d3')", 'A:/d1/d2/d3' ], [ "path('A:/')", 'A:/' ], [ "path('A:', 'foo')", 'A:/foo' ], [ "path('A:', 'foo')", 'A:/foo' ], [ "path('A:f')", 'A:/f' ], [ "path('A:/')", 'A:/' ], [ "path('a:/')", 'A:/' ],; } } # Tries a named function with the given args and compares the result against # an expected result. Works with functions that return scalars or arrays. for ( @tests, $IS_WIN32 ? @win32_tests : () ) { my ( $function, $expected, $win32case ) = @$_; $expected = $win32case if $IS_WIN32 && $win32case; $function =~ s#\\#\\\\#g; my $got = join ',', eval $function; if ($@) { is( $@, '', $function ); } else { is( $got, $expected, $function ); } } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/overloading.t 0000644 00000001026 15125124546 0007511 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $path = path("t/stringify.t"); is( "$path", "t/stringify.t", "stringify via overloading" ); is( $path->stringify, "t/stringify.t", "stringify via method" ); ok( $path, "boolifies to true" ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/normalize.t 0000644 00000001602 15125124546 0007200 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my @cases = ( #<<< [ '.' => '.' ], [ './' => '.' ], [ '/' => '/' ], [ '/.' => '/' ], [ '..' => '..' ], [ '/..' => '/' ], [ '../' => '..' ], [ '../..' => '../..' ], [ '/./' => '/' ], [ '/foo/' => '/foo' ], [ 'foo/' => 'foo' ], [ './foo' => 'foo' ], [ 'foo/.' => 'foo' ], #>>> ); for my $c (@cases) { my ( $in, $out ) = @$c; my $label = defined($in) ? $in : "undef"; $label = "empty" unless length $label; is( path($in)->stringify, $out, sprintf( "%5s -> %-5s", $label, $out ) ); } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/input_output_no_PU_UU.t 0000644 00000001103 15125124546 0011464 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; # Tiny equivalent of Devel::Hide use lib map { my ( $m, $c ) = ( $_, qq{die "Can't locate $_ (hidden)\n"} ); sub { return unless $_[1] eq $m; open my $fh, "<", \$c; return $fh } } qw{Unicode/UTF8.pm PerlIO/utf8_strict.pm}; note "Hiding Unicode::UTF8 and PerlIO::utf8_strict"; do "./t/input_output.t" or die $@ || $!; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/visit.t 0000644 00000000677 15125124546 0006351 0 ustar 00 use strict; use warnings; use Test::More tests => 3; use Path::Tiny; path('t')->visit(sub{ return [ ] }); pass "visit callback doesn't choke on random returned refs"; my $all; my $terminated; path('t')->visit(sub{ $all++ }); path('t')->visit(sub{ $terminated++; return \0 if $terminated == 10 }); is $terminated => 10, "terminated before the whole dir was read"; cmp_ok $all, '>=', $terminated, "we have more than 10 tests in that dir"; t/mkpath.t 0000644 00000001663 15125124546 0006473 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Temp (); use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $tempdir = File::Temp->newdir; my $path = path($tempdir)->child("foo"); ok( !-e $path, "target directory not created yet" ); ok( $path->mkpath, "mkpath on directory returned true" ); ok( -d $path, "target directory created" ); if ( $^O ne 'MSWin32' ) { my $path2 = path($tempdir)->child("bar"); ok( !-e $path2, "target directory not created yet" ); ok( $path2->mkpath( { mode => 0700 } ), "mkpath on directory with mode" ); if ( $^O ne 'msys' ) { is( $path2->stat->mode & 0777, 0700, "correct mode" ); } ok( -d $path2, "target directory created" ); } done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/exception.t 0000644 00000002414 15125124546 0007200 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; my $err; $err = exception { path("aljfakdlfadks")->slurp }; like( $err, qr/at \Q$0\E/, "exception reported at caller's package" ); for my $m (qw/append iterator lines lines_raw lines_utf8 slurp spew/) { $err = exception { path("foo")->$m( { wibble => 1 } ) }; like( $err, qr/Invalid option\(s\) for $m: wibble/, "$m bad args" ); } $err = exception { path("foo")->visit( sub { 1 }, { wibble => 1 } ); }; like( $err, qr/Invalid option\(s\) for visit: wibble/, "visit bad args" ); # exclude append/spew because they handle hash/not-hash themselves my $scalar = [qw/array ref/]; for my $m (qw/iterator lines lines_raw lines_utf8 slurp/) { $err = exception { path("foo")->$m($scalar) }; like( $err, qr/Options for $m must be a hash reference/, "$m not hashref" ); } $err = exception { path("foo")->visit( sub { 1 }, $scalar ); }; like( $err, qr/Options for visit must be a hash reference/, "visit not hashref" ); done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: t/zz-atomic.t 0000644 00000001632 15125124546 0007120 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; BEGIN { plan skip_all => "Can't mock random() with Path::Tiny already loaded" if $INC{'Path/Tiny.pm'}; eval "use Test::MockRandom 'Path::Tiny';"; plan skip_all => "Test::MockRandom required for atomicity tests" if $@; } use lib 't/lib'; use TestUtils qw/exception/; use Path::Tiny; srand(0); subtest "spew (atomic)" => sub { my $file = Path::Tiny->tempfile; ok( $file->spew("original"), "spew" ); is( $file->slurp, "original", "original file" ); my $tmp = $file->[Path::Tiny::PATH] . $$ . "0"; open my $fh, ">", $tmp; ok( $fh, "opened collision file '$tmp'" ); print $fh "collide!"; close $fh; my $error = exception { ok( $file->spew("overwritten"), "spew" ) }; ok( $error, "spew errors if the temp file exists" ); is( $file->slurp(), "original", "original file intact" ); }; done_testing(); t/temp.t 0000644 00000011763 15125124546 0006156 0 ustar 00 use 5.008001; use strict; use warnings; use Cwd; # hack around https://bugs.activestate.com/show_bug.cgi?id=104767 use Test::More 0.96; use File::Spec::Unix; use lib 't/lib'; use TestUtils qw/exception tempd/; use Path::Tiny; subtest "tempdir" => sub { my $tempdir = Path::Tiny->tempdir; isa_ok( $tempdir->cached_temp, 'File::Temp::Dir', "cached_temp" ); my $string = $tempdir->stringify; ok( $tempdir->exists, "tempdir exists" ); undef $tempdir; ok( !-e $string, "tempdir destroyed" ); }; subtest "tempfile" => sub { my $tempfile = Path::Tiny->tempfile; isa_ok( $tempfile->cached_temp, 'File::Temp', "cached_temp" ); my $string = $tempfile->stringify; ok( $tempfile->exists, "tempfile exists" ); undef $tempfile; ok( !-e $string, "tempfile destroyed" ); }; subtest "tempdir w/ TEMPLATE" => sub { my $tempdir = Path::Tiny->tempdir( TEMPLATE => "helloXXXXX" ); like( $tempdir, qr/hello/, "found template" ); }; subtest "tempfile w/ TEMPLATE" => sub { my $tempfile = Path::Tiny->tempfile( TEMPLATE => "helloXXXXX" ); like( $tempfile, qr/hello/, "found template" ); }; subtest "tempdir w/ leading template" => sub { my $tempdir = Path::Tiny->tempdir("helloXXXXX"); like( $tempdir, qr/hello/, "found template" ); }; subtest "tempfile w/ leading template" => sub { my $tempfile = Path::Tiny->tempfile("helloXXXXX"); like( $tempfile, qr/hello/, "found template" ); }; subtest "tempfile handle" => sub { my $tempfile = Path::Tiny->tempfile; my $fh = $tempfile->filehandle; is( ref $tempfile->[5], 'File::Temp', "cached File::Temp object" ); is( fileno $tempfile->[5], undef, "cached handle is closed" ); }; subtest "survives absolute" => sub { my $wd = tempd; my $tempdir = Path::Tiny->tempdir( DIR => '.' )->absolute; ok( -d $tempdir, "exists" ); }; subtest "realpath option" => sub { my $wd = tempd; my $tempdir = Path::Tiny->tempdir( { realpath => 1 }, DIR => '.' ); is( $tempdir, $tempdir->realpath, "tempdir has realpath" ); my $tempfile = Path::Tiny->tempfile( { realpath => 1 }, DIR => '.' ); is( $tempfile, $tempfile->realpath, "tempfile has realpath" ); }; subtest "cached_temp on non tempfile" => sub { my $path = path("abcdefg"); eval { $path->cached_temp }; like( $@, qr/has no cached File::Temp object/, "cached_temp error message" ); }; subtest "tempdir w/ leading template as instance method" => sub { my $wd = tempd; my $basedir = Path::Tiny->cwd; my $repodir = $basedir->child('whatever'); $repodir->remove_tree if $repodir->exists; $repodir->mkdir; my $tempdir = $repodir->tempdir("helloXXXXX"); like( $tempdir, qr/hello/, "found template" ); ok( scalar($repodir->children) > 0, 'something was created' ); my $basename = $tempdir->basename; ok( -d $repodir->child($basename), "right directory exists" ); }; subtest "tempdir w/ leading template as instance method" => sub { my $wd = tempd; my $basedir = Path::Tiny->cwd; my $repodir = $basedir->child('whatever'); $repodir->remove_tree if $repodir->exists; $repodir->mkdir; my $tempdir = $repodir->tempdir("helloXXXXX"); like( $tempdir, qr/hello/, "found template" ); ok( scalar($repodir->children) > 0, 'something was created' ); my $basename = $tempdir->basename; ok( -d $repodir->child($basename), "right directory exists" ); }; subtest "tempfile w/out leading template as instance method" => sub { my $wd = tempd; my $basedir = Path::Tiny->cwd; my $repodir = $basedir->child('whatever'); $repodir->remove_tree if $repodir->exists; $repodir->mkdir; my $tempfile = $repodir->tempfile( TEMPLATE => "helloXXXXX" ); like( $tempfile, qr/hello/, "found template" ); ok( scalar($repodir->children) > 0, 'something was created' ); my $basename = $tempfile->basename; ok( -e $repodir->child($basename), "right file exists" ); }; subtest "tempfile w/out leading template as instance method" => sub { my $wd = tempd; my $basedir = Path::Tiny->cwd; my $repodir = $basedir->child('whatever'); $repodir->remove_tree if $repodir->exists; $repodir->mkdir; my $tempfile = $repodir->tempfile( TEMPLATE => "helloXXXXX"); like( $tempfile, qr/hello/, "found template" ); ok( scalar($repodir->children) > 0, 'something was created' ); my $basename = $tempfile->basename; ok( -e $repodir->child($basename), "right file exists" ); }; subtest "tempfile, instance method, overridden DIR" => sub { my $wd = tempd; my $basedir = Path::Tiny->cwd; my $repodir = $basedir->child('whatever'); $repodir->remove_tree if $repodir->exists; $repodir->mkdir; my $bd = $basedir->stringify; my $tempfile = $repodir->tempfile("helloXXXXX", DIR => $bd); ok( $tempfile->parent ne $bd ), "DIR is overridden"; }; done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # t/filesystem.t 0000644 00000033506 15125124546 0007374 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use File::Temp qw(tmpnam tempdir); use File::Spec; use Cwd; use lib 't/lib'; use TestUtils qw/exception has_symlinks/; use Path::Tiny; # Tests adapted from Path::Class t/basic.t my $file = path( scalar tmpnam() ); ok $file, "Got a filename via tmpnam()"; { my $fh = $file->openw; ok $fh, "Opened $file for writing"; ok print( $fh "Foo\n" ), "Printed to $file"; } ok -e $file, "$file should exist"; ok $file->is_file, "it's a file!"; if ( -e "/dev/null" ) { ok( path("/dev/null")->is_file, "/dev/null is_file, too" ); } my ( $volume, $dirname, $basename ) = map { s{\\}{/}; $_ } File::Spec->splitpath($file); is( $file->volume, $volume, "volume correct" ); is( $file->volume, $volume, "volume cached " ); # for coverage is( $file->dirname, $dirname, "dirname correct" ); is( $file->basename, $basename, "basename correct" ); { my $fh = $file->openr; is scalar <$fh>, "Foo\n", "Read contents of $file correctly"; } note "stat"; { my $stat = $file->stat; ok $stat; cmp_ok $stat->mtime, '>', time() - 20; # Modified within last 20 seconds $stat = $file->parent->stat; ok $stat; } note "stat/lstat with no file"; { my $file = "i/do/not/exist"; ok exception { path($file)->stat }; ok exception { path($file)->lstat }; } 1 while unlink $file; ok not -e $file; my $dir = path( tempdir( TMPDIR => 1, CLEANUP => 1 ) ); ok $dir; ok -d $dir; ok $dir->is_dir, "It's a directory!"; $file = $dir->child('foo.x'); $file->touch; ok -e $file; my $epoch = time - 10; utime $epoch, $epoch, $file; $file->touch; ok( $file->stat->mtime > $epoch, "touch sets utime as current time" ); $file->touch($epoch); ok( $file->stat->mtime == $epoch, "touch sets utime as 10 secs before" ); { my @files = $dir->children; is scalar @files, 1 or diag explain \@files; ok scalar grep { /foo\.x/ } @files; } ok $dir->remove_tree, "Removed $dir"; ok !-e $dir, "$dir no longer exists"; ok !$dir->remove_tree, "Removing non-existent dir returns false"; my $tmpdir = Path::Tiny->tempdir; { $dir = path( $tmpdir, 'foo', 'bar' ); $dir->parent->remove_tree if -e $dir->parent; ok $dir->mkdir, "Created $dir"; ok -d $dir, "$dir is a directory"; $dir = $dir->parent; ok $dir->remove_tree( { safe => 1 } ); # check that we pass through args ok !-e $dir; } { $dir = path( $tmpdir, 'foo' ); ok $dir->mkdir; ok $dir->child('dir')->mkdir; ok -d $dir->child('dir'); ok $dir->child('file.x')->touch; ok $dir->child('0')->touch; ok $dir->child('foo/bar/baz.txt')->touchpath; subtest 'iterator' => sub { my @contents; my $iter = $dir->iterator; while ( my $file = $iter->() ) { push @contents, $file; } is scalar @contents, 4 or diag explain \@contents; is( $iter->(), undef, "exhausted iterator is undef" ); my $joined = join ' ', sort map $_->basename, grep { -f $_ } @contents; is $joined, '0 file.x' or diag explain \@contents; my ($subdir) = grep { $_ eq $dir->child('dir') } @contents; ok $subdir; is -d $subdir, 1; my ($file) = grep { $_ eq $dir->child('file.x') } @contents; ok $file; is -d $file, ''; }; subtest 'visit' => sub { my @contents; $dir->visit( sub { push @contents, $_[0] } ); is scalar @contents, 4 or diag explain \@contents; my $joined = join ' ', sort map $_->basename, grep { -f $_ } @contents; is $joined, '0 file.x' or diag explain \@contents; my ($subdir) = grep { $_ eq $dir->child('dir') } @contents; ok $subdir; is -d $subdir, 1; my ($file) = grep { $_ eq $dir->child('file.x') } @contents; ok $file; is -d $file, ''; }; ok $dir->remove_tree; ok !-e $dir; # Try again with directory called '0', in curdir my $orig = Path::Tiny->cwd; ok $dir->mkdir; ok chdir($dir); my $dir2 = path("."); ok $dir2->child('0')->mkdir; ok -d $dir2->child('0'); subtest 'iterator' => sub { my @contents; my $iter = $dir2->iterator; while ( my $file = $iter->() ) { push @contents, $file; } ok grep { $_ eq '0' } @contents; }; subtest 'visit' => sub { my @contents; $dir2->visit( sub { push @contents, $_[0] } ); ok grep { $_ eq '0' } @contents; }; ok chdir($orig); ok $dir->remove_tree; ok !-e $dir; } { my $file = path( $tmpdir, 'slurp' ); ok $file; my $fh = $file->openw or die "Can't create $file: $!"; print $fh "Line1\nLine2\n"; close $fh; ok -e $file; my $content = $file->slurp; is $content, "Line1\nLine2\n"; my @content = $file->lines; is_deeply \@content, [ "Line1\n", "Line2\n" ]; @content = $file->lines( { chomp => 1 } ); is_deeply \@content, [ "Line1", "Line2" ]; ok( $file->remove, "removing file" ); ok !-e $file, "file is gone"; ok !$file->remove, "removing file again returns false"; my $subdir = $tmpdir->child('subdir'); ok $subdir->mkdir; ok exception { $subdir->remove }, "calling 'remove' on a directory throws"; ok rmdir $subdir; my $orig = Path::Tiny->cwd; ok chdir $tmpdir; my $zero_file = path '0'; ok $zero_file->openw; ok $zero_file->remove, "removing file called '0'"; ok chdir $orig; } { my $file = path( $tmpdir, 'slurp' ); ok $file; my $fh = $file->openw(':raw') or die "Can't create $file: $!"; print $fh "Line1\r\nLine2\r\n\302\261\r\n"; close $fh; ok -e $file; my $content = $file->slurp( { binmode => ':raw' } ); is $content, "Line1\r\nLine2\r\n\302\261\r\n", "slurp raw"; my $line3 = "\302\261\n"; utf8::decode($line3); $content = $file->slurp( { binmode => ':crlf:utf8' } ); is $content, "Line1\nLine2\n" . $line3, "slurp+crlf+utf8"; my @content = $file->lines( { binmode => ':crlf:utf8' } ); is_deeply \@content, [ "Line1\n", "Line2\n", $line3 ], "lines+crlf+utf8"; chop($line3); @content = $file->lines( { chomp => 1, binmode => ':crlf:utf8' } ); is_deeply \@content, [ "Line1", "Line2", $line3 ], "lines+chomp+crlf+utf8"; $file->remove; ok not -e $file; } { my $file = path( $tmpdir, 'spew' ); $file->remove() if $file->exists; $file->spew( { binmode => ':raw' }, "Line1\r\n" ); $file->append( { binmode => ':raw' }, "Line2" ); my $content = $file->slurp( { binmode => ':raw' } ); is( $content, "Line1\r\nLine2" ); } { # Make sure we can make an absolute/relative roundtrip my $cwd = path("."); is $cwd, $cwd->absolute->relative, "from $cwd to " . $cwd->absolute . " to " . $cwd->absolute->relative; } { # realpath should resolve .. my $lib = path("t/../lib"); my $real = $lib->realpath; unlike $real, qr/\.\./, "updir gone from realpath"; my $abs_lib = $lib->absolute; my $abs_t = path("t")->absolute; my $case = $abs_t->child("../lib"); is( $case->realpath, $lib->realpath, "realpath on absolute" ); # non-existent directory in realpath should throw error eval { path("lkajdfak/djslakdj")->realpath }; like( $@, qr/Error resolving realpath/, "caught error from realpath on non-existent dir" ); # but non-existent basename in realpath should throw error eval { path("./djslakdj")->realpath }; is( $@, '', "no error from realpath on non-existent last component" ); } subtest "move()" => sub { subtest "dest is a file (and does not exist)" => sub { my $file = $tmpdir->child("mv-foo.txt"); $file->spew("Hello World\n"); my $moveto = $tmpdir->child("mv-bar.txt"); ok !-e $moveto, "destination does not exist before"; my $result = $file->move("$moveto"); is "$result" => "$moveto", "returned the right file"; is $moveto->slurp, "Hello World\n", "target exists and matches orig"; ok !$file->exists, "orig no longer exists"; }; subtest "dest is a dir" => sub { my $file = $tmpdir->child("mv-dir.txt"); $file->spew("Hello World\n"); my $anothertmpdir = Path::Tiny->tempdir; my $result = $file->move($anothertmpdir); is "$result" => "$anothertmpdir/mv-dir.txt", "returned the right file"; is $result->slurp, "Hello World\n", "target exists and matches orig"; ok !$file->exists, "orig no longer exists"; }; subtest "dest file already exists" => sub { my $file = $tmpdir->child("mv-non.txt"); $file->spew("Hello World\n"); my $anothertmpdir = Path::Tiny->tempdir; my $dest = $anothertmpdir->child( "move-it.there"); $dest->spew( "Original Content\n" ); ok -f $dest, "destination file exists"; my $result; { local ( $!, $@ ); $result = $file->move("$dest"); is $@, undef, q[$@ - no errors leaked on success]; is $!, "", q[$! - no errors leaked on success]; } is "$result" => $dest, "returned the right file"; is $result->slurp, "Hello World\n", "target exists and matches orig"; ok !$file->exists, "orig no longer exists"; }; subtest "dest parent dir does not exist" => sub { my $file = $tmpdir->child("mv-noparent.txt"); $file->spew("Hello World\n"); my $anothertmpdir = Path::Tiny->tempdir; my $result = eval { $file->move("$anothertmpdir/rutroh/yo.txt") }; ok !$result, "does not return true"; like "$@", qr/move/, "throws error"; ok $file->exists, "orig still exists"; } }; subtest "copy()" => sub { my $file = $tmpdir->child("foo.txt"); $file->spew("Hello World\n"); my $copy; subtest "dest is a file" => sub { $copy = $tmpdir->child("bar.txt"); my $result = $file->copy($copy); is "$result" => "$copy", "returned the right file"; is( $copy->slurp, "Hello World\n", "file copied" ); }; subtest "dest is a dir" => sub { # new tempdir not to clobber the original foo.txt my $tmpdir = Path::Tiny->tempdir; my $result = $file->copy($tmpdir); is "$result" => "$tmpdir/foo.txt", "returned the right file"; is $result->slurp, "Hello World\n", "file copied"; }; subtest "try some different chmods" => sub { ok( $copy->chmod(0000), "chmod(0000)" ); ok( $copy->chmod("0400"), "chmod('0400')" ); SKIP: { skip "No exception if run as root", 1 if $> == 0; skip "No exception writing to read-only file", 1 unless exception { open my $fh, ">", "$copy" or die }; # probe if actually read-only my $error = exception { $file->copy($copy) }; ok( $error, "copy throws error if permission denied" ); like( $error, qr/\Q$file/, "error messages includes the source file name" ); like( $error, qr/\Q$copy/, "error messages includes the destination file name" ); } ok( $copy->chmod("u+w"), "chmod('u+w')" ); }; }; { $tmpdir->child( "subdir", "touched.txt" )->touchpath->spew("Hello World\n"); is( $tmpdir->child( "subdir", "touched.txt" )->slurp, "Hello World\n", "touch can chain" ); } { # Only run if a 255 length filename is allowed. Test checks that the temp # file created doesn't exceed 255 characters. my $file = $tmpdir->child("A" x 255); if ( eval { $file->touch; 1 } ) {; ok( path($file)->spew("Hello"), "spew to long filename" ); } } SKIP: { my $newtmp = Path::Tiny->tempdir; my $file = $newtmp->child("foo.txt"); my $link = $newtmp->child("bar.txt"); $file->spew("Hello World\n"); skip "symlink unavailable", 1 unless has_symlinks(); eval { symlink $file => $link }; ok( $link->lstat->size, "lstat" ); is( $link->realpath, $file->realpath, "realpath resolves symlinks" ); ok $link->remove, 'remove symbolic link'; ok $file->remove; $file = $newtmp->child("foo.txt"); $link = $newtmp->child("bar.txt"); $file->spew("Hello World\n"); ok symlink $file => $link; ok $file->remove; ok $link->remove, 'remove broken symbolic link'; my $dir = $newtmp->child('foo'); $link = $newtmp->child("bar"); ok $dir->mkdir; ok -d $dir; $file = $dir->child("baz.txt"); $file->spew("Hello World\n"); ok symlink $dir => $link; ok $link->remove_tree, 'remove_tree symbolic link'; ok $dir->remove_tree; $dir = $newtmp->child('foo'); $link = $newtmp->child("bar"); ok $dir->mkdir; ok -d $dir; $file = $dir->child("baz.txt"); $file->spew("Hello World\n"); ok symlink $dir => $link; ok $dir->remove_tree; ok $link->remove_tree, 'remove_tree broken symbolic link'; $file = $newtmp->child("foo.txt"); $link = $newtmp->child("bar.txt"); my $link2 = $newtmp->child("baz.txt"); $file->spew("Hello World\n"); ok symlink $file => $link; ok symlink $link => $link2; $link2->spew("Hello Perl\n"); ok -l $link2, 'path is still symbolic link after spewing'; is readlink($link2), $link, 'symbolic link is available after spewing'; is readlink($link), $file, 'symbolic link is available after spewing'; is $file->slurp, "Hello Perl\n", 'spewing follows the link and replace the destination instead'; } # We don't have subsume so comment these out. Keep in case we # implement it later ##{ ## my $t = path( 't'); ## my $foo_bar = $t->child('foo','bar'); ## $foo_bar->remove; # Make sure it doesn't exist ## ## ok $t->subsumes($foo_bar), "t subsumes t/foo/bar"; ## ok !$t->contains($foo_bar), "t doesn't contain t/foo/bar"; ## ## $foo_bar->mkdir; ## ok $t->subsumes($foo_bar), "t still subsumes t/foo/bar"; ## ok $t->contains($foo_bar), "t now contains t/foo/bar"; ## ## $t->child('foo')->remove; ##} done_testing; t/lib/TestUtils.pm 0000644 00000003116 15125124546 0010061 0 ustar 00 use 5.008001; use strict; use warnings; package TestUtils; use Carp; use Cwd qw/getcwd/; use Config; use File::Temp 0.19 (); use Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw( exception pushd tempd has_symlinks ); # If we have Test::FailWarnings, use it BEGIN { eval { require Test::FailWarnings; 1 } and do { Test::FailWarnings->import }; } sub has_symlinks { return $Config{d_symlink} unless $^O eq 'msys' || $^O eq 'MSWin32'; if ($^O eq 'msys') { # msys needs both `d_symlink` and a special environment variable return unless $Config{d_symlink}; return $ENV{MSYS} =~ /winsymlinks:nativestrict/; } elsif ($^O eq 'MSWin32') { # Perl 5.33.5 adds symlink support for MSWin32 but needs elevated # privileges so verify if we can use it for testing. my $wd=tempd(); open my $fh, ">", "foo"; return eval { symlink "foo", "bar" }; } } sub exception(&) { my $code = shift; my $success = eval { $code->(); 1 }; my $err = $@; return '' if $success; croak "Execution died, but the error was lost" unless $@; return $@; } sub tempd { return pushd( File::Temp->newdir ); } sub pushd { my $temp = shift; my $guard = TestUtils::_Guard->new( { temp => $temp, origin => getcwd(), code => sub { chdir $_[0]{origin} }, } ); chdir $guard->{temp} or croak("Couldn't chdir: $!"); return $guard; } package TestUtils::_Guard; sub new { bless $_[1], $_[0] } sub DESTROY { $_[0]{code}->( $_[0] ) } 1; t/README 0000644 00000000326 15125124546 0005675 0 ustar 00 Some test files are adapted from those in Path::Class. Path::Tiny isn't API compatible so some adjustments have been made. For the most part, these tests are here to see if it handles special cases the same way. t/has_same_bytes.t 0000644 00000004056 15125124546 0010174 0 ustar 00 use 5.008001; use strict; use warnings; use Test::More 0.96; use lib 't/lib'; use TestUtils qw/exception has_symlinks/; use Path::Tiny; my $dir = Path::Tiny->tempdir; # identical contents in two files my $file1a = $dir->child("file1b.txt"); my $file1b = $dir->child("file1a.txt"); for my $f ( $file1a, $file1b ) { $f->spew("hello world"); } # different contents my $file2 = $dir->child("file2.txt"); $file2->spew("goodbye world"); # a directory, instead of a file my $subdir = $dir->child("subdir"); $subdir->mkdir; subtest "only files" => sub { ok( $file1a->has_same_bytes($file1a), "same file" ); ok( $file1a->has_same_bytes($file1b), "different files, same contents" ); ok( !$file1a->has_same_bytes($file2), "different files, different contents" ); }; subtest "symlinks" => sub { plan skip_all => "No symlink support" unless has_symlinks(); my $file1c = $dir->child("file1c.txt"); symlink "$file1a" => "$file1c"; ok( $file1a->has_same_bytes($file1c), "file compared to self symlink" ); ok( $file1c->has_same_bytes($file1a), "self symlink compared to file" ); }; subtest "exception" => sub { my $doesnt_exist = $dir->child("doesnt_exist.txt"); # Different OSes return different errors, so we just check for any error. ok( exception { $file1a->has_same_bytes($doesnt_exist) }, "file->has_same_bytes(doesnt_exist)" ); ok( exception { $doesnt_exist->has_same_bytes($file1a) }, "doesnt_exist->has_same_bytes(file)" ); ok( exception { $file1a->has_same_bytes($subdir) }, "file->has_same_bytes(dir)" ); ok( exception { $subdir->has_same_bytes($file1a) }, "dir->has_same_bytes(file)" ); ok( exception { $subdir->has_same_bytes($subdir) }, "dir->has_same_bytes(dir)" ); ok( exception { $subdir->has_same_bytes($dir) }, "dir->has_same_bytes(different_dir)" ); }; done_testing; # # This file is part of Path-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # perlcritic.rc 0000644 00000001166 15125124546 0007243 0 ustar 00 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::ProhibitEvilVariables] variables = $DB::single # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] META.yml 0000644 00000006124 15125124546 0006025 0 ustar 00 --- abstract: 'File path utility' author: - 'David Golden <dagolden@cpan.org>' build_requires: Digest::MD5: '0' ExtUtils::MakeMaker: '0' File::Basename: '0' File::Spec: '0.86' File::Spec::Functions: '0' File::Spec::Unix: '0' File::Temp: '0.19' Test::More: '0.96' lib: '0' open: '0' perl: '5.008001' configure_requires: ExtUtils::MakeMaker: '6.17' perl: '5.008001' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Path-Tiny no_index: directory: - corpus - examples - t - xt package: - DB - flock provides: Path::Tiny: file: lib/Path/Tiny.pm version: '0.146' Path::Tiny::Error: file: lib/Path/Tiny.pm version: '0.146' recommends: Unicode::UTF8: '0.58' requires: Carp: '0' Cwd: '0' Digest: '1.03' Digest::SHA: '5.45' Encode: '0' Exporter: '5.57' Fcntl: '0' File::Compare: '0' File::Copy: '0' File::Glob: '0' File::Path: '2.07' File::Spec: '0.86' File::Temp: '0.19' File::stat: '0' constant: '0' overload: '0' perl: '5.008001' strict: '0' warnings: '0' warnings::register: '0' resources: bugtracker: https://github.com/dagolden/Path-Tiny/issues homepage: https://github.com/dagolden/Path-Tiny repository: https://github.com/dagolden/Path-Tiny.git version: '0.146' x_authority: cpan:DAGOLDEN x_contributors: - 'Alex Efros <powerman@powerman.name>' - 'Aristotle Pagaltzis <pagaltzis@gmx.de>' - 'Chris Williams <bingos@cpan.org>' - 'Dan Book <grinnz@grinnz.com>' - 'Dave Rolsky <autarch@urth.org>' - 'David Steinbrunner <dsteinbrunner@pobox.com>' - 'Doug Bell <madcityzen@gmail.com>' - 'Elvin Aslanov <rwp.primary@gmail.com>' - 'Flavio Poletti <flavio@polettix.it>' - 'Gabor Szabo <szabgab@cpan.org>' - 'Gabriel Andrade <gabiruh@gmail.com>' - 'George Hartzell <hartzell@cpan.org>' - 'Geraud Continsouzas <geraud@scsi.nc>' - 'Goro Fuji <gfuji@cpan.org>' - 'Graham Knop <haarg@haarg.org>' - 'Graham Ollis <plicease@cpan.org>' - 'Ian Sillitoe <ian@sillit.com>' - 'James Hunt <james@niftylogic.com>' - 'John Karr <brainbuz@brainbuz.org>' - 'Karen Etheridge <ether@cpan.org>' - 'Mark Ellis <mark.ellis@cartridgesave.co.uk>' - 'Martin H. Sluka <fany@cpan.org>' - 'Martin Kjeldsen <mk@bluepipe.dk>' - 'Mary Ehlers <regina.verb.ae@gmail.com>' - 'Michael G. Schwern <mschwern@cpan.org>' - 'Nicolas R <nicolas@atoomic.org>' - 'Nicolas Rochelemagne <rochelemagne@cpanel.net>' - 'Nigel Gregoire <nigelgregoire@gmail.com>' - 'Philippe Bruhat (BooK) <book@cpan.org>' - 'regina-verbae <regina-verbae@users.noreply.github.com>' - 'Roy Ivy III <rivy@cpan.org>' - 'Shlomi Fish <shlomif@shlomifish.org>' - 'Smylers <Smylers@stripey.com>' - 'Tatsuhiko Miyagawa <miyagawa@bulknews.net>' - 'Toby Inkster <tobyink@cpan.org>' - 'Yanick Champoux <yanick@babyl.dyndns.org>' - '김도형 - Keedi Kim <keedi@cpan.org>' x_generated_by_perl: v5.36.0 x_serialization_backend: 'YAML::Tiny version 1.73' x_spdx_expression: Apache-2.0 dist.ini 0000644 00000002554 15125124546 0006223 0 ustar 00 name = Path-Tiny author = David Golden <dagolden@cpan.org> license = Apache_2_0 copyright_holder = David Golden copyright_year = 2014 [@DAGOLDEN] :version = 0.072 -remove = MinimumPerlFast stopwords = AIX stopwords = BENCHMARKING stopwords = CRLF stopwords = IEC stopwords = KiB stopwords = Lustre stopwords = MiB stopwords = NFS stopwords = SHA stopwords = UNC stopwords = canonpath stopwords = chainable stopwords = codepoints stopwords = cwd stopwords = dirname stopwords = fatalize stopwords = iec stopwords = kB stopwords = lstat stopwords = mkdir stopwords = mkpath stopwords = opena stopwords = openr stopwords = openrw stopwords = openw stopwords = perms stopwords = realpath stopwords = si stopwords = stat stopwords = stringifying stopwords = subclasses stopwords = touchpath stopwords = unlinked stopwords = utf MetaNoIndex.package = flock [ReleaseStatus::FromVersion] testing = third_decimal_odd [MinimumPerl] [RemovePrereqs] remove = Unicode::UTF8 remove = PerlIO::utf8_strict remove = Path::Class remove = Test::FailWarnings remove = threads ; Digest/Digest::SHA are fine in 5.10.0+ [Prereqs] Digest = 1.03 Digest::SHA = 5.45 File::Path = 2.07 File::Temp = 0.19 ; newdir [Prereqs / Recommends] Unicode::UTF8 = 0.58 [Prereqs / TestRecommends] Test::FailWarnings = 0 Test::MockRandom = 0 [OnlyCorePrereqs] starting_version = current check_dual_life_versions = 0 Makefile.PL 0000644 00000004301 15125124546 0006521 0 ustar 00 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.031. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "File path utility", "AUTHOR" => "David Golden <dagolden\@cpan.org>", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "Path-Tiny", "LICENSE" => "apache", "MIN_PERL_VERSION" => "5.008001", "NAME" => "Path::Tiny", "PREREQ_PM" => { "Carp" => 0, "Cwd" => 0, "Digest" => "1.03", "Digest::SHA" => "5.45", "Encode" => 0, "Exporter" => "5.57", "Fcntl" => 0, "File::Compare" => 0, "File::Copy" => 0, "File::Glob" => 0, "File::Path" => "2.07", "File::Spec" => "0.86", "File::Temp" => "0.19", "File::stat" => 0, "constant" => 0, "overload" => 0, "strict" => 0, "warnings" => 0, "warnings::register" => 0 }, "TEST_REQUIRES" => { "Digest::MD5" => 0, "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Spec" => "0.86", "File::Spec::Functions" => 0, "File::Spec::Unix" => 0, "File::Temp" => "0.19", "Test::More" => "0.96", "lib" => 0, "open" => 0 }, "VERSION" => "0.146", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Cwd" => 0, "Digest" => "1.03", "Digest::MD5" => 0, "Digest::SHA" => "5.45", "Encode" => 0, "Exporter" => "5.57", "ExtUtils::MakeMaker" => 0, "Fcntl" => 0, "File::Basename" => 0, "File::Compare" => 0, "File::Copy" => 0, "File::Glob" => 0, "File::Path" => "2.07", "File::Spec" => "0.86", "File::Spec::Functions" => 0, "File::Spec::Unix" => 0, "File::Temp" => "0.19", "File::stat" => 0, "Test::More" => "0.96", "constant" => 0, "lib" => 0, "open" => 0, "overload" => 0, "strict" => 0, "warnings" => 0, "warnings::register" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); blib/man3/Path::Tiny.3pm 0000644 00000155635 15125124546 0010703 0 ustar 00 .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Path::Tiny 3" .TH Path::Tiny 3 "2024-05-08" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Path::Tiny \- File path utility .SH "VERSION" .IX Header "VERSION" version 0.146 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Path::Tiny; \& \& # Creating Path::Tiny objects \& \& my $dir = path("/tmp"); \& my $foo = path("foo.txt"); \& \& my $subdir = $dir\->child("foo"); \& my $bar = $subdir\->child("bar.txt"); \& \& # Stringifies as cleaned up path \& \& my $file = path("./foo.txt"); \& print $file; # "foo.txt" \& \& # Reading files \& \& my $guts = $file\->slurp; \& $guts = $file\->slurp_utf8; \& \& my @lines = $file\->lines; \& @lines = $file\->lines_utf8; \& \& my ($head) = $file\->lines( {count => 1} ); \& my ($tail) = $file\->lines( {count => \-1} ); \& \& # Writing files \& \& $bar\->spew( @data ); \& $bar\->spew_utf8( @data ); \& \& # Reading directories \& \& for ( $dir\->children ) { ... } \& \& my $iter = $dir\->iterator; \& while ( my $next = $iter\->() ) { ... } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a small, fast utility for working with file paths. It is friendlier to use than File::Spec and provides easy access to functions from several other core file handling modules. It aims to be smaller and faster than many alternatives on \s-1CPAN,\s0 while helping people do many common things in consistent and less error-prone ways. .PP Path::Tiny does not try to work for anything except Unix-like and Win32 platforms. Even then, it might break if you try something particularly obscure or tortuous. (Quick! What does this mean: \&\f(CW\*(C`///../../..//./././a//b/.././c/././\*(C'\fR? And how does it differ on Win32?) .PP All paths are forced to have Unix-style forward slashes. Stringifying the object gives you back the path (after some clean up). .PP File input/output methods \f(CW\*(C`flock\*(C'\fR handles before reading or writing, as appropriate (if supported by the platform and/or filesystem). .PP The \f(CW*_utf8\fR methods (\f(CW\*(C`slurp_utf8\*(C'\fR, \f(CW\*(C`lines_utf8\*(C'\fR, etc.) operate in raw mode. On Windows, that means they will not have \s-1CRLF\s0 translation from the \&\f(CW\*(C`:crlf\*(C'\fR \s-1IO\s0 layer. Installing Unicode::UTF8 0.58 or later will speed up \&\f(CW*_utf8\fR situations in many cases and is highly recommended. Alternatively, installing PerlIO::utf8_strict 0.003 or later will be used in place of the default \f(CW\*(C`:encoding(UTF\-8)\*(C'\fR. .PP This module depends heavily on PerlIO layers for correct operation and thus requires Perl 5.008001 or later. .SH "CONSTRUCTORS" .IX Header "CONSTRUCTORS" .SS "path" .IX Subsection "path" .Vb 3 \& $path = path("foo/bar"); \& $path = path("/tmp", "file.txt"); # list \& $path = path("."); # cwd .Ve .PP Constructs a \f(CW\*(C`Path::Tiny\*(C'\fR object. It doesn't matter if you give a file or directory path. It's still up to you to call directory-like methods only on directories and file-like methods only on files. This function is exported automatically by default. .PP The first argument must be defined and have non-zero length or an exception will be thrown. This prevents subtle, dangerous errors with code like \&\f(CW\*(C`path( maybe_undef() )\->remove_tree\*(C'\fR. .PP \&\fB\s-1DEPRECATED\s0\fR: If and only if the \fBfirst\fR character of the \fBfirst\fR argument to \f(CW\*(C`path\*(C'\fR is a tilde ('~'), then tilde replacement will be applied to the first path segment. A single tilde will be replaced with \f(CW\*(C`glob(\*(Aq~\*(Aq)\*(C'\fR and a tilde followed by a username will be replaced with output of \&\f(CW\*(C`glob(\*(Aq~username\*(Aq)\*(C'\fR. \fBNo other method does tilde expansion on its arguments\fR. See \*(L"Tilde expansion (deprecated)\*(R" for more. .PP On Windows, if the path consists of a drive identifier without a path component (\f(CW\*(C`C:\*(C'\fR or \f(CW\*(C`D:\*(C'\fR), it will be expanded to the absolute path of the current directory on that volume using \f(CW\*(C`Cwd::getdcwd()\*(C'\fR. .PP If called with a single \f(CW\*(C`Path::Tiny\*(C'\fR argument, the original is returned unless the original is holding a temporary file or directory reference in which case a stringified copy is made. .PP .Vb 2 \& $path = path("foo/bar"); \& $temp = Path::Tiny\->tempfile; \& \& $p2 = path($path); # like $p2 = $path \& $t2 = path($temp); # like $t2 = path( "$temp" ) .Ve .PP This optimizes copies without proliferating references unexpectedly if a copy is made by code outside your control. .PP Current \s-1API\s0 available since 0.017. .SS "new" .IX Subsection "new" .Vb 1 \& $path = Path::Tiny\->new("foo/bar"); .Ve .PP This is just like \f(CW\*(C`path\*(C'\fR, but with method call overhead. (Why would you do that?) .PP Current \s-1API\s0 available since 0.001. .SS "cwd" .IX Subsection "cwd" .Vb 2 \& $path = Path::Tiny\->cwd; # path( Cwd::getcwd ) \& $path = cwd; # optional export .Ve .PP Gives you the absolute path to the current directory as a \f(CW\*(C`Path::Tiny\*(C'\fR object. This is slightly faster than \f(CW\*(C`path(".")\->absolute\*(C'\fR. .PP \&\f(CW\*(C`cwd\*(C'\fR may be exported on request and used as a function instead of as a method. .PP Current \s-1API\s0 available since 0.018. .SS "rootdir" .IX Subsection "rootdir" .Vb 2 \& $path = Path::Tiny\->rootdir; # / \& $path = rootdir; # optional export .Ve .PP Gives you \f(CW\*(C`File::Spec\->rootdir\*(C'\fR as a \f(CW\*(C`Path::Tiny\*(C'\fR object if you're too picky for \f(CW\*(C`path("/")\*(C'\fR. .PP \&\f(CW\*(C`rootdir\*(C'\fR may be exported on request and used as a function instead of as a method. .PP Current \s-1API\s0 available since 0.018. .SS "tempfile, tempdir" .IX Subsection "tempfile, tempdir" .Vb 6 \& $temp = Path::Tiny\->tempfile( @options ); \& $temp = Path::Tiny\->tempdir( @options ); \& $temp = $dirpath\->tempfile( @options ); \& $temp = $dirpath\->tempdir( @options ); \& $temp = tempfile( @options ); # optional export \& $temp = tempdir( @options ); # optional export .Ve .PP \&\f(CW\*(C`tempfile\*(C'\fR passes the options to \f(CW\*(C`File::Temp\->new\*(C'\fR and returns a \&\f(CW\*(C`Path::Tiny\*(C'\fR object with the file name. The \f(CW\*(C`TMPDIR\*(C'\fR option will be enabled by default, but you can override that by passing \f(CW\*(C`TMPDIR => 0\*(C'\fR along with the options. (If you use an absolute \f(CW\*(C`TEMPLATE\*(C'\fR option, you will want to disable \f(CW\*(C`TMPDIR\*(C'\fR.) .PP The resulting \f(CW\*(C`File::Temp\*(C'\fR object is cached. When the \f(CW\*(C`Path::Tiny\*(C'\fR object is destroyed, the \f(CW\*(C`File::Temp\*(C'\fR object will be as well. .PP \&\f(CW\*(C`File::Temp\*(C'\fR annoyingly requires you to specify a custom template in slightly different ways depending on which function or method you call, but \&\f(CW\*(C`Path::Tiny\*(C'\fR lets you ignore that and can take either a leading template or a \&\f(CW\*(C`TEMPLATE\*(C'\fR option and does the right thing. .PP .Vb 2 \& $temp = Path::Tiny\->tempfile( "customXXXXXXXX" ); # ok \& $temp = Path::Tiny\->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok .Ve .PP The tempfile path object will be normalized to have an absolute path, even if created in a relative directory using \f(CW\*(C`DIR\*(C'\fR. If you want it to have the \f(CW\*(C`realpath\*(C'\fR instead, pass a leading options hash like this: .PP .Vb 1 \& $real_temp = tempfile({realpath => 1}, @options); .Ve .PP \&\f(CW\*(C`tempdir\*(C'\fR is just like \f(CW\*(C`tempfile\*(C'\fR, except it calls \&\f(CW\*(C`File::Temp\->newdir\*(C'\fR instead. .PP Both \f(CW\*(C`tempfile\*(C'\fR and \f(CW\*(C`tempdir\*(C'\fR may be exported on request and used as functions instead of as methods. .PP The methods can be called on an instances representing a directory. In this case, the directory is used as the base to create the temporary file/directory, setting the \f(CW\*(C`DIR\*(C'\fR option in File::Temp. .PP .Vb 4 \& my $target_dir = path(\*(Aq/to/destination\*(Aq); \& my $tempfile = $target_dir\->tempfile(\*(AqfoobarXXXXXX\*(Aq); \& $tempfile\->spew(\*(AqA lot of data...\*(Aq); # not atomic \& $tempfile\->move($target_dir\->child(\*(Aqfoobar\*(Aq)); # hopefully atomic .Ve .PP In this case, any value set for option \f(CW\*(C`DIR\*(C'\fR is ignored. .PP \&\fBNote\fR: for tempfiles, the filehandles from File::Temp are closed and not reused. This is not as secure as using File::Temp handles directly, but is less prone to deadlocks or access problems on some platforms. Think of what \&\f(CW\*(C`Path::Tiny\*(C'\fR gives you to be just a temporary file \fBname\fR that gets cleaned up. .PP \&\fBNote 2\fR: if you don't want these cleaned up automatically when the object is destroyed, File::Temp requires different options for directories and files. Use \f(CW\*(C`CLEANUP => 0\*(C'\fR for directories and \f(CW\*(C`UNLINK => 0\*(C'\fR for files. .PP \&\fBNote 3\fR: Don't lose the temporary object by chaining a method call instead of storing it: .PP .Vb 1 \& my $lost = tempdir()\->child("foo"); # tempdir cleaned up right away .Ve .PP \&\fBNote 4\fR: The cached object may be accessed with the \*(L"cached_temp\*(R" method. Keeping a reference to, or modifying the cached object may break the behavior documented above and is not supported. Use at your own risk. .PP Current \s-1API\s0 available since 0.119. .SH "METHODS" .IX Header "METHODS" .SS "absolute" .IX Subsection "absolute" .Vb 2 \& $abs = path("foo/bar")\->absolute; \& $abs = path("foo/bar")\->absolute("/tmp"); .Ve .PP Returns a new \f(CW\*(C`Path::Tiny\*(C'\fR object with an absolute path (or itself if already absolute). If no argument is given, the current directory is used as the absolute base path. If an argument is given, it will be converted to an absolute path (if it is not already) and used as the absolute base path. .PP This will not resolve upward directories (\*(L"foo/../bar\*(R") unless \f(CW\*(C`canonpath\*(C'\fR in File::Spec would normally do so on your platform. If you need them resolved, you must call the more expensive \f(CW\*(C`realpath\*(C'\fR method instead. .PP On Windows, an absolute path without a volume component will have it added based on the current drive. .PP Current \s-1API\s0 available since 0.101. .SS "append, append_raw, append_utf8" .IX Subsection "append, append_raw, append_utf8" .Vb 5 \& path("foo.txt")\->append(@data); \& path("foo.txt")\->append(\e@data); \& path("foo.txt")\->append({binmode => ":raw"}, @data); \& path("foo.txt")\->append_raw(@data); \& path("foo.txt")\->append_utf8(@data); .Ve .PP Appends data to a file. The file is locked with \f(CW\*(C`flock\*(C'\fR prior to writing and closed afterwards. An optional hash reference may be used to pass options. Valid options are: .IP "\(bu" 4 \&\f(CW\*(C`binmode\*(C'\fR: passed to \f(CW\*(C`binmode()\*(C'\fR on the handle used for writing. .IP "\(bu" 4 \&\f(CW\*(C`truncate\*(C'\fR: truncates the file after locking and before appending .PP The \f(CW\*(C`truncate\*(C'\fR option is a way to replace the contents of a file \&\fBin place\fR, unlike \*(L"spew\*(R" which writes to a temporary file and then replaces the original (if it exists). .PP \&\f(CW\*(C`append_raw\*(C'\fR is like \f(CW\*(C`append\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:unix\*(C'\fR for a fast, unbuffered, raw write. .PP \&\f(CW\*(C`append_utf8\*(C'\fR is like \f(CW\*(C`append\*(C'\fR with an unbuffered \f(CW\*(C`binmode\*(C'\fR \&\f(CW\*(C`:unix:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:unix:utf8_strict\*(C'\fR with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, an unbuffered, raw append will be done instead on the data encoded with \&\f(CW\*(C`Unicode::UTF8\*(C'\fR. .PP Current \s-1API\s0 available since 0.060. .SS "assert" .IX Subsection "assert" .Vb 1 \& $path = path("foo.txt")\->assert( sub { $_\->exists } ); .Ve .PP Returns the invocant after asserting that a code reference argument returns true. When the assertion code reference runs, it will have the invocant object in the \f(CW$_\fR variable. If it returns false, an exception will be thrown. The assertion code reference may also throw its own exception. .PP If no assertion is provided, the invocant is returned without error. .PP Current \s-1API\s0 available since 0.062. .SS "basename" .IX Subsection "basename" .Vb 4 \& $name = path("foo/bar.txt")\->basename; # bar.txt \& $name = path("foo.txt")\->basename(\*(Aq.txt\*(Aq); # foo \& $name = path("foo.txt")\->basename(qr/.txt/); # foo \& $name = path("foo.txt")\->basename(@suffixes); .Ve .PP Returns the file portion or last directory portion of a path. .PP Given a list of suffixes as strings or regular expressions, any that match at the end of the file portion or last directory portion will be removed before the result is returned. .PP Current \s-1API\s0 available since 0.054. .SS "canonpath" .IX Subsection "canonpath" .Vb 1 \& $canonical = path("foo/bar")\->canonpath; # foo\ebar on Windows .Ve .PP Returns a string with the canonical format of the path name for the platform. In particular, this means directory separators will be \f(CW\*(C`\e\*(C'\fR on Windows. .PP Current \s-1API\s0 available since 0.001. .SS "cached_temp" .IX Subsection "cached_temp" Returns the cached \f(CW\*(C`File::Temp\*(C'\fR or \f(CW\*(C`File::Temp::Dir\*(C'\fR object if the \&\f(CW\*(C`Path::Tiny\*(C'\fR object was created with \f(CW\*(C`/tempfile\*(C'\fR or \f(CW\*(C`/tempdir\*(C'\fR. If there is no such object, this method throws. .PP \&\fB\s-1WARNING\s0\fR: Keeping a reference to, or modifying the cached object may break the behavior documented for temporary files and directories created with \f(CW\*(C`Path::Tiny\*(C'\fR and is not supported. Use at your own risk. .PP Current \s-1API\s0 available since 0.101. .SS "child" .IX Subsection "child" .Vb 2 \& $file = path("/tmp")\->child("foo.txt"); # "/tmp/foo.txt" \& $file = path("/tmp")\->child(@parts); .Ve .PP Returns a new \f(CW\*(C`Path::Tiny\*(C'\fR object relative to the original. Works like \f(CW\*(C`catfile\*(C'\fR or \f(CW\*(C`catdir\*(C'\fR from File::Spec, but without caring about file or directories. .PP \&\fB\s-1WARNING\s0\fR: because the argument could contain \f(CW\*(C`..\*(C'\fR or refer to symlinks, there is no guarantee that the new path refers to an actual descendent of the original. If this is important to you, transform parent and child with \&\*(L"realpath\*(R" and check them with \*(L"subsumes\*(R". .PP Current \s-1API\s0 available since 0.001. .SS "children" .IX Subsection "children" .Vb 2 \& @paths = path("/tmp")\->children; \& @paths = path("/tmp")\->children( qr/\e.txt\ez/ ); .Ve .PP Returns a list of \f(CW\*(C`Path::Tiny\*(C'\fR objects for all files and directories within a directory. Excludes \*(L".\*(R" and \*(L"..\*(R" automatically. .PP If an optional \f(CW\*(C`qr//\*(C'\fR argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching: .PP .Vb 2 \& @paths = path("/tmp")\->children( qr/^foo/ ); \& # matches children like the glob foo* .Ve .PP Current \s-1API\s0 available since 0.028. .SS "chmod" .IX Subsection "chmod" .Vb 4 \& path("foo.txt")\->chmod(0777); \& path("foo.txt")\->chmod("0755"); \& path("foo.txt")\->chmod("go\-w"); \& path("foo.txt")\->chmod("a=r,u+wx"); .Ve .PP Sets file or directory permissions. The argument can be a numeric mode, a octal string beginning with a \*(L"0\*(R" or a limited subset of the symbolic mode use by \fI/bin/chmod\fR. .PP The symbolic mode must be a comma-delimited list of mode clauses. Clauses must match \f(CW\*(C`qr/\eA([augo]+)([=+\-])([rwx]+)\ez/\*(C'\fR, which defines \*(L"who\*(R", \*(L"op\*(R" and \&\*(L"perms\*(R" parameters for each clause. Unlike \fI/bin/chmod\fR, all three parameters are required for each clause, multiple ops are not allowed and permissions \&\f(CW\*(C`stugoX\*(C'\fR are not supported. (See File::chmod for more complex needs.) .PP Current \s-1API\s0 available since 0.053. .SS "copy" .IX Subsection "copy" .Vb 1 \& path("/tmp/foo.txt")\->copy("/tmp/bar.txt"); .Ve .PP Copies the current path to the given destination using File::Copy's \&\f(CW\*(C`copy\*(C'\fR function. Upon success, returns the \f(CW\*(C`Path::Tiny\*(C'\fR object for the newly copied file. .PP Current \s-1API\s0 available since 0.070. .SS "digest" .IX Subsection "digest" .Vb 3 \& $obj = path("/tmp/foo.txt")\->digest; # SHA\-256 \& $obj = path("/tmp/foo.txt")\->digest("MD5"); # user\-selected \& $obj = path("/tmp/foo.txt")\->digest( { chunk_size => 1e6 }, "MD5" ); .Ve .PP Returns a hexadecimal digest for a file. An optional hash reference of options may be given. The only option is \f(CW\*(C`chunk_size\*(C'\fR. If \f(CW\*(C`chunk_size\*(C'\fR is given, that many bytes will be read at a time. If not provided, the entire file will be slurped into memory to compute the digest. .PP Any subsequent arguments are passed to the constructor for Digest to select an algorithm. If no arguments are given, the default is \s-1SHA\-256.\s0 .PP Current \s-1API\s0 available since 0.056. .SS "dirname (deprecated)" .IX Subsection "dirname (deprecated)" .Vb 1 \& $name = path("/tmp/foo.txt")\->dirname; # "/tmp/" .Ve .PP Returns the directory portion you would get from calling \&\f(CW\*(C`File::Spec\->splitpath( $path\->stringify )\*(C'\fR or \f(CW"."\fR for a path without a parent directory portion. Because File::Spec is inconsistent, the result might or might not have a trailing slash. Because of this, this method is \&\fBdeprecated\fR. .PP A better, more consistently approach is likely \f(CW\*(C`$path\->parent\->stringify\*(C'\fR, which will not have a trailing slash except for a root directory. .PP Deprecated in 0.056. .SS "edit, edit_raw, edit_utf8" .IX Subsection "edit, edit_raw, edit_utf8" .Vb 3 \& path("foo.txt")\->edit( \e&callback, $options ); \& path("foo.txt")\->edit_utf8( \e&callback ); \& path("foo.txt")\->edit_raw( \e&callback ); .Ve .PP These are convenience methods that allow \*(L"editing\*(R" a file using a single callback argument. They slurp the file using \f(CW\*(C`slurp\*(C'\fR, place the contents inside a localized \f(CW$_\fR variable, call the callback function (without arguments), and then write \f(CW$_\fR (presumably mutated) back to the file with \f(CW\*(C`spew\*(C'\fR. .PP An optional hash reference may be used to pass options. The only option is \&\f(CW\*(C`binmode\*(C'\fR, which is passed to \f(CW\*(C`slurp\*(C'\fR and \f(CW\*(C`spew\*(C'\fR. .PP \&\f(CW\*(C`edit_utf8\*(C'\fR and \f(CW\*(C`edit_raw\*(C'\fR act like their respective \f(CW\*(C`slurp_*\*(C'\fR and \&\f(CW\*(C`spew_*\*(C'\fR methods. .PP Current \s-1API\s0 available since 0.077. .SS "edit_lines, edit_lines_utf8, edit_lines_raw" .IX Subsection "edit_lines, edit_lines_utf8, edit_lines_raw" .Vb 3 \& path("foo.txt")\->edit_lines( \e&callback, $options ); \& path("foo.txt")\->edit_lines_utf8( \e&callback ); \& path("foo.txt")\->edit_lines_raw( \e&callback ); .Ve .PP These are convenience methods that allow \*(L"editing\*(R" a file's lines using a single callback argument. They iterate over the file: for each line, the line is put into a localized \f(CW$_\fR variable, the callback function is executed (without arguments) and then \f(CW$_\fR is written to a temporary file. When iteration is finished, the temporary file is atomically renamed over the original. .PP An optional hash reference may be used to pass options. The only option is \&\f(CW\*(C`binmode\*(C'\fR, which is passed to the method that open handles for reading and writing. .PP \&\f(CW\*(C`edit_lines_raw\*(C'\fR is like \f(CW\*(C`edit_lines\*(C'\fR with a buffered \f(CW\*(C`binmode\*(C'\fR of \&\f(CW\*(C`:raw\*(C'\fR. .PP \&\f(CW\*(C`edit_lines_utf8\*(C'\fR is like \f(CW\*(C`edit_lines\*(C'\fR with a buffered \f(CW\*(C`binmode\*(C'\fR \&\f(CW\*(C`:raw:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:raw:utf8_strict\*(C'\fR with PerlIO::utf8_strict). .PP Current \s-1API\s0 available since 0.077. .SS "exists, is_file, is_dir" .IX Subsection "exists, is_file, is_dir" .Vb 3 \& if ( path("/tmp")\->exists ) { ... } # \-e \& if ( path("/tmp")\->is_dir ) { ... } # \-d \& if ( path("/tmp")\->is_file ) { ... } # \-e && ! \-d .Ve .PP Implements file test operations, this means the file or directory actually has to exist on the filesystem. Until then, it's just a path. .PP \&\fBNote\fR: \f(CW\*(C`is_file\*(C'\fR is not \f(CW\*(C`\-f\*(C'\fR because \f(CW\*(C`\-f\*(C'\fR is not the opposite of \f(CW\*(C`\-d\*(C'\fR. \&\f(CW\*(C`\-f\*(C'\fR means \*(L"plain file\*(R", excluding symlinks, devices, etc. that often can be read just like files. .PP Use \f(CW\*(C`\-f\*(C'\fR instead if you really mean to check for a plain file. .PP Current \s-1API\s0 available since 0.053. .SS "filehandle" .IX Subsection "filehandle" .Vb 3 \& $fh = path("/tmp/foo.txt")\->filehandle($mode, $binmode); \& $fh = path("/tmp/foo.txt")\->filehandle({ locked => 1 }, $mode, $binmode); \& $fh = path("/tmp/foo.txt")\->filehandle({ exclusive => 1 }, $mode, $binmode); .Ve .PP Returns an open file handle. The \f(CW$mode\fR argument must be a Perl-style read/write mode string (\*(L"<\*(R" ,\*(L">\*(R", \*(L">>\*(R", etc.). If a \f(CW$binmode\fR is given, it is set during the \f(CW\*(C`open\*(C'\fR call. .PP An optional hash reference may be used to pass options. .PP The \f(CW\*(C`locked\*(C'\fR option governs file locking; if true, handles opened for writing, appending or read-write are locked with \f(CW\*(C`LOCK_EX\*(C'\fR; otherwise, they are locked with \f(CW\*(C`LOCK_SH\*(C'\fR. When using \f(CW\*(C`locked\*(C'\fR, \*(L">\*(R" or \*(L"+>\*(R" modes will delay truncation until after the lock is acquired. .PP The \f(CW\*(C`exclusive\*(C'\fR option causes the \fBopen()\fR call to fail if the file already exists. This corresponds to the O_EXCL flag to sysopen / \fBopen\fR\|(2). \&\f(CW\*(C`exclusive\*(C'\fR implies \f(CW\*(C`locked\*(C'\fR and will set it for you if you forget it. .PP See \f(CW\*(C`openr\*(C'\fR, \f(CW\*(C`openw\*(C'\fR, \f(CW\*(C`openrw\*(C'\fR, and \f(CW\*(C`opena\*(C'\fR for sugar. .PP Current \s-1API\s0 available since 0.066. .SS "has_same_bytes" .IX Subsection "has_same_bytes" .Vb 3 \& if ( path("foo.txt")\->has_same_bytes("bar.txt") ) { \& # ... \& } .Ve .PP This method returns true if both the invocant and the argument can be opened as file handles and the handles contain the same bytes. It returns false if their contents differ. If either can't be opened as a file (e.g. a directory or non-existent file), the method throws an exception. If both can be opened and both have the same \f(CW\*(C`realpath\*(C'\fR, the method returns true without scanning any data. .PP Current \s-1API\s0 available since 0.125. .SS "is_absolute, is_relative" .IX Subsection "is_absolute, is_relative" .Vb 2 \& if ( path("/tmp")\->is_absolute ) { ... } \& if ( path("/tmp")\->is_relative ) { ... } .Ve .PP Booleans for whether the path appears absolute or relative. .PP Current \s-1API\s0 available since 0.001. .SS "is_rootdir" .IX Subsection "is_rootdir" .Vb 4 \& while ( ! $path\->is_rootdir ) { \& $path = $path\->parent; \& ... \& } .Ve .PP Boolean for whether the path is the root directory of the volume. I.e. the \&\f(CW\*(C`dirname\*(C'\fR is \f(CW\*(C`q[/]\*(C'\fR and the \f(CW\*(C`basename\*(C'\fR is \f(CW\*(C`q[]\*(C'\fR. .PP This works even on \f(CW\*(C`MSWin32\*(C'\fR with drives and \s-1UNC\s0 volumes: .PP .Vb 2 \& path("C:/")\->is_rootdir; # true \& path("//server/share/")\->is_rootdir; #true .Ve .PP Current \s-1API\s0 available since 0.038. .SS "iterator" .IX Subsection "iterator" .Vb 1 \& $iter = path("/tmp")\->iterator( \e%options ); .Ve .PP Returns a code reference that walks a directory lazily. Each invocation returns a \f(CW\*(C`Path::Tiny\*(C'\fR object or undef when the iterator is exhausted. .PP .Vb 4 \& $iter = path("/tmp")\->iterator; \& while ( $path = $iter\->() ) { \& ... \& } .Ve .PP The current and parent directory entries (\*(L".\*(R" and \*(L"..\*(R") will not be included. .PP If the \f(CW\*(C`recurse\*(C'\fR option is true, the iterator will walk the directory recursively, breadth-first. If the \f(CW\*(C`follow_symlinks\*(C'\fR option is also true, directory links will be followed recursively. There is no protection against loops when following links. If a directory is not readable, it will not be followed. .PP The default is the same as: .PP .Vb 4 \& $iter = path("/tmp")\->iterator( { \& recurse => 0, \& follow_symlinks => 0, \& } ); .Ve .PP For a more powerful, recursive iterator with built-in loop avoidance, see Path::Iterator::Rule. .PP See also \*(L"visit\*(R". .PP Current \s-1API\s0 available since 0.016. .SS "lines, lines_raw, lines_utf8" .IX Subsection "lines, lines_raw, lines_utf8" .Vb 4 \& @contents = path("/tmp/foo.txt")\->lines; \& @contents = path("/tmp/foo.txt")\->lines(\e%options); \& @contents = path("/tmp/foo.txt")\->lines_raw; \& @contents = path("/tmp/foo.txt")\->lines_utf8; \& \& @contents = path("/tmp/foo.txt")\->lines( { chomp => 1, count => 4 } ); .Ve .PP Returns a list of lines from a file. Optionally takes a hash-reference of options. Valid options are \f(CW\*(C`binmode\*(C'\fR, \f(CW\*(C`count\*(C'\fR and \f(CW\*(C`chomp\*(C'\fR. .PP If \f(CW\*(C`binmode\*(C'\fR is provided, it will be set on the handle prior to reading. .PP If a positive \f(CW\*(C`count\*(C'\fR is provided, that many lines will be returned from the start of the file. If a negative \f(CW\*(C`count\*(C'\fR is provided, the entire file will be read, but only \f(CW\*(C`abs(count)\*(C'\fR will be kept and returned. If \f(CW\*(C`abs(count)\*(C'\fR exceeds the number of lines in the file, all lines will be returned. .PP If \f(CW\*(C`chomp\*(C'\fR is set, any end-of-line character sequences (\f(CW\*(C`CR\*(C'\fR, \f(CW\*(C`CRLF\*(C'\fR, or \&\f(CW\*(C`LF\*(C'\fR) will be removed from the lines returned. .PP Because the return is a list, \f(CW\*(C`lines\*(C'\fR in scalar context will return the number of lines (and throw away the data). .PP .Vb 1 \& $number_of_lines = path("/tmp/foo.txt")\->lines; .Ve .PP \&\f(CW\*(C`lines_raw\*(C'\fR is like \f(CW\*(C`lines\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:raw\*(C'\fR. We use \f(CW\*(C`:raw\*(C'\fR instead of \f(CW\*(C`:unix\*(C'\fR so PerlIO buffering can manage reading by line. .PP \&\f(CW\*(C`lines_utf8\*(C'\fR is like \f(CW\*(C`lines\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:raw:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:raw:utf8_strict\*(C'\fR with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered \s-1UTF\-8\s0 slurp will be done and then the lines will be split. This is actually faster than relying on \&\s-1IO\s0 layers, though a bit memory intensive. If memory use is a concern, consider \f(CW\*(C`openr_utf8\*(C'\fR and iterating directly on the handle. .PP Current \s-1API\s0 available since 0.065. .SS "mkdir" .IX Subsection "mkdir" .Vb 2 \& path("foo/bar/baz")\->mkdir; \& path("foo/bar/baz")\->mkdir( \e%options ); .Ve .PP Like calling \f(CW\*(C`make_path\*(C'\fR from File::Path. An optional hash reference is passed through to \f(CW\*(C`make_path\*(C'\fR. Errors will be trapped and an exception thrown. Returns the the path object to facilitate chaining. .PP \&\fB\s-1NOTE\s0\fR: unlike Perl's builtin \f(CW\*(C`mkdir\*(C'\fR, this will create intermediate paths similar to the Unix \f(CW\*(C`mkdir \-p\*(C'\fR command. It will not error if applied to an existing directory. .PP Current \s-1API\s0 available since 0.125. .SS "mkpath (deprecated)" .IX Subsection "mkpath (deprecated)" Like calling \f(CW\*(C`mkdir\*(C'\fR, but returns the list of directories created or an empty list if the directories already exist, just like \f(CW\*(C`make_path\*(C'\fR. .PP Deprecated in 0.125. .SS "move" .IX Subsection "move" .Vb 1 \& path("foo.txt")\->move("bar.txt"); .Ve .PP Moves the current path to the given destination using File::Copy's \&\f(CW\*(C`move\*(C'\fR function. Upon success, returns the \f(CW\*(C`Path::Tiny\*(C'\fR object for the newly moved file. .PP If the destination already exists and is a directory, and the source is not a directory, then the source file will be renamed into the directory specified by the destination. .PP If possible, \fBmove()\fR will simply rename the file. Otherwise, it copies the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. .PP Current \s-1API\s0 available since 0.124. Prior versions used Perl's \&\-built\-in (and less robust) rename function and did not return an object. .SS "openr, openw, openrw, opena" .IX Subsection "openr, openw, openrw, opena" .Vb 3 \& $fh = path("foo.txt")\->openr($binmode); # read \& $fh = path("foo.txt")\->openr_raw; \& $fh = path("foo.txt")\->openr_utf8; \& \& $fh = path("foo.txt")\->openw($binmode); # write \& $fh = path("foo.txt")\->openw_raw; \& $fh = path("foo.txt")\->openw_utf8; \& \& $fh = path("foo.txt")\->opena($binmode); # append \& $fh = path("foo.txt")\->opena_raw; \& $fh = path("foo.txt")\->opena_utf8; \& \& $fh = path("foo.txt")\->openrw($binmode); # read/write \& $fh = path("foo.txt")\->openrw_raw; \& $fh = path("foo.txt")\->openrw_utf8; .Ve .PP Returns a file handle opened in the specified mode. The \f(CW\*(C`openr\*(C'\fR style methods take a single \f(CW\*(C`binmode\*(C'\fR argument. All of the \f(CW\*(C`open*\*(C'\fR methods have \&\f(CW\*(C`open*_raw\*(C'\fR and \f(CW\*(C`open*_utf8\*(C'\fR equivalents that use buffered I/O layers \f(CW\*(C`:raw\*(C'\fR and \f(CW\*(C`:raw:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:raw:utf8_strict\*(C'\fR with PerlIO::utf8_strict). .PP An optional hash reference may be used to pass options. The only option is \&\f(CW\*(C`locked\*(C'\fR. If true, handles opened for writing, appending or read-write are locked with \f(CW\*(C`LOCK_EX\*(C'\fR; otherwise, they are locked for \f(CW\*(C`LOCK_SH\*(C'\fR. .PP .Vb 1 \& $fh = path("foo.txt")\->openrw_utf8( { locked => 1 } ); .Ve .PP See \*(L"filehandle\*(R" for more on locking. .PP Current \s-1API\s0 available since 0.011. .SS "parent" .IX Subsection "parent" .Vb 2 \& $parent = path("foo/bar/baz")\->parent; # foo/bar \& $parent = path("foo/wibble.txt")\->parent; # foo \& \& $parent = path("foo/bar/baz")\->parent(2); # foo .Ve .PP Returns a \f(CW\*(C`Path::Tiny\*(C'\fR object corresponding to the parent directory of the original directory or file. An optional positive integer argument is the number of parent directories upwards to return. \f(CW\*(C`parent\*(C'\fR by itself is equivalent to \&\f(CWparent(1)\fR. .PP Current \s-1API\s0 available since 0.014. .SS "realpath" .IX Subsection "realpath" .Vb 2 \& $real = path("/baz/foo/../bar")\->realpath; \& $real = path("foo/../bar")\->realpath; .Ve .PP Returns a new \f(CW\*(C`Path::Tiny\*(C'\fR object with all symbolic links and upward directory parts resolved using Cwd's \f(CW\*(C`realpath\*(C'\fR. Compared to \f(CW\*(C`absolute\*(C'\fR, this is more expensive as it must actually consult the filesystem. .PP If the parent path can't be resolved (e.g. if it includes directories that don't exist), an exception will be thrown: .PP .Vb 1 \& $real = path("doesnt_exist/foo")\->realpath; # dies .Ve .PP However, if the parent path exists and only the last component (e.g. filename) doesn't exist, the realpath will be the realpath of the parent plus the non-existent last component: .PP .Vb 1 \& $real = path("./aasdlfasdlf")\->realpath; # works .Ve .PP The underlying Cwd module usually worked this way on Unix, but died on Windows (and some Unixes) if the full path didn't exist. As of version 0.064, it's safe to use anywhere. .PP Current \s-1API\s0 available since 0.001. .SS "relative" .IX Subsection "relative" .Vb 1 \& $rel = path("/tmp/foo/bar")\->relative("/tmp"); # foo/bar .Ve .PP Returns a \f(CW\*(C`Path::Tiny\*(C'\fR object with a path relative to a new base path given as an argument. If no argument is given, the current directory will be used as the new base path. .PP If either path is already relative, it will be made absolute based on the current directly before determining the new relative path. .PP The algorithm is roughly as follows: .IP "\(bu" 4 If the original and new base path are on different volumes, an exception will be thrown. .IP "\(bu" 4 If the original and new base are identical, the relative path is \f(CW"."\fR. .IP "\(bu" 4 If the new base subsumes the original, the relative path is the original path with the new base chopped off the front .IP "\(bu" 4 If the new base does not subsume the original, a common prefix path is determined (possibly the root directory) and the relative path will consist of updirs (\f(CW".."\fR) to reach the common prefix, followed by the original path less the common prefix. .PP Unlike \f(CW\*(C`File::Spec::abs2rel\*(C'\fR, in the last case above, the calculation based on a common prefix takes into account symlinks that could affect the updir process. Given an original path \*(L"/A/B\*(R" and a new base \*(L"/A/C\*(R", (where \*(L"A\*(R", \*(L"B\*(R" and \*(L"C\*(R" could each have multiple path components): .IP "\(bu" 4 Symlinks in \*(L"A\*(R" don't change the result unless the last component of A is a symlink and the first component of \*(L"C\*(R" is an updir. .IP "\(bu" 4 Symlinks in \*(L"B\*(R" don't change the result and will exist in the result as given. .IP "\(bu" 4 Symlinks and updirs in \*(L"C\*(R" must be resolved to actual paths, taking into account the possibility that not all path components might exist on the filesystem. .PP Current \s-1API\s0 available since 0.001. New algorithm (that accounts for symlinks) available since 0.079. .SS "remove" .IX Subsection "remove" .Vb 1 \& path("foo.txt")\->remove; .Ve .PP This is just like \f(CW\*(C`unlink\*(C'\fR, except for its error handling: if the path does not exist, it returns false; if deleting the file fails, it throws an exception. .PP Current \s-1API\s0 available since 0.012. .SS "remove_tree" .IX Subsection "remove_tree" .Vb 4 \& # directory \& path("foo/bar/baz")\->remove_tree; \& path("foo/bar/baz")\->remove_tree( \e%options ); \& path("foo/bar/baz")\->remove_tree( { safe => 0 } ); # force remove .Ve .PP Like calling \f(CW\*(C`remove_tree\*(C'\fR from File::Path, but defaults to \f(CW\*(C`safe\*(C'\fR mode. An optional hash reference is passed through to \f(CW\*(C`remove_tree\*(C'\fR. Errors will be trapped and an exception thrown. Returns the number of directories deleted, just like \f(CW\*(C`remove_tree\*(C'\fR. .PP If you want to remove a directory only if it is empty, use the built-in \&\f(CW\*(C`rmdir\*(C'\fR function instead. .PP .Vb 1 \& rmdir path("foo/bar/baz/"); .Ve .PP Current \s-1API\s0 available since 0.013. .SS "sibling" .IX Subsection "sibling" .Vb 3 \& $foo = path("/tmp/foo.txt"); \& $sib = $foo\->sibling("bar.txt"); # /tmp/bar.txt \& $sib = $foo\->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt .Ve .PP Returns a new \f(CW\*(C`Path::Tiny\*(C'\fR object relative to the parent of the original. This is slightly more efficient than \f(CW\*(C`$path\->parent\->child(...)\*(C'\fR. .PP Current \s-1API\s0 available since 0.058. .SS "size, size_human" .IX Subsection "size, size_human" .Vb 1 \& my $p = path("foo"); # with size 1025 bytes \& \& $p\->size; # "1025" \& $p\->size_human; # "1.1 K" \& $p\->size_human( {format => "iec"} ); # "1.1 KiB" .Ve .PP Returns the size of a file. The \f(CW\*(C`size\*(C'\fR method is just a wrapper around \f(CW\*(C`\-s\*(C'\fR. .PP The \f(CW\*(C`size_human\*(C'\fR method provides a human-readable string similar to \&\f(CW\*(C`ls \-lh\*(C'\fR. Like \f(CW\*(C`ls\*(C'\fR, it rounds upwards and provides one decimal place for single-digit sizes and no decimal places for larger sizes. The only available option is \f(CW\*(C`format\*(C'\fR, which has three valid values: .IP "\(bu" 4 \&'ls' (the default): base\-2 sizes, with \f(CW\*(C`ls\*(C'\fR style single-letter suffixes (K, M, etc.) .IP "\(bu" 4 \&'iec': base\-2 sizes, with \s-1IEC\s0 binary suffixes (KiB, MiB, etc.) .IP "\(bu" 4 \&'si': base\-10 sizes, with \s-1SI\s0 decimal suffixes (kB, \s-1MB,\s0 etc.) .PP If \f(CW\*(C`\-s\*(C'\fR would return \f(CW\*(C`undef\*(C'\fR, \f(CW\*(C`size_human\*(C'\fR returns the empty string. .PP Current \s-1API\s0 available since 0.122. .SS "slurp, slurp_raw, slurp_utf8" .IX Subsection "slurp, slurp_raw, slurp_utf8" .Vb 4 \& $data = path("foo.txt")\->slurp; \& $data = path("foo.txt")\->slurp( {binmode => ":raw"} ); \& $data = path("foo.txt")\->slurp_raw; \& $data = path("foo.txt")\->slurp_utf8; .Ve .PP Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is \f(CW\*(C`binmode\*(C'\fR, which is passed to \f(CW\*(C`binmode()\*(C'\fR on the handle used for reading. .PP \&\f(CW\*(C`slurp_raw\*(C'\fR is like \f(CW\*(C`slurp\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:unix\*(C'\fR for a fast, unbuffered, raw read. .PP \&\f(CW\*(C`slurp_utf8\*(C'\fR is like \f(CW\*(C`slurp\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \&\f(CW\*(C`:unix:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:unix:utf8_strict\*(C'\fR with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a unbuffered, raw slurp will be done instead and the result decoded with \&\f(CW\*(C`Unicode::UTF8\*(C'\fR. This is just as strict and is roughly an order of magnitude faster than using \f(CW\*(C`:encoding(UTF\-8)\*(C'\fR. .PP \&\fBNote\fR: \f(CW\*(C`slurp\*(C'\fR and friends lock the filehandle before slurping. If you plan to slurp from a file created with File::Temp, be sure to close other handles or open without locking to avoid a deadlock: .PP .Vb 2 \& my $tempfile = File::Temp\->new(EXLOCK => 0); \& my $guts = path($tempfile)\->slurp; .Ve .PP Current \s-1API\s0 available since 0.004. .SS "spew, spew_raw, spew_utf8" .IX Subsection "spew, spew_raw, spew_utf8" .Vb 5 \& path("foo.txt")\->spew(@data); \& path("foo.txt")\->spew(\e@data); \& path("foo.txt")\->spew({binmode => ":raw"}, @data); \& path("foo.txt")\->spew_raw(@data); \& path("foo.txt")\->spew_utf8(@data); .Ve .PP Writes data to a file atomically. The file is written to a temporary file in the same directory, then renamed over the original. An optional hash reference may be used to pass options. The only option is \f(CW\*(C`binmode\*(C'\fR, which is passed to \&\f(CW\*(C`binmode()\*(C'\fR on the handle used for writing. .PP \&\f(CW\*(C`spew_raw\*(C'\fR is like \f(CW\*(C`spew\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:unix\*(C'\fR for a fast, unbuffered, raw write. .PP \&\f(CW\*(C`spew_utf8\*(C'\fR is like \f(CW\*(C`spew\*(C'\fR with a \f(CW\*(C`binmode\*(C'\fR of \f(CW\*(C`:unix:encoding(UTF\-8)\*(C'\fR (or \f(CW\*(C`:unix:utf8_strict\*(C'\fR with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered spew will be done instead on the data encoded with \f(CW\*(C`Unicode::UTF8\*(C'\fR. .PP \&\fB\s-1NOTE\s0\fR: because the file is written to a temporary file and then renamed, the new file will wind up with permissions based on your current umask. This is a feature to protect you from a race condition that would otherwise give different permissions than you might expect. If you really want to keep the original mode flags, use \*(L"append\*(R" with the \f(CW\*(C`truncate\*(C'\fR option. .PP Current \s-1API\s0 available since 0.011. .SS "stat, lstat" .IX Subsection "stat, lstat" .Vb 2 \& $stat = path("foo.txt")\->stat; \& $stat = path("/some/symlink")\->lstat; .Ve .PP Like calling \f(CW\*(C`stat\*(C'\fR or \f(CW\*(C`lstat\*(C'\fR from File::stat. .PP Current \s-1API\s0 available since 0.001. .SS "stringify" .IX Subsection "stringify" .Vb 2 \& $path = path("foo.txt"); \& say $path\->stringify; # same as "$path" .Ve .PP Returns a string representation of the path. Unlike \f(CW\*(C`canonpath\*(C'\fR, this method returns the path standardized with Unix-style \f(CW\*(C`/\*(C'\fR directory separators. .PP Current \s-1API\s0 available since 0.001. .SS "subsumes" .IX Subsection "subsumes" .Vb 2 \& path("foo/bar")\->subsumes("foo/bar/baz"); # true \& path("/foo/bar")\->subsumes("/foo/baz"); # false .Ve .PP Returns true if the first path is a prefix of the second path at a directory boundary. .PP This \fBdoes not\fR resolve parent directory entries (\f(CW\*(C`..\*(C'\fR) or symlinks: .PP .Vb 1 \& path("foo/bar")\->subsumes("foo/bar/../baz"); # true .Ve .PP If such things are important to you, ensure that both paths are resolved to the filesystem with \f(CW\*(C`realpath\*(C'\fR: .PP .Vb 3 \& my $p1 = path("foo/bar")\->realpath; \& my $p2 = path("foo/bar/../baz")\->realpath; \& if ( $p1\->subsumes($p2) ) { ... } .Ve .PP Current \s-1API\s0 available since 0.048. .SS "touch" .IX Subsection "touch" .Vb 2 \& path("foo.txt")\->touch; \& path("foo.txt")\->touch($epoch_secs); .Ve .PP Like the Unix \f(CW\*(C`touch\*(C'\fR utility. Creates the file if it doesn't exist, or else changes the modification and access times to the current time. If the first argument is the epoch seconds then it will be used. .PP Returns the path object so it can be easily chained with other methods: .PP .Vb 2 \& # won\*(Aqt die if foo.txt doesn\*(Aqt exist \& $content = path("foo.txt")\->touch\->slurp; .Ve .PP Current \s-1API\s0 available since 0.015. .SS "touchpath" .IX Subsection "touchpath" .Vb 1 \& path("bar/baz/foo.txt")\->touchpath; .Ve .PP Combines \f(CW\*(C`mkdir\*(C'\fR and \f(CW\*(C`touch\*(C'\fR. Creates the parent directory if it doesn't exist, before touching the file. Returns the path object like \f(CW\*(C`touch\*(C'\fR does. .PP If you need to pass options, use \f(CW\*(C`mkdir\*(C'\fR and \f(CW\*(C`touch\*(C'\fR separately: .PP .Vb 1 \& path("bar/baz")\->mkdir( \e%options )\->child("foo.txt")\->touch($epoch_secs); .Ve .PP Current \s-1API\s0 available since 0.022. .SS "visit" .IX Subsection "visit" .Vb 1 \& path("/tmp")\->visit( \e&callback, \e%options ); .Ve .PP Executes a callback for each child of a directory. It returns a hash reference with any state accumulated during iteration. .PP The options are the same as for \*(L"iterator\*(R" (which it uses internally): \&\f(CW\*(C`recurse\*(C'\fR and \f(CW\*(C`follow_symlinks\*(C'\fR. Both default to false. .PP The callback function will receive a \f(CW\*(C`Path::Tiny\*(C'\fR object as the first argument and a hash reference to accumulate state as the second argument. For example: .PP .Vb 9 \& # collect files sizes \& my $sizes = path("/tmp")\->visit( \& sub { \& my ($path, $state) = @_; \& return if $path\->is_dir; \& $state\->{$path} = \-s $path; \& }, \& { recurse => 1 } \& ); .Ve .PP For convenience, the \f(CW\*(C`Path::Tiny\*(C'\fR object will also be locally aliased as the \&\f(CW$_\fR global variable: .PP .Vb 2 \& # print paths matching /foo/ \& path("/tmp")\->visit( sub { say if /foo/ }, { recurse => 1} ); .Ve .PP If the callback returns a \fBreference\fR to a false scalar value, iteration will terminate. This is not the same as \*(L"pruning\*(R" a directory search; this just stops all iteration and returns the state hash reference. .PP .Vb 9 \& # find up to 10 files larger than 100K \& my $files = path("/tmp")\->visit( \& sub { \& my ($path, $state) = @_; \& $state\->{$path}++ if \-s $path > 102400 \& return \e0 if keys %$state == 10; \& }, \& { recurse => 1 } \& ); .Ve .PP If you want more flexible iteration, use a module like Path::Iterator::Rule. .PP Current \s-1API\s0 available since 0.062. .SS "volume" .IX Subsection "volume" .Vb 2 \& $vol = path("/tmp/foo.txt")\->volume; # "" \& $vol = path("C:/tmp/foo.txt")\->volume; # "C:" .Ve .PP Returns the volume portion of the path. This is equivalent to what File::Spec would give from \f(CW\*(C`splitpath\*(C'\fR and thus usually is the empty string on Unix-like operating systems or the drive letter for an absolute path on \f(CW\*(C`MSWin32\*(C'\fR. .PP Current \s-1API\s0 available since 0.001. .SH "EXCEPTION HANDLING" .IX Header "EXCEPTION HANDLING" Simple usage errors will generally croak. Failures of underlying Perl functions will be thrown as exceptions in the class \&\f(CW\*(C`Path::Tiny::Error\*(C'\fR. .PP A \f(CW\*(C`Path::Tiny::Error\*(C'\fR object will be a hash reference with the following fields: .IP "\(bu" 4 \&\f(CW\*(C`op\*(C'\fR — a description of the operation, usually function call and any extra info .IP "\(bu" 4 \&\f(CW\*(C`file\*(C'\fR — the file or directory relating to the error .IP "\(bu" 4 \&\f(CW\*(C`err\*(C'\fR — hold \f(CW$!\fR at the time the error was thrown .IP "\(bu" 4 \&\f(CW\*(C`msg\*(C'\fR — a string combining the above data and a Carp-like short stack trace .PP Exception objects will stringify as the \f(CW\*(C`msg\*(C'\fR field. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" .SS "\s-1PERL_PATH_TINY_NO_FLOCK\s0" .IX Subsection "PERL_PATH_TINY_NO_FLOCK" If the environment variable \f(CW\*(C`PERL_PATH_TINY_NO_FLOCK\*(C'\fR is set to a true value then flock will \s-1NOT\s0 be used when accessing files (this is not recommended). .SH "CAVEATS" .IX Header "CAVEATS" .SS "Subclassing not supported" .IX Subsection "Subclassing not supported" For speed, this class is implemented as an array based object and uses many direct function calls internally. You must not subclass it and expect things to work properly. .SS "Tilde expansion (deprecated)" .IX Subsection "Tilde expansion (deprecated)" Tilde expansion was a nice idea, but it can't easily be applied consistently across the entire \s-1API.\s0 This was a source of bugs and confusion for users. Therefore, it is \fBdeprecated\fR and its use is discouraged. Limitations to the existing, legacy behavior follow. .PP Tilde expansion will only occur if the \fBfirst\fR argument to \f(CW\*(C`path\*(C'\fR begins with a tilde. \fBNo other method does tilde expansion on its arguments\fR. If you want tilde expansion on arguments, you must explicitly wrap them in a call to \&\f(CW\*(C`path\*(C'\fR. .PP .Vb 1 \& path( "~/foo.txt" )\->copy( path( "~/bar.txt" ) ); .Ve .PP If you need a literal leading tilde, use \f(CW\*(C`path("./~whatever")\*(C'\fR so that the argument to \f(CW\*(C`path\*(C'\fR doesn't start with a tilde, but the path still resolves to the current directory. .PP Behaviour of tilde expansion with a username for non-existent users depends on the output of \f(CW\*(C`glob\*(C'\fR on the system. .SS "File locking" .IX Subsection "File locking" If flock is not supported on a platform, it will not be used, even if locking is requested. .PP In situations where a platform normally would support locking, but the flock fails due to a filesystem limitation, Path::Tiny has some heuristics to detect this and will warn once and continue in an unsafe mode. If you want this failure to be fatal, you can fatalize the 'flock' warnings category: .PP .Vb 1 \& use warnings FATAL => \*(Aqflock\*(Aq; .Ve .PP See additional caveats below. .PP \fI\s-1NFS\s0 and \s-1BSD\s0\fR .IX Subsection "NFS and BSD" .PP On \s-1BSD,\s0 Perl's flock implementation may not work to lock files on an \&\s-1NFS\s0 filesystem. If detected, this situation will warn once, as described above. .PP \fILustre\fR .IX Subsection "Lustre" .PP The Lustre filesystem does not support flock. If detected, this situation will warn once, as described above. .PP \fI\s-1AIX\s0 and locking\fR .IX Subsection "AIX and locking" .PP \&\s-1AIX\s0 requires a write handle for locking. Therefore, calls that normally open a read handle and take a shared lock instead will open a read-write handle and take an exclusive lock. If the user does not have write permission, no lock will be used. .SS "utf8 vs \s-1UTF\-8\s0" .IX Subsection "utf8 vs UTF-8" All the \f(CW*_utf8\fR methods by default use \f(CW\*(C`:encoding(UTF\-8)\*(C'\fR \*(-- either as \&\f(CW\*(C`:unix:encoding(UTF\-8)\*(C'\fR (unbuffered, for whole file operations) or \&\f(CW\*(C`:raw:encoding(UTF\-8)\*(C'\fR (buffered, for line-by-line operations). These are strict against the Unicode spec and disallows illegal Unicode codepoints or \&\s-1UTF\-8\s0 sequences. .PP Unfortunately, \f(CW\*(C`:encoding(UTF\-8)\*(C'\fR is very, very slow. If you install Unicode::UTF8 0.58 or later, that module will be used by some \f(CW*_utf8\fR methods to encode or decode data after a raw, binary input/output operation, which is much faster. Alternatively, if you install PerlIO::utf8_strict, that will be used instead of \f(CW\*(C`:encoding(UTF\-8)\*(C'\fR and is also very fast. .PP If you need the performance and can accept the security risk, \&\f(CW\*(C`slurp({binmode => ":unix:utf8"})\*(C'\fR will be faster than \f(CW\*(C`:unix:encoding(UTF\-8)\*(C'\fR (but not as fast as \f(CW\*(C`Unicode::UTF8\*(C'\fR). .PP Note that the \f(CW*_utf8\fR methods read in \fBraw\fR mode. There is no \s-1CRLF\s0 translation on Windows. If you must have \s-1CRLF\s0 translation, use the regular input/output methods with an appropriate binmode: .PP .Vb 2 \& $path\->spew_utf8($data); # raw \& $path\->spew({binmode => ":encoding(UTF\-8)"}, $data; # LF \-> CRLF .Ve .SS "Default \s-1IO\s0 layers and the open pragma" .IX Subsection "Default IO layers and the open pragma" If you have Perl 5.10 or later, file input/output methods (\f(CW\*(C`slurp\*(C'\fR, \f(CW\*(C`spew\*(C'\fR, etc.) and high-level handle opening methods ( \f(CW\*(C`filehandle\*(C'\fR, \f(CW\*(C`openr\*(C'\fR, \&\f(CW\*(C`openw\*(C'\fR, etc. ) respect default encodings set by the \f(CW\*(C`\-C\*(C'\fR switch or lexical open settings of the caller. For \s-1UTF\-8,\s0 this is almost certainly slower than using the dedicated \f(CW\*(C`_utf8\*(C'\fR methods if you have Unicode::UTF8 or PerlIP::utf8_strict. .SH "TYPE CONSTRAINTS AND COERCION" .IX Header "TYPE CONSTRAINTS AND COERCION" A standard MooseX::Types library is available at MooseX::Types::Path::Tiny. A Type::Tiny equivalent is available as Types::Path::Tiny. .SH "SEE ALSO" .IX Header "SEE ALSO" These are other file/path utilities, which may offer a different feature set than \f(CW\*(C`Path::Tiny\*(C'\fR. .IP "\(bu" 4 File::chmod .IP "\(bu" 4 File::Fu .IP "\(bu" 4 IO::All .IP "\(bu" 4 Path::Class .PP These iterators may be slightly faster than the recursive iterator in \&\f(CW\*(C`Path::Tiny\*(C'\fR: .IP "\(bu" 4 Path::Iterator::Rule .IP "\(bu" 4 File::Next .PP There are probably comparable, non-Tiny tools. Let me know if you want me to add a module to the list. .PP This module was featured in the 2013 Perl Advent Calendar <http://www.perladvent.org/2013/2013-12-18.html>. .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Path\-Tiny/issues>. You will be notified automatically of any progress on your issue. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. .PP <https://github.com/dagolden/Path\-Tiny> .PP .Vb 1 \& git clone https://github.com/dagolden/Path\-Tiny.git .Ve .SH "AUTHOR" .IX Header "AUTHOR" David Golden <dagolden@cpan.org> .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Alex Efros <powerman@powerman.name> .IP "\(bu" 4 Aristotle Pagaltzis <pagaltzis@gmx.de> .IP "\(bu" 4 Chris Williams <bingos@cpan.org> .IP "\(bu" 4 Dan Book <grinnz@grinnz.com> .IP "\(bu" 4 Dave Rolsky <autarch@urth.org> .IP "\(bu" 4 David Steinbrunner <dsteinbrunner@pobox.com> .IP "\(bu" 4 Doug Bell <madcityzen@gmail.com> .IP "\(bu" 4 Elvin Aslanov <rwp.primary@gmail.com> .IP "\(bu" 4 Flavio Poletti <flavio@polettix.it> .IP "\(bu" 4 Gabor Szabo <szabgab@cpan.org> .IP "\(bu" 4 Gabriel Andrade <gabiruh@gmail.com> .IP "\(bu" 4 George Hartzell <hartzell@cpan.org> .IP "\(bu" 4 Geraud Continsouzas <geraud@scsi.nc> .IP "\(bu" 4 Goro Fuji <gfuji@cpan.org> .IP "\(bu" 4 Graham Knop <haarg@haarg.org> .IP "\(bu" 4 Graham Ollis <plicease@cpan.org> .IP "\(bu" 4 Ian Sillitoe <ian@sillit.com> .IP "\(bu" 4 James Hunt <james@niftylogic.com> .IP "\(bu" 4 John Karr <brainbuz@brainbuz.org> .IP "\(bu" 4 Karen Etheridge <ether@cpan.org> .IP "\(bu" 4 Mark Ellis <mark.ellis@cartridgesave.co.uk> .IP "\(bu" 4 Martin H. Sluka <fany@cpan.org> .IP "\(bu" 4 Martin Kjeldsen <mk@bluepipe.dk> .IP "\(bu" 4 Mary Ehlers <regina.verb.ae@gmail.com> .IP "\(bu" 4 Michael G. Schwern <mschwern@cpan.org> .IP "\(bu" 4 Nicolas R <nicolas@atoomic.org> .IP "\(bu" 4 Nicolas Rochelemagne <rochelemagne@cpanel.net> .IP "\(bu" 4 Nigel Gregoire <nigelgregoire@gmail.com> .IP "\(bu" 4 Philippe Bruhat (BooK) <book@cpan.org> .IP "\(bu" 4 regina-verbae <regina\-verbae@users.noreply.github.com> .IP "\(bu" 4 Roy Ivy \s-1III\s0 <rivy@cpan.org> .IP "\(bu" 4 Shlomi Fish <shlomif@shlomifish.org> .IP "\(bu" 4 Smylers <Smylers@stripey.com> .IP "\(bu" 4 Tatsuhiko Miyagawa <miyagawa@bulknews.net> .IP "\(bu" 4 Toby Inkster <tobyink@cpan.org> .IP "\(bu" 4 Yanick Champoux <yanick@babyl.dyndns.org> .IP "\(bu" 4 김도형 \- Keedi Kim <keedi@cpan.org> .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2014 by David Golden. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve blib/man3/.exists 0000644 00000000000 15125124546 0007625 0 ustar 00 blib/man1/.exists 0000644 00000000000 15125124546 0007623 0 ustar 00 blib/arch/.exists 0000644 00000000000 15125124546 0007704 0 ustar 00 blib/arch/auto/Path/Tiny/.exists 0000644 00000000000 15125124546 0012473 0 ustar 00 blib/bin/.exists 0000644 00000000000 15125124546 0007537 0 ustar 00 blib/script/.exists 0000644 00000000000 15125124546 0010273 0 ustar 00 blib/lib/Path/.exists 0000644 00000000000 15125124546 0010431 0 ustar 00 blib/lib/Path/Tiny.pm 0000444 00000373402 15125124546 0010413 0 ustar 00 use 5.008001; use strict; use warnings; package Path::Tiny; # ABSTRACT: File path utility our $VERSION = '0.146'; # Dependencies use Config; use Exporter 5.57 (qw/import/); use File::Spec 0.86 (); # shipped with 5.8.1 use Carp (); our @EXPORT = qw/path/; our @EXPORT_OK = qw/cwd rootdir tempfile tempdir/; use constant { PATH => 0, CANON => 1, VOL => 2, DIR => 3, FILE => 4, TEMP => 5, IS_WIN32 => ( $^O eq 'MSWin32' ), }; use overload ( q{""} => 'stringify', bool => sub () { 1 }, fallback => 1, ); # FREEZE/THAW per Sereal/CBOR/Types::Serialiser protocol sub THAW { return path( $_[2] ) } { no warnings 'once'; *TO_JSON = *FREEZE = \&stringify }; my $HAS_UU; # has Unicode::UTF8; lazily populated sub _check_UU { local $SIG{__DIE__}; # prevent outer handler from being called !!eval { require Unicode::UTF8; Unicode::UTF8->VERSION(0.58); 1; }; } my $HAS_PU; # has PerlIO::utf8_strict; lazily populated sub _check_PU { local $SIG{__DIE__}; # prevent outer handler from being called !!eval { # MUST preload Encode or $SIG{__DIE__} localization fails # on some Perl 5.8.8 (maybe other 5.8.*) compiled with -O2. require Encode; require PerlIO::utf8_strict; PerlIO::utf8_strict->VERSION(0.003); 1; }; } my $HAS_FLOCK = $Config{d_flock} || $Config{d_fcntl_can_lock} || $Config{d_lockf}; # notions of "root" directories differ on Win32: \\server\dir\ or C:\ or \ my $SLASH = qr{[\\/]}; my $NOTSLASH = qr{[^\\/]}; my $DRV_VOL = qr{[a-z]:}i; my $UNC_VOL = qr{$SLASH $SLASH $NOTSLASH+ $SLASH $NOTSLASH+}x; my $WIN32_ROOT = qr{(?: $UNC_VOL $SLASH | $DRV_VOL $SLASH | $SLASH )}x; sub _win32_vol { my ( $path, $drv ) = @_; require Cwd; my $dcwd = eval { Cwd::getdcwd($drv) }; # C: -> C:\some\cwd # getdcwd on non-existent drive returns empty string # so just use the original drive Z: -> Z: $dcwd = "$drv" unless defined $dcwd && length $dcwd; # normalize dwcd to end with a slash: might be C:\some\cwd or D:\ or Z: $dcwd =~ s{$SLASH?\z}{/}; # make the path absolute with dcwd $path =~ s{^$DRV_VOL}{$dcwd}; return $path; } # This is a string test for before we have the object; see is_rootdir for well-formed # object test sub _is_root { return IS_WIN32() ? ( $_[0] =~ /^$WIN32_ROOT\z/ ) : ( $_[0] eq '/' ); } BEGIN { *_same = IS_WIN32() ? sub { lc( $_[0] ) eq lc( $_[1] ) } : sub { $_[0] eq $_[1] }; } # mode bits encoded for chmod in symbolic mode my %MODEBITS = ( om => 0007, gm => 0070, um => 0700 ); ## no critic { my $m = 0; $MODEBITS{$_} = ( 1 << $m++ ) for qw/ox ow or gx gw gr ux uw ur/ }; sub _symbolic_chmod { my ( $mode, $symbolic ) = @_; for my $clause ( split /,\s*/, $symbolic ) { if ( $clause =~ m{\A([augo]+)([=+-])([rwx]+)\z} ) { my ( $who, $action, $perms ) = ( $1, $2, $3 ); $who =~ s/a/ugo/g; for my $w ( split //, $who ) { my $p = 0; $p |= $MODEBITS{"$w$_"} for split //, $perms; if ( $action eq '=' ) { $mode = ( $mode & ~$MODEBITS{"${w}m"} ) | $p; } else { $mode = $action eq "+" ? ( $mode | $p ) : ( $mode & ~$p ); } } } else { Carp::croak("Invalid mode clause '$clause' for chmod()"); } } return $mode; } # flock doesn't work on NFS on BSD or on some filesystems like lustre. # Since program authors often can't control or detect that, we warn once # instead of being fatal if we can detect it and people who need it strict # can fatalize the 'flock' category #<<< No perltidy { package flock; use warnings::register } #>>> my $WARNED_NO_FLOCK = 0; sub _throw { my ( $self, $function, $file, $msg ) = @_; if ( $function =~ /^flock/ && $! =~ /operation not supported|function not implemented/i && !warnings::fatal_enabled('flock') ) { if ( !$WARNED_NO_FLOCK ) { warnings::warn( flock => "Flock not available: '$!': continuing in unsafe mode" ); $WARNED_NO_FLOCK++; } } else { $msg = $! unless defined $msg; Path::Tiny::Error->throw( $function, ( defined $file ? $file : $self->[PATH] ), $msg ); } return; } # cheapo option validation sub _get_args { my ( $raw, @valid ) = @_; if ( defined($raw) && ref($raw) ne 'HASH' ) { my ( undef, undef, undef, $called_as ) = caller(1); $called_as =~ s{^.*::}{}; Carp::croak("Options for $called_as must be a hash reference"); } my $cooked = {}; for my $k (@valid) { $cooked->{$k} = delete $raw->{$k} if exists $raw->{$k}; } if ( keys %$raw ) { my ( undef, undef, undef, $called_as ) = caller(1); $called_as =~ s{^.*::}{}; Carp::croak( "Invalid option(s) for $called_as: " . join( ", ", keys %$raw ) ); } return $cooked; } #--------------------------------------------------------------------------# # Constructors #--------------------------------------------------------------------------# #pod =construct path #pod #pod $path = path("foo/bar"); #pod $path = path("/tmp", "file.txt"); # list #pod $path = path("."); # cwd #pod #pod Constructs a C<Path::Tiny> object. It doesn't matter if you give a file or #pod directory path. It's still up to you to call directory-like methods only on #pod directories and file-like methods only on files. This function is exported #pod automatically by default. #pod #pod The first argument must be defined and have non-zero length or an exception #pod will be thrown. This prevents subtle, dangerous errors with code like #pod C<< path( maybe_undef() )->remove_tree >>. #pod #pod B<DEPRECATED>: If and only if the B<first> character of the B<first> argument #pod to C<path> is a tilde ('~'), then tilde replacement will be applied to the #pod first path segment. A single tilde will be replaced with C<glob('~')> and a #pod tilde followed by a username will be replaced with output of #pod C<glob('~username')>. B<No other method does tilde expansion on its arguments>. #pod See L</Tilde expansion (deprecated)> for more. #pod #pod On Windows, if the path consists of a drive identifier without a path component #pod (C<C:> or C<D:>), it will be expanded to the absolute path of the current #pod directory on that volume using C<Cwd::getdcwd()>. #pod #pod If called with a single C<Path::Tiny> argument, the original is returned unless #pod the original is holding a temporary file or directory reference in which case a #pod stringified copy is made. #pod #pod $path = path("foo/bar"); #pod $temp = Path::Tiny->tempfile; #pod #pod $p2 = path($path); # like $p2 = $path #pod $t2 = path($temp); # like $t2 = path( "$temp" ) #pod #pod This optimizes copies without proliferating references unexpectedly if a copy is #pod made by code outside your control. #pod #pod Current API available since 0.017. #pod #pod =cut sub path { my $path = shift; Carp::croak("Path::Tiny paths require defined, positive-length parts") unless 1 + @_ == grep { defined && length } $path, @_; # non-temp Path::Tiny objects are effectively immutable and can be reused if ( !@_ && ref($path) eq __PACKAGE__ && !$path->[TEMP] ) { return $path; } # stringify objects $path = "$path"; # do any tilde expansions my ($tilde) = $path =~ m{^(~[^/]*)}; if ( defined $tilde ) { # Escape File::Glob metacharacters (my $escaped = $tilde) =~ s/([\[\{\*\?\\])/\\$1/g; require File::Glob; my ($homedir) = File::Glob::bsd_glob($escaped); if (defined $homedir && ! $File::Glob::ERROR) { $homedir =~ tr[\\][/] if IS_WIN32(); $path =~ s{^\Q$tilde\E}{$homedir}; } } unshift @_, $path; goto &_pathify; } # _path is like path but without tilde expansion sub _path { my $path = shift; Carp::croak("Path::Tiny paths require defined, positive-length parts") unless 1 + @_ == grep { defined && length } $path, @_; # non-temp Path::Tiny objects are effectively immutable and can be reused if ( !@_ && ref($path) eq __PACKAGE__ && !$path->[TEMP] ) { return $path; } # stringify objects $path = "$path"; unshift @_, $path; goto &_pathify; } # _pathify expects one or more string arguments, then joins and canonicalizes # them into an object. sub _pathify { my $path = shift; # expand relative volume paths on windows; put trailing slash on UNC root if ( IS_WIN32() ) { $path = _win32_vol( $path, $1 ) if $path =~ m{^($DRV_VOL)(?:$NOTSLASH|\z)}; $path .= "/" if $path =~ m{^$UNC_VOL\z}; } # concatenations stringifies objects, too if (@_) { $path .= ( _is_root($path) ? "" : "/" ) . join( "/", @_ ); } # canonicalize, but with unix slashes and put back trailing volume slash my $cpath = $path = File::Spec->canonpath($path); $path =~ tr[\\][/] if IS_WIN32(); $path = "/" if $path eq '/..'; # for old File::Spec $path .= "/" if IS_WIN32() && $path =~ m{^$UNC_VOL\z}; # root paths must always have a trailing slash, but other paths must not if ( _is_root($path) ) { $path =~ s{/?\z}{/}; } else { $path =~ s{/\z}{}; } bless [ $path, $cpath ], __PACKAGE__; } #pod =construct new #pod #pod $path = Path::Tiny->new("foo/bar"); #pod #pod This is just like C<path>, but with method call overhead. (Why would you #pod do that?) #pod #pod Current API available since 0.001. #pod #pod =cut sub new { shift; path(@_) } #pod =construct cwd #pod #pod $path = Path::Tiny->cwd; # path( Cwd::getcwd ) #pod $path = cwd; # optional export #pod #pod Gives you the absolute path to the current directory as a C<Path::Tiny> object. #pod This is slightly faster than C<< path(".")->absolute >>. #pod #pod C<cwd> may be exported on request and used as a function instead of as a #pod method. #pod #pod Current API available since 0.018. #pod #pod =cut sub cwd { require Cwd; return _path( Cwd::getcwd() ); } #pod =construct rootdir #pod #pod $path = Path::Tiny->rootdir; # / #pod $path = rootdir; # optional export #pod #pod Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if you're too #pod picky for C<path("/")>. #pod #pod C<rootdir> may be exported on request and used as a function instead of as a #pod method. #pod #pod Current API available since 0.018. #pod #pod =cut sub rootdir { _path( File::Spec->rootdir ) } #pod =construct tempfile, tempdir #pod #pod $temp = Path::Tiny->tempfile( @options ); #pod $temp = Path::Tiny->tempdir( @options ); #pod $temp = $dirpath->tempfile( @options ); #pod $temp = $dirpath->tempdir( @options ); #pod $temp = tempfile( @options ); # optional export #pod $temp = tempdir( @options ); # optional export #pod #pod C<tempfile> passes the options to C<< File::Temp->new >> and returns a #pod C<Path::Tiny> object with the file name. The C<TMPDIR> option will be enabled #pod by default, but you can override that by passing C<< TMPDIR => 0 >> along with #pod the options. (If you use an absolute C<TEMPLATE> option, you will want to #pod disable C<TMPDIR>.) #pod #pod The resulting C<File::Temp> object is cached. When the C<Path::Tiny> object is #pod destroyed, the C<File::Temp> object will be as well. #pod #pod C<File::Temp> annoyingly requires you to specify a custom template in slightly #pod different ways depending on which function or method you call, but #pod C<Path::Tiny> lets you ignore that and can take either a leading template or a #pod C<TEMPLATE> option and does the right thing. #pod #pod $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok #pod $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok #pod #pod The tempfile path object will be normalized to have an absolute path, even if #pod created in a relative directory using C<DIR>. If you want it to have #pod the C<realpath> instead, pass a leading options hash like this: #pod #pod $real_temp = tempfile({realpath => 1}, @options); #pod #pod C<tempdir> is just like C<tempfile>, except it calls #pod C<< File::Temp->newdir >> instead. #pod #pod Both C<tempfile> and C<tempdir> may be exported on request and used as #pod functions instead of as methods. #pod #pod The methods can be called on an instances representing a #pod directory. In this case, the directory is used as the base to create the #pod temporary file/directory, setting the C<DIR> option in File::Temp. #pod #pod my $target_dir = path('/to/destination'); #pod my $tempfile = $target_dir->tempfile('foobarXXXXXX'); #pod $tempfile->spew('A lot of data...'); # not atomic #pod $tempfile->move($target_dir->child('foobar')); # hopefully atomic #pod #pod In this case, any value set for option C<DIR> is ignored. #pod #pod B<Note>: for tempfiles, the filehandles from File::Temp are closed and not #pod reused. This is not as secure as using File::Temp handles directly, but is #pod less prone to deadlocks or access problems on some platforms. Think of what #pod C<Path::Tiny> gives you to be just a temporary file B<name> that gets cleaned #pod up. #pod #pod B<Note 2>: if you don't want these cleaned up automatically when the object #pod is destroyed, File::Temp requires different options for directories and #pod files. Use C<< CLEANUP => 0 >> for directories and C<< UNLINK => 0 >> for #pod files. #pod #pod B<Note 3>: Don't lose the temporary object by chaining a method call instead #pod of storing it: #pod #pod my $lost = tempdir()->child("foo"); # tempdir cleaned up right away #pod #pod B<Note 4>: The cached object may be accessed with the L</cached_temp> method. #pod Keeping a reference to, or modifying the cached object may break the #pod behavior documented above and is not supported. Use at your own risk. #pod #pod Current API available since 0.119. #pod #pod =cut sub tempfile { my ( $opts, $maybe_template, $args ) = _parse_file_temp_args(tempfile => @_); # File::Temp->new demands TEMPLATE $args->{TEMPLATE} = $maybe_template->[0] if @$maybe_template; require File::Temp; my $temp = File::Temp->new( TMPDIR => 1, %$args ); close $temp; my $self = $opts->{realpath} ? _path($temp)->realpath : _path($temp)->absolute; $self->[TEMP] = $temp; # keep object alive while we are return $self; } sub tempdir { my ( $opts, $maybe_template, $args ) = _parse_file_temp_args(tempdir => @_); require File::Temp; my $temp = File::Temp->newdir( @$maybe_template, TMPDIR => 1, %$args ); my $self = $opts->{realpath} ? _path($temp)->realpath : _path($temp)->absolute; $self->[TEMP] = $temp; # keep object alive while we are # Some ActiveState Perls for Windows break Cwd in ways that lead # File::Temp to get confused about what path to remove; this # monkey-patches the object with our own view of the absolute path $temp->{REALNAME} = $self->[CANON] if IS_WIN32; return $self; } # normalize the various ways File::Temp does templates sub _parse_file_temp_args { my $called_as = shift; if ( @_ && $_[0] eq 'Path::Tiny' ) { shift } # class method elsif ( @_ && eval{$_[0]->isa('Path::Tiny')} ) { my $dir = shift; if (! $dir->is_dir) { $dir->_throw( $called_as, $dir, "is not a directory object" ); } push @_, DIR => $dir->stringify; # no overriding } my $opts = ( @_ && ref $_[0] eq 'HASH' ) ? shift @_ : {}; $opts = _get_args( $opts, qw/realpath/ ); my $leading_template = ( scalar(@_) % 2 == 1 ? shift(@_) : '' ); my %args = @_; %args = map { uc($_), $args{$_} } keys %args; my @template = ( exists $args{TEMPLATE} ? delete $args{TEMPLATE} : $leading_template ? $leading_template : () ); return ( $opts, \@template, \%args ); } #--------------------------------------------------------------------------# # Private methods #--------------------------------------------------------------------------# sub _splitpath { my ($self) = @_; @{$self}[ VOL, DIR, FILE ] = File::Spec->splitpath( $self->[PATH] ); } sub _resolve_symlinks { my ($self) = @_; my $new = $self; my ( $count, %seen ) = 0; while ( -l $new->[PATH] ) { if ( $seen{ $new->[PATH] }++ ) { $self->_throw( 'readlink', $self->[PATH], "symlink loop detected" ); } if ( ++$count > 100 ) { $self->_throw( 'readlink', $self->[PATH], "maximum symlink depth exceeded" ); } my $resolved = readlink $new->[PATH]; $new->_throw( 'readlink', $new->[PATH] ) unless defined $resolved; $resolved = _path($resolved); $new = $resolved->is_absolute ? $resolved : $new->sibling($resolved); } return $new; } sub _replacment_path { my ($self) = @_; my $unique_suffix = $$ . int( rand( 2**31 ) ); my $temp = _path( $self . $unique_suffix ); # If filename with process+random suffix is too long, use a shorter # version that doesn't preserve the basename. if ( length $temp->basename > 255 ) { $temp = $self->sibling( "temp" . $unique_suffix ); } return $temp; } #--------------------------------------------------------------------------# # Public methods #--------------------------------------------------------------------------# #pod =method absolute #pod #pod $abs = path("foo/bar")->absolute; #pod $abs = path("foo/bar")->absolute("/tmp"); #pod #pod Returns a new C<Path::Tiny> object with an absolute path (or itself if already #pod absolute). If no argument is given, the current directory is used as the #pod absolute base path. If an argument is given, it will be converted to an #pod absolute path (if it is not already) and used as the absolute base path. #pod #pod This will not resolve upward directories ("foo/../bar") unless C<canonpath> #pod in L<File::Spec> would normally do so on your platform. If you need them #pod resolved, you must call the more expensive C<realpath> method instead. #pod #pod On Windows, an absolute path without a volume component will have it added #pod based on the current drive. #pod #pod Current API available since 0.101. #pod #pod =cut sub absolute { my ( $self, $base ) = @_; # absolute paths handled differently by OS if (IS_WIN32) { return $self if length $self->volume; # add missing volume if ( $self->is_absolute ) { require Cwd; # use Win32::GetCwd not Cwd::getdcwd because we're sure # to have the former but not necessarily the latter my ($drv) = Win32::GetCwd() =~ /^($DRV_VOL | $UNC_VOL)/x; return _path( $drv . $self->[PATH] ); } } else { return $self if $self->is_absolute; } # no base means use current directory as base require Cwd; return _path( Cwd::getcwd(), $_[0]->[PATH] ) unless defined $base; # relative base should be made absolute; we check is_absolute rather # than unconditionally make base absolute so that "/foo" doesn't become # "C:/foo" on Windows. $base = _path($base); return _path( ( $base->is_absolute ? $base : $base->absolute ), $_[0]->[PATH] ); } #pod =method append, append_raw, append_utf8 #pod #pod path("foo.txt")->append(@data); #pod path("foo.txt")->append(\@data); #pod path("foo.txt")->append({binmode => ":raw"}, @data); #pod path("foo.txt")->append_raw(@data); #pod path("foo.txt")->append_utf8(@data); #pod #pod Appends data to a file. The file is locked with C<flock> prior to writing #pod and closed afterwards. An optional hash reference may be used to pass #pod options. Valid options are: #pod #pod =for :list #pod * C<binmode>: passed to C<binmode()> on the handle used for writing. #pod * C<truncate>: truncates the file after locking and before appending #pod #pod The C<truncate> option is a way to replace the contents of a file #pod B<in place>, unlike L</spew> which writes to a temporary file and then #pod replaces the original (if it exists). #pod #pod C<append_raw> is like C<append> with a C<binmode> of C<:unix> for a fast, #pod unbuffered, raw write. #pod #pod C<append_utf8> is like C<append> with an unbuffered C<binmode> #pod C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with #pod L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, an #pod unbuffered, raw append will be done instead on the data encoded with #pod C<Unicode::UTF8>. #pod #pod Current API available since 0.060. #pod #pod =cut sub append { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; my $mode = $args->{truncate} ? ">" : ">>"; my $fh = $self->filehandle( { locked => 1 }, $mode, $binmode ); print( {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data ) or self->_throw('print'); close $fh or $self->_throw('close'); } sub append_raw { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); $args->{binmode} = ':unix'; append( $self, $args, @data ); } sub append_utf8 { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { $args->{binmode} = ":unix"; append( $self, $args, map { Unicode::UTF8::encode_utf8($_) } @data ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $args->{binmode} = ":unix:utf8_strict"; append( $self, $args, @data ); } else { $args->{binmode} = ":unix:encoding(UTF-8)"; append( $self, $args, @data ); } } #pod =method assert #pod #pod $path = path("foo.txt")->assert( sub { $_->exists } ); #pod #pod Returns the invocant after asserting that a code reference argument returns #pod true. When the assertion code reference runs, it will have the invocant #pod object in the C<$_> variable. If it returns false, an exception will be #pod thrown. The assertion code reference may also throw its own exception. #pod #pod If no assertion is provided, the invocant is returned without error. #pod #pod Current API available since 0.062. #pod #pod =cut sub assert { my ( $self, $assertion ) = @_; return $self unless $assertion; if ( ref $assertion eq 'CODE' ) { local $_ = $self; $assertion->() or Path::Tiny::Error->throw( "assert", $self->[PATH], "failed assertion" ); } else { Carp::croak("argument to assert must be a code reference argument"); } return $self; } #pod =method basename #pod #pod $name = path("foo/bar.txt")->basename; # bar.txt #pod $name = path("foo.txt")->basename('.txt'); # foo #pod $name = path("foo.txt")->basename(qr/.txt/); # foo #pod $name = path("foo.txt")->basename(@suffixes); #pod #pod Returns the file portion or last directory portion of a path. #pod #pod Given a list of suffixes as strings or regular expressions, any that match at #pod the end of the file portion or last directory portion will be removed before #pod the result is returned. #pod #pod Current API available since 0.054. #pod #pod =cut sub basename { my ( $self, @suffixes ) = @_; $self->_splitpath unless defined $self->[FILE]; my $file = $self->[FILE]; for my $s (@suffixes) { my $re = ref($s) eq 'Regexp' ? qr/$s\z/ : qr/\Q$s\E\z/; last if $file =~ s/$re//; } return $file; } #pod =method canonpath #pod #pod $canonical = path("foo/bar")->canonpath; # foo\bar on Windows #pod #pod Returns a string with the canonical format of the path name for #pod the platform. In particular, this means directory separators #pod will be C<\> on Windows. #pod #pod Current API available since 0.001. #pod #pod =cut sub canonpath { $_[0]->[CANON] } #pod =method cached_temp #pod #pod Returns the cached C<File::Temp> or C<File::Temp::Dir> object if the #pod C<Path::Tiny> object was created with C</tempfile> or C</tempdir>. #pod If there is no such object, this method throws. #pod #pod B<WARNING>: Keeping a reference to, or modifying the cached object may #pod break the behavior documented for temporary files and directories created #pod with C<Path::Tiny> and is not supported. Use at your own risk. #pod #pod Current API available since 0.101. #pod #pod =cut sub cached_temp { my $self = shift; $self->_throw( "cached_temp", $self, "has no cached File::Temp object" ) unless defined $self->[TEMP]; return $self->[TEMP]; } #pod =method child #pod #pod $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" #pod $file = path("/tmp")->child(@parts); #pod #pod Returns a new C<Path::Tiny> object relative to the original. Works #pod like C<catfile> or C<catdir> from File::Spec, but without caring about #pod file or directories. #pod #pod B<WARNING>: because the argument could contain C<..> or refer to symlinks, #pod there is no guarantee that the new path refers to an actual descendent of #pod the original. If this is important to you, transform parent and child with #pod L</realpath> and check them with L</subsumes>. #pod #pod Current API available since 0.001. #pod #pod =cut sub child { my ( $self, @parts ) = @_; return _path( $self->[PATH], @parts ); } #pod =method children #pod #pod @paths = path("/tmp")->children; #pod @paths = path("/tmp")->children( qr/\.txt\z/ ); #pod #pod Returns a list of C<Path::Tiny> objects for all files and directories #pod within a directory. Excludes "." and ".." automatically. #pod #pod If an optional C<qr//> argument is provided, it only returns objects for child #pod names that match the given regular expression. Only the base name is used #pod for matching: #pod #pod @paths = path("/tmp")->children( qr/^foo/ ); #pod # matches children like the glob foo* #pod #pod Current API available since 0.028. #pod #pod =cut sub children { my ( $self, $filter ) = @_; my $dh; opendir $dh, $self->[PATH] or $self->_throw('opendir'); my @children = readdir $dh; closedir $dh or $self->_throw('closedir'); if ( not defined $filter ) { @children = grep { $_ ne '.' && $_ ne '..' } @children; } elsif ( $filter && ref($filter) eq 'Regexp' ) { @children = grep { $_ ne '.' && $_ ne '..' && $_ =~ $filter } @children; } else { Carp::croak("Invalid argument '$filter' for children()"); } return map { _path( $self->[PATH], $_ ) } @children; } #pod =method chmod #pod #pod path("foo.txt")->chmod(0777); #pod path("foo.txt")->chmod("0755"); #pod path("foo.txt")->chmod("go-w"); #pod path("foo.txt")->chmod("a=r,u+wx"); #pod #pod Sets file or directory permissions. The argument can be a numeric mode, a #pod octal string beginning with a "0" or a limited subset of the symbolic mode use #pod by F</bin/chmod>. #pod #pod The symbolic mode must be a comma-delimited list of mode clauses. Clauses must #pod match C<< qr/\A([augo]+)([=+-])([rwx]+)\z/ >>, which defines "who", "op" and #pod "perms" parameters for each clause. Unlike F</bin/chmod>, all three parameters #pod are required for each clause, multiple ops are not allowed and permissions #pod C<stugoX> are not supported. (See L<File::chmod> for more complex needs.) #pod #pod Current API available since 0.053. #pod #pod =cut sub chmod { my ( $self, $new_mode ) = @_; my $mode; if ( $new_mode =~ /\d/ ) { $mode = ( $new_mode =~ /^0/ ? oct($new_mode) : $new_mode ); } elsif ( $new_mode =~ /[=+-]/ ) { $mode = _symbolic_chmod( $self->stat->mode & 07777, $new_mode ); ## no critic } else { Carp::croak("Invalid mode argument '$new_mode' for chmod()"); } CORE::chmod( $mode, $self->[PATH] ) or $self->_throw("chmod"); return 1; } #pod =method copy #pod #pod path("/tmp/foo.txt")->copy("/tmp/bar.txt"); #pod #pod Copies the current path to the given destination using L<File::Copy>'s #pod C<copy> function. Upon success, returns the C<Path::Tiny> object for the #pod newly copied file. #pod #pod Current API available since 0.070. #pod #pod =cut # XXX do recursively for directories? sub copy { my ( $self, $dest ) = @_; require File::Copy; File::Copy::copy( $self->[PATH], $dest ) or Carp::croak("copy failed for $self to $dest: $!"); return -d $dest ? _path( $dest, $self->basename ) : _path($dest); } #pod =method digest #pod #pod $obj = path("/tmp/foo.txt")->digest; # SHA-256 #pod $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected #pod $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); #pod #pod Returns a hexadecimal digest for a file. An optional hash reference of options may #pod be given. The only option is C<chunk_size>. If C<chunk_size> is given, that many #pod bytes will be read at a time. If not provided, the entire file will be slurped #pod into memory to compute the digest. #pod #pod Any subsequent arguments are passed to the constructor for L<Digest> to select #pod an algorithm. If no arguments are given, the default is SHA-256. #pod #pod Current API available since 0.056. #pod #pod =cut sub digest { my ( $self, @opts ) = @_; my $args = ( @opts && ref $opts[0] eq 'HASH' ) ? shift @opts : {}; $args = _get_args( $args, qw/chunk_size/ ); unshift @opts, 'SHA-256' unless @opts; require Digest; my $digest = Digest->new(@opts); if ( $args->{chunk_size} ) { my $fh = $self->filehandle( { locked => 1 }, "<", ":unix" ); my $buf; while (!eof($fh)) { my $rc = read $fh, $buf, $args->{chunk_size}; $self->_throw('read') unless defined $rc; $digest->add($buf); } } else { $digest->add( $self->slurp_raw ); } return $digest->hexdigest; } #pod =method dirname (deprecated) #pod #pod $name = path("/tmp/foo.txt")->dirname; # "/tmp/" #pod #pod Returns the directory portion you would get from calling #pod C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a path without a #pod parent directory portion. Because L<File::Spec> is inconsistent, the result #pod might or might not have a trailing slash. Because of this, this method is #pod B<deprecated>. #pod #pod A better, more consistently approach is likely C<< $path->parent->stringify >>, #pod which will not have a trailing slash except for a root directory. #pod #pod Deprecated in 0.056. #pod #pod =cut sub dirname { my ($self) = @_; $self->_splitpath unless defined $self->[DIR]; return length $self->[DIR] ? $self->[DIR] : "."; } #pod =method edit, edit_raw, edit_utf8 #pod #pod path("foo.txt")->edit( \&callback, $options ); #pod path("foo.txt")->edit_utf8( \&callback ); #pod path("foo.txt")->edit_raw( \&callback ); #pod #pod These are convenience methods that allow "editing" a file using a single #pod callback argument. They slurp the file using C<slurp>, place the contents #pod inside a localized C<$_> variable, call the callback function (without #pod arguments), and then write C<$_> (presumably mutated) back to the #pod file with C<spew>. #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<binmode>, which is passed to C<slurp> and C<spew>. #pod #pod C<edit_utf8> and C<edit_raw> act like their respective C<slurp_*> and #pod C<spew_*> methods. #pod #pod Current API available since 0.077. #pod #pod =cut sub edit { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/binmode/ ); Carp::croak("Callback for edit() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; local $_ = $self->slurp( exists( $args->{binmode} ) ? { binmode => $args->{binmode} } : () ); $cb->(); $self->spew( $args, $_ ); return; } # this is done long-hand to benefit from slurp_utf8 optimizations sub edit_utf8 { my ( $self, $cb ) = @_; Carp::croak("Callback for edit_utf8() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; local $_ = $self->slurp_utf8; $cb->(); $self->spew_utf8($_); return; } sub edit_raw { $_[2] = { binmode => ":unix" }; goto &edit } #pod =method edit_lines, edit_lines_utf8, edit_lines_raw #pod #pod path("foo.txt")->edit_lines( \&callback, $options ); #pod path("foo.txt")->edit_lines_utf8( \&callback ); #pod path("foo.txt")->edit_lines_raw( \&callback ); #pod #pod These are convenience methods that allow "editing" a file's lines using a #pod single callback argument. They iterate over the file: for each line, the #pod line is put into a localized C<$_> variable, the callback function is #pod executed (without arguments) and then C<$_> is written to a temporary file. #pod When iteration is finished, the temporary file is atomically renamed over #pod the original. #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<binmode>, which is passed to the method that open handles for reading and #pod writing. #pod #pod C<edit_lines_raw> is like C<edit_lines> with a buffered C<binmode> of #pod C<:raw>. #pod #pod C<edit_lines_utf8> is like C<edit_lines> with a buffered C<binmode> #pod C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with #pod L<PerlIO::utf8_strict>). #pod #pod Current API available since 0.077. #pod #pod =cut sub edit_lines { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/binmode/ ); Carp::croak("Callback for edit_lines() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; my $binmode = $args->{binmode}; # get default binmode from caller's lexical scope (see "perldoc open") $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; # writing needs to follow the link and create the tempfile in the same # dir for later atomic rename my $resolved_path = $self->_resolve_symlinks; my $temp = $resolved_path->_replacment_path; my $temp_fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode ); my $in_fh = $self->filehandle( { locked => 1 }, '<', $binmode ); local $_; while (! eof($in_fh) ) { defined( $_ = readline($in_fh) ) or $self->_throw('readline'); $cb->(); $temp_fh->print($_) or self->_throw('print', $temp); } close $temp_fh or $self->_throw( 'close', $temp ); close $in_fh or $self->_throw('close'); return $temp->move($resolved_path); } sub edit_lines_raw { $_[2] = { binmode => ":raw" }; goto &edit_lines } sub edit_lines_utf8 { if ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $_[2] = { binmode => ":raw:utf8_strict" }; } else { $_[2] = { binmode => ":raw:encoding(UTF-8)" }; } goto &edit_lines; } #pod =method exists, is_file, is_dir #pod #pod if ( path("/tmp")->exists ) { ... } # -e #pod if ( path("/tmp")->is_dir ) { ... } # -d #pod if ( path("/tmp")->is_file ) { ... } # -e && ! -d #pod #pod Implements file test operations, this means the file or directory actually has #pod to exist on the filesystem. Until then, it's just a path. #pod #pod B<Note>: C<is_file> is not C<-f> because C<-f> is not the opposite of C<-d>. #pod C<-f> means "plain file", excluding symlinks, devices, etc. that often can be #pod read just like files. #pod #pod Use C<-f> instead if you really mean to check for a plain file. #pod #pod Current API available since 0.053. #pod #pod =cut sub exists { -e $_[0]->[PATH] } sub is_file { -e $_[0]->[PATH] && !-d _ } sub is_dir { -d $_[0]->[PATH] } #pod =method filehandle #pod #pod $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); #pod $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); #pod $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); #pod #pod Returns an open file handle. The C<$mode> argument must be a Perl-style #pod read/write mode string ("<" ,">", ">>", etc.). If a C<$binmode> #pod is given, it is set during the C<open> call. #pod #pod An optional hash reference may be used to pass options. #pod #pod The C<locked> option governs file locking; if true, handles opened for writing, #pod appending or read-write are locked with C<LOCK_EX>; otherwise, they are #pod locked with C<LOCK_SH>. When using C<locked>, ">" or "+>" modes will delay #pod truncation until after the lock is acquired. #pod #pod The C<exclusive> option causes the open() call to fail if the file already #pod exists. This corresponds to the O_EXCL flag to sysopen / open(2). #pod C<exclusive> implies C<locked> and will set it for you if you forget it. #pod #pod See C<openr>, C<openw>, C<openrw>, and C<opena> for sugar. #pod #pod Current API available since 0.066. #pod #pod =cut # Note: must put binmode on open line, not subsequent binmode() call, so things # like ":unix" actually stop perlio/crlf from being added sub filehandle { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked exclusive/ ); $args->{locked} = 1 if $args->{exclusive}; my ( $opentype, $binmode ) = @args; $opentype = "<" unless defined $opentype; Carp::croak("Invalid file mode '$opentype'") unless grep { $opentype eq $_ } qw/< +< > +> >> +>>/; $binmode = ( ( caller(0) )[10] || {} )->{ 'open' . substr( $opentype, -1, 1 ) } unless defined $binmode; $binmode = "" unless defined $binmode; my ( $fh, $lock, $trunc ); if ( $HAS_FLOCK && $args->{locked} && !$ENV{PERL_PATH_TINY_NO_FLOCK} ) { require Fcntl; # truncating file modes shouldn't truncate until lock acquired if ( grep { $opentype eq $_ } qw( > +> ) ) { # sysopen in write mode without truncation my $flags = $opentype eq ">" ? Fcntl::O_WRONLY() : Fcntl::O_RDWR(); $flags |= Fcntl::O_CREAT(); $flags |= Fcntl::O_EXCL() if $args->{exclusive}; sysopen( $fh, $self->[PATH], $flags ) or $self->_throw("sysopen"); # fix up the binmode since sysopen() can't specify layers like # open() and binmode() can't start with just :unix like open() if ( $binmode =~ s/^:unix// ) { # eliminate pseudo-layers binmode( $fh, ":raw" ) or $self->_throw("binmode (:raw)"); # strip off real layers until only :unix is left while ( 1 < ( my $layers =()= PerlIO::get_layers( $fh, output => 1 ) ) ) { binmode( $fh, ":pop" ) or $self->_throw("binmode (:pop)"); } } # apply any remaining binmode layers if ( length $binmode ) { binmode( $fh, $binmode ) or $self->_throw("binmode ($binmode)"); } # ask for lock and truncation $lock = Fcntl::LOCK_EX(); $trunc = 1; } elsif ( $^O eq 'aix' && $opentype eq "<" ) { # AIX can only lock write handles, so upgrade to RW and LOCK_EX if # the file is writable; otherwise give up on locking. N.B. # checking -w before open to determine the open mode is an # unavoidable race condition if ( -w $self->[PATH] ) { $opentype = "+<"; $lock = Fcntl::LOCK_EX(); } } else { $lock = $opentype eq "<" ? Fcntl::LOCK_SH() : Fcntl::LOCK_EX(); } } unless ($fh) { my $mode = $opentype . $binmode; open $fh, $mode, $self->[PATH] or $self->_throw("open ($mode)"); } do { flock( $fh, $lock ) or $self->_throw("flock ($lock)") } if $lock; do { truncate( $fh, 0 ) or $self->_throw("truncate") } if $trunc; return $fh; } #pod =method has_same_bytes #pod #pod if ( path("foo.txt")->has_same_bytes("bar.txt") ) { #pod # ... #pod } #pod #pod This method returns true if both the invocant and the argument can be opened as #pod file handles and the handles contain the same bytes. It returns false if their #pod contents differ. If either can't be opened as a file (e.g. a directory or #pod non-existent file), the method throws an exception. If both can be opened and #pod both have the same C<realpath>, the method returns true without scanning any #pod data. #pod #pod Current API available since 0.125. #pod #pod =cut sub has_same_bytes { my ($self, $other_path) = @_; my $other = _path($other_path); my $fh1 = $self->openr_raw({ locked => 1 }); my $fh2 = $other->openr_raw({ locked => 1 }); # check for directories if (-d $fh1) { $self->_throw('has_same_bytes', $self->[PATH], "directory not allowed"); } if (-d $fh2) { $self->_throw('has_same_bytes', $other->[PATH], "directory not allowed"); } # Now that handles are open, we know the inputs are readable files that # exist, so it's safe to compare via realpath if ($self->realpath eq $other->realpath) { return 1 } # result is 0 for equal, 1 for unequal, -1 for error require File::Compare; my $res = File::Compare::compare($fh1, $fh2, 65536); if ($res < 0) { $self->_throw('has_same_bytes') } return $res == 0; } #pod =method is_absolute, is_relative #pod #pod if ( path("/tmp")->is_absolute ) { ... } #pod if ( path("/tmp")->is_relative ) { ... } #pod #pod Booleans for whether the path appears absolute or relative. #pod #pod Current API available since 0.001. #pod #pod =cut sub is_absolute { substr( $_[0]->dirname, 0, 1 ) eq '/' } sub is_relative { substr( $_[0]->dirname, 0, 1 ) ne '/' } #pod =method is_rootdir #pod #pod while ( ! $path->is_rootdir ) { #pod $path = $path->parent; #pod ... #pod } #pod #pod Boolean for whether the path is the root directory of the volume. I.e. the #pod C<dirname> is C<q[/]> and the C<basename> is C<q[]>. #pod #pod This works even on C<MSWin32> with drives and UNC volumes: #pod #pod path("C:/")->is_rootdir; # true #pod path("//server/share/")->is_rootdir; #true #pod #pod Current API available since 0.038. #pod #pod =cut sub is_rootdir { my ($self) = @_; $self->_splitpath unless defined $self->[DIR]; return $self->[DIR] eq '/' && $self->[FILE] eq ''; } #pod =method iterator #pod #pod $iter = path("/tmp")->iterator( \%options ); #pod #pod Returns a code reference that walks a directory lazily. Each invocation #pod returns a C<Path::Tiny> object or undef when the iterator is exhausted. #pod #pod $iter = path("/tmp")->iterator; #pod while ( $path = $iter->() ) { #pod ... #pod } #pod #pod The current and parent directory entries ("." and "..") will not #pod be included. #pod #pod If the C<recurse> option is true, the iterator will walk the directory #pod recursively, breadth-first. If the C<follow_symlinks> option is also true, #pod directory links will be followed recursively. There is no protection against #pod loops when following links. If a directory is not readable, it will not be #pod followed. #pod #pod The default is the same as: #pod #pod $iter = path("/tmp")->iterator( { #pod recurse => 0, #pod follow_symlinks => 0, #pod } ); #pod #pod For a more powerful, recursive iterator with built-in loop avoidance, see #pod L<Path::Iterator::Rule>. #pod #pod See also L</visit>. #pod #pod Current API available since 0.016. #pod #pod =cut sub iterator { my $self = shift; my $args = _get_args( shift, qw/recurse follow_symlinks/ ); my @dirs = $self; my $current; return sub { my $next; while (@dirs) { if ( ref $dirs[0] eq 'Path::Tiny' ) { if ( !-r $dirs[0] ) { # Directory is missing or not readable, so skip it. There # is still a race condition possible between the check and # the opendir, but we can't easily differentiate between # error cases that are OK to skip and those that we want # to be exceptions, so we live with the race and let opendir # be fatal. shift @dirs and next; } $current = $dirs[0]; my $dh; opendir( $dh, $current->[PATH] ) or $self->_throw( 'opendir', $current->[PATH] ); $dirs[0] = $dh; if ( -l $current->[PATH] && !$args->{follow_symlinks} ) { # Symlink attack! It was a real dir, but is now a symlink! # N.B. we check *after* opendir so the attacker has to win # two races: replace dir with symlink before opendir and # replace symlink with dir before -l check above shift @dirs and next; } } while ( defined( $next = readdir $dirs[0] ) ) { next if $next eq '.' || $next eq '..'; my $path = $current->child($next); push @dirs, $path if $args->{recurse} && -d $path && !( !$args->{follow_symlinks} && -l $path ); return $path; } shift @dirs; } return; }; } #pod =method lines, lines_raw, lines_utf8 #pod #pod @contents = path("/tmp/foo.txt")->lines; #pod @contents = path("/tmp/foo.txt")->lines(\%options); #pod @contents = path("/tmp/foo.txt")->lines_raw; #pod @contents = path("/tmp/foo.txt")->lines_utf8; #pod #pod @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); #pod #pod Returns a list of lines from a file. Optionally takes a hash-reference of #pod options. Valid options are C<binmode>, C<count> and C<chomp>. #pod #pod If C<binmode> is provided, it will be set on the handle prior to reading. #pod #pod If a positive C<count> is provided, that many lines will be returned from the #pod start of the file. If a negative C<count> is provided, the entire file will be #pod read, but only C<abs(count)> will be kept and returned. If C<abs(count)> #pod exceeds the number of lines in the file, all lines will be returned. #pod #pod If C<chomp> is set, any end-of-line character sequences (C<CR>, C<CRLF>, or #pod C<LF>) will be removed from the lines returned. #pod #pod Because the return is a list, C<lines> in scalar context will return the number #pod of lines (and throw away the data). #pod #pod $number_of_lines = path("/tmp/foo.txt")->lines; #pod #pod C<lines_raw> is like C<lines> with a C<binmode> of C<:raw>. We use C<:raw> #pod instead of C<:unix> so PerlIO buffering can manage reading by line. #pod #pod C<lines_utf8> is like C<lines> with a C<binmode> of C<:raw:encoding(UTF-8)> #pod (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> #pod 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the #pod lines will be split. This is actually faster than relying on #pod IO layers, though a bit memory intensive. If memory use is a #pod concern, consider C<openr_utf8> and iterating directly on the handle. #pod #pod Current API available since 0.065. #pod #pod =cut sub lines { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open<'} unless defined $binmode; my $fh = $self->filehandle( { locked => 1 }, "<", $binmode ); my $chomp = $args->{chomp}; # XXX more efficient to read @lines then chomp(@lines) vs map? if ( $args->{count} ) { my ( $counter, $mod, @result ) = ( 0, abs( $args->{count} ) ); my $line; while ( !eof($fh) ) { defined( $line = readline($fh) ) or $self->_throw('readline'); $line =~ s/(?:\x{0d}?\x{0a}|\x{0d})\z// if $chomp; $result[ $counter++ ] = $line; # for positive count, terminate after right number of lines last if $counter == $args->{count}; # for negative count, eventually wrap around in the result array $counter %= $mod; } # reorder results if full and wrapped somewhere in the middle splice( @result, 0, 0, splice( @result, $counter ) ) if @result == $mod && $counter % $mod; return @result; } elsif ($chomp) { local $!; my @lines = map { s/(?:\x{0d}?\x{0a}|\x{0d})\z//; $_ } <$fh>; ## no critic $self->_throw('readline') if $!; return @lines; } else { if ( wantarray ) { local $!; my @lines = <$fh>; $self->_throw('readline') if $!; return @lines; } else { local $!; my $count =()= <$fh>; $self->_throw('readline') if $!; return $count; } } } sub lines_raw { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); if ( $args->{chomp} && !$args->{count} ) { return split /\n/, slurp_raw($self); ## no critic } else { $args->{binmode} = ":raw"; return lines( $self, $args ); } } my $CRLF = qr/(?:\x{0d}?\x{0a}|\x{0d})/; sub lines_utf8 { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); if ( ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) && $args->{chomp} && !$args->{count} ) { my $slurp = slurp_utf8($self); $slurp =~ s/$CRLF\z//; # like chomp, but full CR?LF|CR return split $CRLF, $slurp, -1; ## no critic } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $args->{binmode} = ":raw:utf8_strict"; return lines( $self, $args ); } else { $args->{binmode} = ":raw:encoding(UTF-8)"; return lines( $self, $args ); } } #pod =method mkdir #pod #pod path("foo/bar/baz")->mkdir; #pod path("foo/bar/baz")->mkdir( \%options ); #pod #pod Like calling C<make_path> from L<File::Path>. An optional hash reference #pod is passed through to C<make_path>. Errors will be trapped and an exception #pod thrown. Returns the the path object to facilitate chaining. #pod #pod B<NOTE>: unlike Perl's builtin C<mkdir>, this will create intermediate paths #pod similar to the Unix C<mkdir -p> command. It will not error if applied to an #pod existing directory. #pod #pod Current API available since 0.125. #pod #pod =cut sub mkdir { my ( $self, $args ) = @_; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; require File::Path; my @dirs; my $ok = eval { File::Path::make_path( $self->[PATH], $args ); 1; }; if (!$ok) { $self->_throw('mkdir', $self->[PATH], "error creating path: $@"); } if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; $self->_throw('mkdir', $file, $message); } return $self; } #pod =method mkpath (deprecated) #pod #pod Like calling C<mkdir>, but returns the list of directories created or an empty list if #pod the directories already exist, just like C<make_path>. #pod #pod Deprecated in 0.125. #pod #pod =cut sub mkpath { my ( $self, $args ) = @_; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; require File::Path; my @dirs = File::Path::make_path( $self->[PATH], $args ); if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; Carp::croak("mkpath failed for $file: $message"); } return @dirs; } #pod =method move #pod #pod path("foo.txt")->move("bar.txt"); #pod #pod Moves the current path to the given destination using L<File::Copy>'s #pod C<move> function. Upon success, returns the C<Path::Tiny> object for the #pod newly moved file. #pod #pod If the destination already exists and is a directory, and the source is not a #pod directory, then the source file will be renamed into the directory #pod specified by the destination. #pod #pod If possible, move() will simply rename the file. Otherwise, it #pod copies the file to the new location and deletes the original. If an #pod error occurs during this copy-and-delete process, you may be left #pod with a (possibly partial) copy of the file under the destination #pod name. #pod #pod Current API available since 0.124. Prior versions used Perl's #pod -built-in (and less robust) L<rename|perlfunc/rename> function #pod and did not return an object. #pod #pod =cut sub move { my ( $self, $dest ) = @_; require File::Copy; File::Copy::move( $self->[PATH], $dest ) or $self->_throw( 'move', $self->[PATH] . "' -> '$dest" ); return -d $dest ? _path( $dest, $self->basename ) : _path($dest); } #pod =method openr, openw, openrw, opena #pod #pod $fh = path("foo.txt")->openr($binmode); # read #pod $fh = path("foo.txt")->openr_raw; #pod $fh = path("foo.txt")->openr_utf8; #pod #pod $fh = path("foo.txt")->openw($binmode); # write #pod $fh = path("foo.txt")->openw_raw; #pod $fh = path("foo.txt")->openw_utf8; #pod #pod $fh = path("foo.txt")->opena($binmode); # append #pod $fh = path("foo.txt")->opena_raw; #pod $fh = path("foo.txt")->opena_utf8; #pod #pod $fh = path("foo.txt")->openrw($binmode); # read/write #pod $fh = path("foo.txt")->openrw_raw; #pod $fh = path("foo.txt")->openrw_utf8; #pod #pod Returns a file handle opened in the specified mode. The C<openr> style methods #pod take a single C<binmode> argument. All of the C<open*> methods have #pod C<open*_raw> and C<open*_utf8> equivalents that use buffered I/O layers C<:raw> #pod and C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with #pod L<PerlIO::utf8_strict>). #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<locked>. If true, handles opened for writing, appending or read-write are #pod locked with C<LOCK_EX>; otherwise, they are locked for C<LOCK_SH>. #pod #pod $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); #pod #pod See L</filehandle> for more on locking. #pod #pod Current API available since 0.011. #pod #pod =cut # map method names to corresponding open mode my %opens = ( opena => ">>", openr => "<", openw => ">", openrw => "+<" ); while ( my ( $k, $v ) = each %opens ) { no strict 'refs'; # must check for lexical IO mode hint *{$k} = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); my ($binmode) = @args; $binmode = ( ( caller(0) )[10] || {} )->{ 'open' . substr( $v, -1, 1 ) } unless defined $binmode; $self->filehandle( $args, $v, $binmode ); }; *{ $k . "_raw" } = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); $self->filehandle( $args, $v, ":raw" ); }; *{ $k . "_utf8" } = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); my $layer; if ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $layer = ":raw:utf8_strict"; } else { $layer = ":raw:encoding(UTF-8)"; } $self->filehandle( $args, $v, $layer ); }; } #pod =method parent #pod #pod $parent = path("foo/bar/baz")->parent; # foo/bar #pod $parent = path("foo/wibble.txt")->parent; # foo #pod #pod $parent = path("foo/bar/baz")->parent(2); # foo #pod #pod Returns a C<Path::Tiny> object corresponding to the parent directory of the #pod original directory or file. An optional positive integer argument is the number #pod of parent directories upwards to return. C<parent> by itself is equivalent to #pod C<parent(1)>. #pod #pod Current API available since 0.014. #pod #pod =cut # XXX this is ugly and coverage is incomplete. I think it's there for windows # so need to check coverage there and compare sub parent { my ( $self, $level ) = @_; $level = 1 unless defined $level && $level > 0; $self->_splitpath unless defined $self->[FILE]; my $parent; if ( length $self->[FILE] ) { if ( $self->[FILE] eq '.' || $self->[FILE] eq ".." ) { $parent = _path( $self->[PATH] . "/.." ); } else { $parent = _path( _non_empty( $self->[VOL] . $self->[DIR] ) ); } } elsif ( length $self->[DIR] ) { # because of symlinks, any internal updir requires us to # just add more updirs at the end if ( $self->[DIR] =~ m{(?:^\.\./|/\.\./|/\.\.\z)} ) { $parent = _path( $self->[VOL] . $self->[DIR] . "/.." ); } else { ( my $dir = $self->[DIR] ) =~ s{/[^\/]+/\z}{/}; $parent = _path( $self->[VOL] . $dir ); } } else { $parent = _path( _non_empty( $self->[VOL] ) ); } return $level == 1 ? $parent : $parent->parent( $level - 1 ); } sub _non_empty { my ($string) = shift; return ( ( defined($string) && length($string) ) ? $string : "." ); } #pod =method realpath #pod #pod $real = path("/baz/foo/../bar")->realpath; #pod $real = path("foo/../bar")->realpath; #pod #pod Returns a new C<Path::Tiny> object with all symbolic links and upward directory #pod parts resolved using L<Cwd>'s C<realpath>. Compared to C<absolute>, this is #pod more expensive as it must actually consult the filesystem. #pod #pod If the parent path can't be resolved (e.g. if it includes directories that #pod don't exist), an exception will be thrown: #pod #pod $real = path("doesnt_exist/foo")->realpath; # dies #pod #pod However, if the parent path exists and only the last component (e.g. filename) #pod doesn't exist, the realpath will be the realpath of the parent plus the #pod non-existent last component: #pod #pod $real = path("./aasdlfasdlf")->realpath; # works #pod #pod The underlying L<Cwd> module usually worked this way on Unix, but died on #pod Windows (and some Unixes) if the full path didn't exist. As of version 0.064, #pod it's safe to use anywhere. #pod #pod Current API available since 0.001. #pod #pod =cut # Win32 and some Unixes need parent path resolved separately so realpath # doesn't throw an error resolving non-existent basename sub realpath { my $self = shift; $self = $self->_resolve_symlinks; require Cwd; $self->_splitpath if !defined $self->[FILE]; my $check_parent = length $self->[FILE] && $self->[FILE] ne '.' && $self->[FILE] ne '..'; my $realpath = eval { # pure-perl Cwd can carp local $SIG{__WARN__} = sub { }; Cwd::realpath( $check_parent ? $self->parent->[PATH] : $self->[PATH] ); }; # parent realpath must exist; not all Cwd::realpath will error if it doesn't $self->_throw("resolving realpath") unless defined $realpath && length $realpath && -e $realpath; return ( $check_parent ? _path( $realpath, $self->[FILE] ) : _path($realpath) ); } #pod =method relative #pod #pod $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar #pod #pod Returns a C<Path::Tiny> object with a path relative to a new base path #pod given as an argument. If no argument is given, the current directory will #pod be used as the new base path. #pod #pod If either path is already relative, it will be made absolute based on the #pod current directly before determining the new relative path. #pod #pod The algorithm is roughly as follows: #pod #pod =for :list #pod * If the original and new base path are on different volumes, an exception #pod will be thrown. #pod * If the original and new base are identical, the relative path is C<".">. #pod * If the new base subsumes the original, the relative path is the original #pod path with the new base chopped off the front #pod * If the new base does not subsume the original, a common prefix path is #pod determined (possibly the root directory) and the relative path will #pod consist of updirs (C<"..">) to reach the common prefix, followed by the #pod original path less the common prefix. #pod #pod Unlike C<File::Spec::abs2rel>, in the last case above, the calculation based #pod on a common prefix takes into account symlinks that could affect the updir #pod process. Given an original path "/A/B" and a new base "/A/C", #pod (where "A", "B" and "C" could each have multiple path components): #pod #pod =for :list #pod * Symlinks in "A" don't change the result unless the last component of A is #pod a symlink and the first component of "C" is an updir. #pod * Symlinks in "B" don't change the result and will exist in the result as #pod given. #pod * Symlinks and updirs in "C" must be resolved to actual paths, taking into #pod account the possibility that not all path components might exist on the #pod filesystem. #pod #pod Current API available since 0.001. New algorithm (that accounts for #pod symlinks) available since 0.079. #pod #pod =cut sub relative { my ( $self, $base ) = @_; $base = _path( defined $base && length $base ? $base : '.' ); # relative paths must be converted to absolute first $self = $self->absolute if $self->is_relative; $base = $base->absolute if $base->is_relative; # normalize volumes if they exist $self = $self->absolute if !length $self->volume && length $base->volume; $base = $base->absolute if length $self->volume && !length $base->volume; # can't make paths relative across volumes if ( !_same( $self->volume, $base->volume ) ) { Carp::croak("relative() can't cross volumes: '$self' vs '$base'"); } # if same absolute path, relative is current directory return _path(".") if _same( $self->[PATH], $base->[PATH] ); # if base is a prefix of self, chop prefix off self if ( $base->subsumes($self) ) { $base = "" if $base->is_rootdir; my $relative = "$self"; $relative =~ s{\A\Q$base/}{}; return _path(".", $relative); } # base is not a prefix, so must find a common prefix (even if root) my ( @common, @self_parts, @base_parts ); @base_parts = split /\//, $base->_just_filepath; # if self is rootdir, then common directory is root (shown as empty # string for later joins); otherwise, must be computed from path parts. if ( $self->is_rootdir ) { @common = (""); shift @base_parts; } else { @self_parts = split /\//, $self->_just_filepath; while ( @self_parts && @base_parts && _same( $self_parts[0], $base_parts[0] ) ) { push @common, shift @base_parts; shift @self_parts; } } # if there are any symlinks from common to base, we have a problem, as # you can't guarantee that updir from base reaches the common prefix; # we must resolve symlinks and try again; likewise, any updirs are # a problem as it throws off calculation of updirs needed to get from # self's path to the common prefix. if ( my $new_base = $self->_resolve_between( \@common, \@base_parts ) ) { return $self->relative($new_base); } # otherwise, symlinks in common or from common to A don't matter as # those don't involve updirs my @new_path = ( ("..") x ( 0+ @base_parts ), @self_parts ); return _path(@new_path); } sub _just_filepath { my $self = shift; my $self_vol = $self->volume; return "$self" if !length $self_vol; ( my $self_path = "$self" ) =~ s{\A\Q$self_vol}{}; return $self_path; } sub _resolve_between { my ( $self, $common, $base ) = @_; my $path = $self->volume . join( "/", @$common ); my $changed = 0; for my $p (@$base) { $path .= "/$p"; if ( $p eq '..' ) { $changed = 1; if ( -e $path ) { $path = _path($path)->realpath->[PATH]; } else { $path =~ s{/[^/]+/..\z}{/}; } } if ( -l $path ) { $changed = 1; $path = _path($path)->realpath->[PATH]; } } return $changed ? _path($path) : undef; } #pod =method remove #pod #pod path("foo.txt")->remove; #pod #pod This is just like C<unlink>, except for its error handling: if the path does #pod not exist, it returns false; if deleting the file fails, it throws an #pod exception. #pod #pod Current API available since 0.012. #pod #pod =cut sub remove { my $self = shift; return 0 if !-e $self->[PATH] && !-l $self->[PATH]; return unlink( $self->[PATH] ) || $self->_throw('unlink'); } #pod =method remove_tree #pod #pod # directory #pod path("foo/bar/baz")->remove_tree; #pod path("foo/bar/baz")->remove_tree( \%options ); #pod path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove #pod #pod Like calling C<remove_tree> from L<File::Path>, but defaults to C<safe> mode. #pod An optional hash reference is passed through to C<remove_tree>. Errors will be #pod trapped and an exception thrown. Returns the number of directories deleted, #pod just like C<remove_tree>. #pod #pod If you want to remove a directory only if it is empty, use the built-in #pod C<rmdir> function instead. #pod #pod rmdir path("foo/bar/baz/"); #pod #pod Current API available since 0.013. #pod #pod =cut sub remove_tree { my ( $self, $args ) = @_; return 0 if !-e $self->[PATH] && !-l $self->[PATH]; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; $args->{safe} = 1 unless defined $args->{safe}; require File::Path; my $count = File::Path::remove_tree( $self->[PATH], $args ); if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; Carp::croak("remove_tree failed for $file: $message"); } return $count; } #pod =method sibling #pod #pod $foo = path("/tmp/foo.txt"); #pod $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt #pod $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt #pod #pod Returns a new C<Path::Tiny> object relative to the parent of the original. #pod This is slightly more efficient than C<< $path->parent->child(...) >>. #pod #pod Current API available since 0.058. #pod #pod =cut sub sibling { my $self = shift; return _path( $self->parent->[PATH], @_ ); } #pod =method size, size_human #pod #pod my $p = path("foo"); # with size 1025 bytes #pod #pod $p->size; # "1025" #pod $p->size_human; # "1.1 K" #pod $p->size_human( {format => "iec"} ); # "1.1 KiB" #pod #pod Returns the size of a file. The C<size> method is just a wrapper around C<-s>. #pod #pod The C<size_human> method provides a human-readable string similar to #pod C<ls -lh>. Like C<ls>, it rounds upwards and provides one decimal place for #pod single-digit sizes and no decimal places for larger sizes. The only available #pod option is C<format>, which has three valid values: #pod #pod =for :list #pod * 'ls' (the default): base-2 sizes, with C<ls> style single-letter suffixes (K, M, etc.) #pod * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) #pod * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) #pod #pod If C<-s> would return C<undef>, C<size_human> returns the empty string. #pod #pod Current API available since 0.122. #pod #pod =cut sub size { -s $_[0]->[PATH] } my %formats = ( 'ls' => [ 1024, log(1024), [ "", map { " $_" } qw/K M G T/ ] ], 'iec' => [ 1024, log(1024), [ "", map { " $_" } qw/KiB MiB GiB TiB/ ] ], 'si' => [ 1000, log(1000), [ "", map { " $_" } qw/kB MB GB TB/ ] ], ); sub _formats { return $formats{$_[0]} } sub size_human { my $self = shift; my $args = _get_args( shift, qw/format/ ); my $format = defined $args->{format} ? $args->{format} : "ls"; my $fmt_opts = $formats{$format} or Carp::croak("Invalid format '$format' for size_human()"); my $size = -s $self->[PATH]; return defined $size ? _human_size( $size, @$fmt_opts ) : ""; } sub _ceil { return $_[0] == int($_[0]) ? $_[0] : int($_[0]+1); } sub _human_size { my ( $size, $base, $log_base, $suffixes ) = @_; return "0" if $size == 0; my $mag = int( log($size) / $log_base ); $size /= $base**$mag; $size = $mag == 0 ? $size : length( int($size) ) == 1 ? _ceil( $size * 10 ) / 10 : _ceil($size); if ( $size >= $base ) { $size /= $base; $mag++; } my $fmt = ( $mag == 0 || length( int($size) ) > 1 ) ? "%.0f%s" : "%.1f%s"; return sprintf( $fmt, $size, $suffixes->[$mag] ); } #pod =method slurp, slurp_raw, slurp_utf8 #pod #pod $data = path("foo.txt")->slurp; #pod $data = path("foo.txt")->slurp( {binmode => ":raw"} ); #pod $data = path("foo.txt")->slurp_raw; #pod $data = path("foo.txt")->slurp_utf8; #pod #pod Reads file contents into a scalar. Takes an optional hash reference which may #pod be used to pass options. The only available option is C<binmode>, which is #pod passed to C<binmode()> on the handle used for reading. #pod #pod C<slurp_raw> is like C<slurp> with a C<binmode> of C<:unix> for #pod a fast, unbuffered, raw read. #pod #pod C<slurp_utf8> is like C<slurp> with a C<binmode> of #pod C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with #pod L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a #pod unbuffered, raw slurp will be done instead and the result decoded with #pod C<Unicode::UTF8>. This is just as strict and is roughly an order of #pod magnitude faster than using C<:encoding(UTF-8)>. #pod #pod B<Note>: C<slurp> and friends lock the filehandle before slurping. If #pod you plan to slurp from a file created with L<File::Temp>, be sure to #pod close other handles or open without locking to avoid a deadlock: #pod #pod my $tempfile = File::Temp->new(EXLOCK => 0); #pod my $guts = path($tempfile)->slurp; #pod #pod Current API available since 0.004. #pod #pod =cut sub slurp { my $self = shift; my $args = _get_args( shift, qw/binmode/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open<'} unless defined $binmode; my $fh = $self->filehandle( { locked => 1 }, "<", $binmode ); if ( ( defined($binmode) ? $binmode : "" ) eq ":unix" and my $size = -s $fh ) { my $buf; my $rc = read $fh, $buf, $size; # File::Slurp in a nutshell $self->_throw('read') unless defined $rc; return $buf; } else { local $/; my $buf = scalar <$fh>; $self->_throw('read') unless defined $buf; return $buf; } } sub slurp_raw { $_[1] = { binmode => ":unix" }; goto &slurp } sub slurp_utf8 { if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { return Unicode::UTF8::decode_utf8( slurp( $_[0], { binmode => ":unix" } ) ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $_[1] = { binmode => ":unix:utf8_strict" }; goto &slurp; } else { $_[1] = { binmode => ":unix:encoding(UTF-8)" }; goto &slurp; } } #pod =method spew, spew_raw, spew_utf8 #pod #pod path("foo.txt")->spew(@data); #pod path("foo.txt")->spew(\@data); #pod path("foo.txt")->spew({binmode => ":raw"}, @data); #pod path("foo.txt")->spew_raw(@data); #pod path("foo.txt")->spew_utf8(@data); #pod #pod Writes data to a file atomically. The file is written to a temporary file in #pod the same directory, then renamed over the original. An optional hash reference #pod may be used to pass options. The only option is C<binmode>, which is passed to #pod C<binmode()> on the handle used for writing. #pod #pod C<spew_raw> is like C<spew> with a C<binmode> of C<:unix> for a fast, #pod unbuffered, raw write. #pod #pod C<spew_utf8> is like C<spew> with a C<binmode> of C<:unix:encoding(UTF-8)> #pod (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> #pod 0.58+ is installed, a raw, unbuffered spew will be done instead on the data #pod encoded with C<Unicode::UTF8>. #pod #pod B<NOTE>: because the file is written to a temporary file and then renamed, the #pod new file will wind up with permissions based on your current umask. This is a #pod feature to protect you from a race condition that would otherwise give #pod different permissions than you might expect. If you really want to keep the #pod original mode flags, use L</append> with the C<truncate> option. #pod #pod Current API available since 0.011. #pod #pod =cut sub spew { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode/ ); my $binmode = $args->{binmode}; # get default binmode from caller's lexical scope (see "perldoc open") $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; # writing needs to follow the link and create the tempfile in the same # dir for later atomic rename my $resolved_path = $self->_resolve_symlinks; my $temp = $resolved_path->_replacment_path; my $fh; my $ok = eval { $fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode ); 1 }; if (!$ok) { my $msg = ref($@) eq 'Path::Tiny::Error' ? "error opening temp file '$@->{file}' for atomic write: $@->{err}" : "error opening temp file for atomic write: $@"; $self->_throw('spew', $self->[PATH], $msg); } print( {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data) or self->_throw('print', $temp->[PATH]); close $fh or $self->_throw( 'close', $temp->[PATH] ); return $temp->move($resolved_path); } sub spew_raw { splice @_, 1, 0, { binmode => ":unix" }; goto &spew } sub spew_utf8 { if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { my $self = shift; spew( $self, { binmode => ":unix" }, map { Unicode::UTF8::encode_utf8($_) } map { ref eq 'ARRAY' ? @$_ : $_ } @_ ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { splice @_, 1, 0, { binmode => ":unix:utf8_strict" }; goto &spew; } else { splice @_, 1, 0, { binmode => ":unix:encoding(UTF-8)" }; goto &spew; } } #pod =method stat, lstat #pod #pod $stat = path("foo.txt")->stat; #pod $stat = path("/some/symlink")->lstat; #pod #pod Like calling C<stat> or C<lstat> from L<File::stat>. #pod #pod Current API available since 0.001. #pod #pod =cut # XXX break out individual stat() components as subs? sub stat { my $self = shift; require File::stat; return File::stat::stat( $self->[PATH] ) || $self->_throw('stat'); } sub lstat { my $self = shift; require File::stat; return File::stat::lstat( $self->[PATH] ) || $self->_throw('lstat'); } #pod =method stringify #pod #pod $path = path("foo.txt"); #pod say $path->stringify; # same as "$path" #pod #pod Returns a string representation of the path. Unlike C<canonpath>, this method #pod returns the path standardized with Unix-style C</> directory separators. #pod #pod Current API available since 0.001. #pod #pod =cut sub stringify { $_[0]->[PATH] =~ /^~/ ? './' . $_[0]->[PATH] : $_[0]->[PATH] } #pod =method subsumes #pod #pod path("foo/bar")->subsumes("foo/bar/baz"); # true #pod path("/foo/bar")->subsumes("/foo/baz"); # false #pod #pod Returns true if the first path is a prefix of the second path at a directory #pod boundary. #pod #pod This B<does not> resolve parent directory entries (C<..>) or symlinks: #pod #pod path("foo/bar")->subsumes("foo/bar/../baz"); # true #pod #pod If such things are important to you, ensure that both paths are resolved to #pod the filesystem with C<realpath>: #pod #pod my $p1 = path("foo/bar")->realpath; #pod my $p2 = path("foo/bar/../baz")->realpath; #pod if ( $p1->subsumes($p2) ) { ... } #pod #pod Current API available since 0.048. #pod #pod =cut sub subsumes { my $self = shift; Carp::croak("subsumes() requires a defined, positive-length argument") unless defined $_[0]; my $other = _path(shift); # normalize absolute vs relative if ( $self->is_absolute && !$other->is_absolute ) { $other = $other->absolute; } elsif ( $other->is_absolute && !$self->is_absolute ) { $self = $self->absolute; } # normalize volume vs non-volume; do this after absolute path # adjustments above since that might add volumes already if ( length $self->volume && !length $other->volume ) { $other = $other->absolute; } elsif ( length $other->volume && !length $self->volume ) { $self = $self->absolute; } if ( $self->[PATH] eq '.' ) { return !!1; # cwd subsumes everything relative } elsif ( $self->is_rootdir ) { # a root directory ("/", "c:/") already ends with a separator return $other->[PATH] =~ m{^\Q$self->[PATH]\E}; } else { # exact match or prefix breaking at a separator return $other->[PATH] =~ m{^\Q$self->[PATH]\E(?:/|\z)}; } } #pod =method touch #pod #pod path("foo.txt")->touch; #pod path("foo.txt")->touch($epoch_secs); #pod #pod Like the Unix C<touch> utility. Creates the file if it doesn't exist, or else #pod changes the modification and access times to the current time. If the first #pod argument is the epoch seconds then it will be used. #pod #pod Returns the path object so it can be easily chained with other methods: #pod #pod # won't die if foo.txt doesn't exist #pod $content = path("foo.txt")->touch->slurp; #pod #pod Current API available since 0.015. #pod #pod =cut sub touch { my ( $self, $epoch ) = @_; if ( !-e $self->[PATH] ) { my $fh = $self->openw; close $fh or $self->_throw('close'); } if ( defined $epoch ) { utime $epoch, $epoch, $self->[PATH] or $self->_throw("utime ($epoch)"); } else { # literal undef prevents warnings :-( utime undef, undef, $self->[PATH] or $self->_throw("utime ()"); } return $self; } #pod =method touchpath #pod #pod path("bar/baz/foo.txt")->touchpath; #pod #pod Combines C<mkdir> and C<touch>. Creates the parent directory if it doesn't exist, #pod before touching the file. Returns the path object like C<touch> does. #pod #pod If you need to pass options, use C<mkdir> and C<touch> separately: #pod #pod path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); #pod #pod Current API available since 0.022. #pod #pod =cut sub touchpath { my ($self) = @_; my $parent = $self->parent; $parent->mkdir unless $parent->exists; $self->touch; } #pod =method visit #pod #pod path("/tmp")->visit( \&callback, \%options ); #pod #pod Executes a callback for each child of a directory. It returns a hash #pod reference with any state accumulated during iteration. #pod #pod The options are the same as for L</iterator> (which it uses internally): #pod C<recurse> and C<follow_symlinks>. Both default to false. #pod #pod The callback function will receive a C<Path::Tiny> object as the first argument #pod and a hash reference to accumulate state as the second argument. For example: #pod #pod # collect files sizes #pod my $sizes = path("/tmp")->visit( #pod sub { #pod my ($path, $state) = @_; #pod return if $path->is_dir; #pod $state->{$path} = -s $path; #pod }, #pod { recurse => 1 } #pod ); #pod #pod For convenience, the C<Path::Tiny> object will also be locally aliased as the #pod C<$_> global variable: #pod #pod # print paths matching /foo/ #pod path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); #pod #pod If the callback returns a B<reference> to a false scalar value, iteration will #pod terminate. This is not the same as "pruning" a directory search; this just #pod stops all iteration and returns the state hash reference. #pod #pod # find up to 10 files larger than 100K #pod my $files = path("/tmp")->visit( #pod sub { #pod my ($path, $state) = @_; #pod $state->{$path}++ if -s $path > 102400 #pod return \0 if keys %$state == 10; #pod }, #pod { recurse => 1 } #pod ); #pod #pod If you want more flexible iteration, use a module like L<Path::Iterator::Rule>. #pod #pod Current API available since 0.062. #pod #pod =cut sub visit { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/recurse follow_symlinks/ ); Carp::croak("Callback for visit() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; my $next = $self->iterator($args); my $state = {}; while ( my $file = $next->() ) { local $_ = $file; my $r = $cb->( $file, $state ); last if ref($r) eq 'SCALAR' && !$$r; } return $state; } #pod =method volume #pod #pod $vol = path("/tmp/foo.txt")->volume; # "" #pod $vol = path("C:/tmp/foo.txt")->volume; # "C:" #pod #pod Returns the volume portion of the path. This is equivalent #pod to what L<File::Spec> would give from C<splitpath> and thus #pod usually is the empty string on Unix-like operating systems or the #pod drive letter for an absolute path on C<MSWin32>. #pod #pod Current API available since 0.001. #pod #pod =cut sub volume { my ($self) = @_; $self->_splitpath unless defined $self->[VOL]; return $self->[VOL]; } package Path::Tiny::Error; our @CARP_NOT = qw/Path::Tiny/; use overload ( q{""} => sub { (shift)->{msg} }, fallback => 1 ); sub throw { my ( $class, $op, $file, $err ) = @_; chomp( my $trace = Carp::shortmess ); my $msg = "Error $op on '$file': $err$trace\n"; die bless { op => $op, file => $file, err => $err, msg => $msg }, $class; } 1; # vim: ts=4 sts=4 sw=4 et: __END__ =pod =encoding UTF-8 =head1 NAME Path::Tiny - File path utility =head1 VERSION version 0.146 =head1 SYNOPSIS use Path::Tiny; # Creating Path::Tiny objects my $dir = path("/tmp"); my $foo = path("foo.txt"); my $subdir = $dir->child("foo"); my $bar = $subdir->child("bar.txt"); # Stringifies as cleaned up path my $file = path("./foo.txt"); print $file; # "foo.txt" # Reading files my $guts = $file->slurp; $guts = $file->slurp_utf8; my @lines = $file->lines; @lines = $file->lines_utf8; my ($head) = $file->lines( {count => 1} ); my ($tail) = $file->lines( {count => -1} ); # Writing files $bar->spew( @data ); $bar->spew_utf8( @data ); # Reading directories for ( $dir->children ) { ... } my $iter = $dir->iterator; while ( my $next = $iter->() ) { ... } =head1 DESCRIPTION This module provides a small, fast utility for working with file paths. It is friendlier to use than L<File::Spec> and provides easy access to functions from several other core file handling modules. It aims to be smaller and faster than many alternatives on CPAN, while helping people do many common things in consistent and less error-prone ways. Path::Tiny does not try to work for anything except Unix-like and Win32 platforms. Even then, it might break if you try something particularly obscure or tortuous. (Quick! What does this mean: C<< ///../../..//./././a//b/.././c/././ >>? And how does it differ on Win32?) All paths are forced to have Unix-style forward slashes. Stringifying the object gives you back the path (after some clean up). File input/output methods C<flock> handles before reading or writing, as appropriate (if supported by the platform and/or filesystem). The C<*_utf8> methods (C<slurp_utf8>, C<lines_utf8>, etc.) operate in raw mode. On Windows, that means they will not have CRLF translation from the C<:crlf> IO layer. Installing L<Unicode::UTF8> 0.58 or later will speed up C<*_utf8> situations in many cases and is highly recommended. Alternatively, installing L<PerlIO::utf8_strict> 0.003 or later will be used in place of the default C<:encoding(UTF-8)>. This module depends heavily on PerlIO layers for correct operation and thus requires Perl 5.008001 or later. =head1 CONSTRUCTORS =head2 path $path = path("foo/bar"); $path = path("/tmp", "file.txt"); # list $path = path("."); # cwd Constructs a C<Path::Tiny> object. It doesn't matter if you give a file or directory path. It's still up to you to call directory-like methods only on directories and file-like methods only on files. This function is exported automatically by default. The first argument must be defined and have non-zero length or an exception will be thrown. This prevents subtle, dangerous errors with code like C<< path( maybe_undef() )->remove_tree >>. B<DEPRECATED>: If and only if the B<first> character of the B<first> argument to C<path> is a tilde ('~'), then tilde replacement will be applied to the first path segment. A single tilde will be replaced with C<glob('~')> and a tilde followed by a username will be replaced with output of C<glob('~username')>. B<No other method does tilde expansion on its arguments>. See L</Tilde expansion (deprecated)> for more. On Windows, if the path consists of a drive identifier without a path component (C<C:> or C<D:>), it will be expanded to the absolute path of the current directory on that volume using C<Cwd::getdcwd()>. If called with a single C<Path::Tiny> argument, the original is returned unless the original is holding a temporary file or directory reference in which case a stringified copy is made. $path = path("foo/bar"); $temp = Path::Tiny->tempfile; $p2 = path($path); # like $p2 = $path $t2 = path($temp); # like $t2 = path( "$temp" ) This optimizes copies without proliferating references unexpectedly if a copy is made by code outside your control. Current API available since 0.017. =head2 new $path = Path::Tiny->new("foo/bar"); This is just like C<path>, but with method call overhead. (Why would you do that?) Current API available since 0.001. =head2 cwd $path = Path::Tiny->cwd; # path( Cwd::getcwd ) $path = cwd; # optional export Gives you the absolute path to the current directory as a C<Path::Tiny> object. This is slightly faster than C<< path(".")->absolute >>. C<cwd> may be exported on request and used as a function instead of as a method. Current API available since 0.018. =head2 rootdir $path = Path::Tiny->rootdir; # / $path = rootdir; # optional export Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if you're too picky for C<path("/")>. C<rootdir> may be exported on request and used as a function instead of as a method. Current API available since 0.018. =head2 tempfile, tempdir $temp = Path::Tiny->tempfile( @options ); $temp = Path::Tiny->tempdir( @options ); $temp = $dirpath->tempfile( @options ); $temp = $dirpath->tempdir( @options ); $temp = tempfile( @options ); # optional export $temp = tempdir( @options ); # optional export C<tempfile> passes the options to C<< File::Temp->new >> and returns a C<Path::Tiny> object with the file name. The C<TMPDIR> option will be enabled by default, but you can override that by passing C<< TMPDIR => 0 >> along with the options. (If you use an absolute C<TEMPLATE> option, you will want to disable C<TMPDIR>.) The resulting C<File::Temp> object is cached. When the C<Path::Tiny> object is destroyed, the C<File::Temp> object will be as well. C<File::Temp> annoyingly requires you to specify a custom template in slightly different ways depending on which function or method you call, but C<Path::Tiny> lets you ignore that and can take either a leading template or a C<TEMPLATE> option and does the right thing. $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok The tempfile path object will be normalized to have an absolute path, even if created in a relative directory using C<DIR>. If you want it to have the C<realpath> instead, pass a leading options hash like this: $real_temp = tempfile({realpath => 1}, @options); C<tempdir> is just like C<tempfile>, except it calls C<< File::Temp->newdir >> instead. Both C<tempfile> and C<tempdir> may be exported on request and used as functions instead of as methods. The methods can be called on an instances representing a directory. In this case, the directory is used as the base to create the temporary file/directory, setting the C<DIR> option in File::Temp. my $target_dir = path('/to/destination'); my $tempfile = $target_dir->tempfile('foobarXXXXXX'); $tempfile->spew('A lot of data...'); # not atomic $tempfile->move($target_dir->child('foobar')); # hopefully atomic In this case, any value set for option C<DIR> is ignored. B<Note>: for tempfiles, the filehandles from File::Temp are closed and not reused. This is not as secure as using File::Temp handles directly, but is less prone to deadlocks or access problems on some platforms. Think of what C<Path::Tiny> gives you to be just a temporary file B<name> that gets cleaned up. B<Note 2>: if you don't want these cleaned up automatically when the object is destroyed, File::Temp requires different options for directories and files. Use C<< CLEANUP => 0 >> for directories and C<< UNLINK => 0 >> for files. B<Note 3>: Don't lose the temporary object by chaining a method call instead of storing it: my $lost = tempdir()->child("foo"); # tempdir cleaned up right away B<Note 4>: The cached object may be accessed with the L</cached_temp> method. Keeping a reference to, or modifying the cached object may break the behavior documented above and is not supported. Use at your own risk. Current API available since 0.119. =head1 METHODS =head2 absolute $abs = path("foo/bar")->absolute; $abs = path("foo/bar")->absolute("/tmp"); Returns a new C<Path::Tiny> object with an absolute path (or itself if already absolute). If no argument is given, the current directory is used as the absolute base path. If an argument is given, it will be converted to an absolute path (if it is not already) and used as the absolute base path. This will not resolve upward directories ("foo/../bar") unless C<canonpath> in L<File::Spec> would normally do so on your platform. If you need them resolved, you must call the more expensive C<realpath> method instead. On Windows, an absolute path without a volume component will have it added based on the current drive. Current API available since 0.101. =head2 append, append_raw, append_utf8 path("foo.txt")->append(@data); path("foo.txt")->append(\@data); path("foo.txt")->append({binmode => ":raw"}, @data); path("foo.txt")->append_raw(@data); path("foo.txt")->append_utf8(@data); Appends data to a file. The file is locked with C<flock> prior to writing and closed afterwards. An optional hash reference may be used to pass options. Valid options are: =over 4 =item * C<binmode>: passed to C<binmode()> on the handle used for writing. =item * C<truncate>: truncates the file after locking and before appending =back The C<truncate> option is a way to replace the contents of a file B<in place>, unlike L</spew> which writes to a temporary file and then replaces the original (if it exists). C<append_raw> is like C<append> with a C<binmode> of C<:unix> for a fast, unbuffered, raw write. C<append_utf8> is like C<append> with an unbuffered C<binmode> C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, an unbuffered, raw append will be done instead on the data encoded with C<Unicode::UTF8>. Current API available since 0.060. =head2 assert $path = path("foo.txt")->assert( sub { $_->exists } ); Returns the invocant after asserting that a code reference argument returns true. When the assertion code reference runs, it will have the invocant object in the C<$_> variable. If it returns false, an exception will be thrown. The assertion code reference may also throw its own exception. If no assertion is provided, the invocant is returned without error. Current API available since 0.062. =head2 basename $name = path("foo/bar.txt")->basename; # bar.txt $name = path("foo.txt")->basename('.txt'); # foo $name = path("foo.txt")->basename(qr/.txt/); # foo $name = path("foo.txt")->basename(@suffixes); Returns the file portion or last directory portion of a path. Given a list of suffixes as strings or regular expressions, any that match at the end of the file portion or last directory portion will be removed before the result is returned. Current API available since 0.054. =head2 canonpath $canonical = path("foo/bar")->canonpath; # foo\bar on Windows Returns a string with the canonical format of the path name for the platform. In particular, this means directory separators will be C<\> on Windows. Current API available since 0.001. =head2 cached_temp Returns the cached C<File::Temp> or C<File::Temp::Dir> object if the C<Path::Tiny> object was created with C</tempfile> or C</tempdir>. If there is no such object, this method throws. B<WARNING>: Keeping a reference to, or modifying the cached object may break the behavior documented for temporary files and directories created with C<Path::Tiny> and is not supported. Use at your own risk. Current API available since 0.101. =head2 child $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" $file = path("/tmp")->child(@parts); Returns a new C<Path::Tiny> object relative to the original. Works like C<catfile> or C<catdir> from File::Spec, but without caring about file or directories. B<WARNING>: because the argument could contain C<..> or refer to symlinks, there is no guarantee that the new path refers to an actual descendent of the original. If this is important to you, transform parent and child with L</realpath> and check them with L</subsumes>. Current API available since 0.001. =head2 children @paths = path("/tmp")->children; @paths = path("/tmp")->children( qr/\.txt\z/ ); Returns a list of C<Path::Tiny> objects for all files and directories within a directory. Excludes "." and ".." automatically. If an optional C<qr//> argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching: @paths = path("/tmp")->children( qr/^foo/ ); # matches children like the glob foo* Current API available since 0.028. =head2 chmod path("foo.txt")->chmod(0777); path("foo.txt")->chmod("0755"); path("foo.txt")->chmod("go-w"); path("foo.txt")->chmod("a=r,u+wx"); Sets file or directory permissions. The argument can be a numeric mode, a octal string beginning with a "0" or a limited subset of the symbolic mode use by F</bin/chmod>. The symbolic mode must be a comma-delimited list of mode clauses. Clauses must match C<< qr/\A([augo]+)([=+-])([rwx]+)\z/ >>, which defines "who", "op" and "perms" parameters for each clause. Unlike F</bin/chmod>, all three parameters are required for each clause, multiple ops are not allowed and permissions C<stugoX> are not supported. (See L<File::chmod> for more complex needs.) Current API available since 0.053. =head2 copy path("/tmp/foo.txt")->copy("/tmp/bar.txt"); Copies the current path to the given destination using L<File::Copy>'s C<copy> function. Upon success, returns the C<Path::Tiny> object for the newly copied file. Current API available since 0.070. =head2 digest $obj = path("/tmp/foo.txt")->digest; # SHA-256 $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); Returns a hexadecimal digest for a file. An optional hash reference of options may be given. The only option is C<chunk_size>. If C<chunk_size> is given, that many bytes will be read at a time. If not provided, the entire file will be slurped into memory to compute the digest. Any subsequent arguments are passed to the constructor for L<Digest> to select an algorithm. If no arguments are given, the default is SHA-256. Current API available since 0.056. =head2 dirname (deprecated) $name = path("/tmp/foo.txt")->dirname; # "/tmp/" Returns the directory portion you would get from calling C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a path without a parent directory portion. Because L<File::Spec> is inconsistent, the result might or might not have a trailing slash. Because of this, this method is B<deprecated>. A better, more consistently approach is likely C<< $path->parent->stringify >>, which will not have a trailing slash except for a root directory. Deprecated in 0.056. =head2 edit, edit_raw, edit_utf8 path("foo.txt")->edit( \&callback, $options ); path("foo.txt")->edit_utf8( \&callback ); path("foo.txt")->edit_raw( \&callback ); These are convenience methods that allow "editing" a file using a single callback argument. They slurp the file using C<slurp>, place the contents inside a localized C<$_> variable, call the callback function (without arguments), and then write C<$_> (presumably mutated) back to the file with C<spew>. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to C<slurp> and C<spew>. C<edit_utf8> and C<edit_raw> act like their respective C<slurp_*> and C<spew_*> methods. Current API available since 0.077. =head2 edit_lines, edit_lines_utf8, edit_lines_raw path("foo.txt")->edit_lines( \&callback, $options ); path("foo.txt")->edit_lines_utf8( \&callback ); path("foo.txt")->edit_lines_raw( \&callback ); These are convenience methods that allow "editing" a file's lines using a single callback argument. They iterate over the file: for each line, the line is put into a localized C<$_> variable, the callback function is executed (without arguments) and then C<$_> is written to a temporary file. When iteration is finished, the temporary file is atomically renamed over the original. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to the method that open handles for reading and writing. C<edit_lines_raw> is like C<edit_lines> with a buffered C<binmode> of C<:raw>. C<edit_lines_utf8> is like C<edit_lines> with a buffered C<binmode> C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). Current API available since 0.077. =head2 exists, is_file, is_dir if ( path("/tmp")->exists ) { ... } # -e if ( path("/tmp")->is_dir ) { ... } # -d if ( path("/tmp")->is_file ) { ... } # -e && ! -d Implements file test operations, this means the file or directory actually has to exist on the filesystem. Until then, it's just a path. B<Note>: C<is_file> is not C<-f> because C<-f> is not the opposite of C<-d>. C<-f> means "plain file", excluding symlinks, devices, etc. that often can be read just like files. Use C<-f> instead if you really mean to check for a plain file. Current API available since 0.053. =head2 filehandle $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); Returns an open file handle. The C<$mode> argument must be a Perl-style read/write mode string ("<" ,">", ">>", etc.). If a C<$binmode> is given, it is set during the C<open> call. An optional hash reference may be used to pass options. The C<locked> option governs file locking; if true, handles opened for writing, appending or read-write are locked with C<LOCK_EX>; otherwise, they are locked with C<LOCK_SH>. When using C<locked>, ">" or "+>" modes will delay truncation until after the lock is acquired. The C<exclusive> option causes the open() call to fail if the file already exists. This corresponds to the O_EXCL flag to sysopen / open(2). C<exclusive> implies C<locked> and will set it for you if you forget it. See C<openr>, C<openw>, C<openrw>, and C<opena> for sugar. Current API available since 0.066. =head2 has_same_bytes if ( path("foo.txt")->has_same_bytes("bar.txt") ) { # ... } This method returns true if both the invocant and the argument can be opened as file handles and the handles contain the same bytes. It returns false if their contents differ. If either can't be opened as a file (e.g. a directory or non-existent file), the method throws an exception. If both can be opened and both have the same C<realpath>, the method returns true without scanning any data. Current API available since 0.125. =head2 is_absolute, is_relative if ( path("/tmp")->is_absolute ) { ... } if ( path("/tmp")->is_relative ) { ... } Booleans for whether the path appears absolute or relative. Current API available since 0.001. =head2 is_rootdir while ( ! $path->is_rootdir ) { $path = $path->parent; ... } Boolean for whether the path is the root directory of the volume. I.e. the C<dirname> is C<q[/]> and the C<basename> is C<q[]>. This works even on C<MSWin32> with drives and UNC volumes: path("C:/")->is_rootdir; # true path("//server/share/")->is_rootdir; #true Current API available since 0.038. =head2 iterator $iter = path("/tmp")->iterator( \%options ); Returns a code reference that walks a directory lazily. Each invocation returns a C<Path::Tiny> object or undef when the iterator is exhausted. $iter = path("/tmp")->iterator; while ( $path = $iter->() ) { ... } The current and parent directory entries ("." and "..") will not be included. If the C<recurse> option is true, the iterator will walk the directory recursively, breadth-first. If the C<follow_symlinks> option is also true, directory links will be followed recursively. There is no protection against loops when following links. If a directory is not readable, it will not be followed. The default is the same as: $iter = path("/tmp")->iterator( { recurse => 0, follow_symlinks => 0, } ); For a more powerful, recursive iterator with built-in loop avoidance, see L<Path::Iterator::Rule>. See also L</visit>. Current API available since 0.016. =head2 lines, lines_raw, lines_utf8 @contents = path("/tmp/foo.txt")->lines; @contents = path("/tmp/foo.txt")->lines(\%options); @contents = path("/tmp/foo.txt")->lines_raw; @contents = path("/tmp/foo.txt")->lines_utf8; @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); Returns a list of lines from a file. Optionally takes a hash-reference of options. Valid options are C<binmode>, C<count> and C<chomp>. If C<binmode> is provided, it will be set on the handle prior to reading. If a positive C<count> is provided, that many lines will be returned from the start of the file. If a negative C<count> is provided, the entire file will be read, but only C<abs(count)> will be kept and returned. If C<abs(count)> exceeds the number of lines in the file, all lines will be returned. If C<chomp> is set, any end-of-line character sequences (C<CR>, C<CRLF>, or C<LF>) will be removed from the lines returned. Because the return is a list, C<lines> in scalar context will return the number of lines (and throw away the data). $number_of_lines = path("/tmp/foo.txt")->lines; C<lines_raw> is like C<lines> with a C<binmode> of C<:raw>. We use C<:raw> instead of C<:unix> so PerlIO buffering can manage reading by line. C<lines_utf8> is like C<lines> with a C<binmode> of C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the lines will be split. This is actually faster than relying on IO layers, though a bit memory intensive. If memory use is a concern, consider C<openr_utf8> and iterating directly on the handle. Current API available since 0.065. =head2 mkdir path("foo/bar/baz")->mkdir; path("foo/bar/baz")->mkdir( \%options ); Like calling C<make_path> from L<File::Path>. An optional hash reference is passed through to C<make_path>. Errors will be trapped and an exception thrown. Returns the the path object to facilitate chaining. B<NOTE>: unlike Perl's builtin C<mkdir>, this will create intermediate paths similar to the Unix C<mkdir -p> command. It will not error if applied to an existing directory. Current API available since 0.125. =head2 mkpath (deprecated) Like calling C<mkdir>, but returns the list of directories created or an empty list if the directories already exist, just like C<make_path>. Deprecated in 0.125. =head2 move path("foo.txt")->move("bar.txt"); Moves the current path to the given destination using L<File::Copy>'s C<move> function. Upon success, returns the C<Path::Tiny> object for the newly moved file. If the destination already exists and is a directory, and the source is not a directory, then the source file will be renamed into the directory specified by the destination. If possible, move() will simply rename the file. Otherwise, it copies the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. Current API available since 0.124. Prior versions used Perl's -built-in (and less robust) L<rename|perlfunc/rename> function and did not return an object. =head2 openr, openw, openrw, opena $fh = path("foo.txt")->openr($binmode); # read $fh = path("foo.txt")->openr_raw; $fh = path("foo.txt")->openr_utf8; $fh = path("foo.txt")->openw($binmode); # write $fh = path("foo.txt")->openw_raw; $fh = path("foo.txt")->openw_utf8; $fh = path("foo.txt")->opena($binmode); # append $fh = path("foo.txt")->opena_raw; $fh = path("foo.txt")->opena_utf8; $fh = path("foo.txt")->openrw($binmode); # read/write $fh = path("foo.txt")->openrw_raw; $fh = path("foo.txt")->openrw_utf8; Returns a file handle opened in the specified mode. The C<openr> style methods take a single C<binmode> argument. All of the C<open*> methods have C<open*_raw> and C<open*_utf8> equivalents that use buffered I/O layers C<:raw> and C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). An optional hash reference may be used to pass options. The only option is C<locked>. If true, handles opened for writing, appending or read-write are locked with C<LOCK_EX>; otherwise, they are locked for C<LOCK_SH>. $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); See L</filehandle> for more on locking. Current API available since 0.011. =head2 parent $parent = path("foo/bar/baz")->parent; # foo/bar $parent = path("foo/wibble.txt")->parent; # foo $parent = path("foo/bar/baz")->parent(2); # foo Returns a C<Path::Tiny> object corresponding to the parent directory of the original directory or file. An optional positive integer argument is the number of parent directories upwards to return. C<parent> by itself is equivalent to C<parent(1)>. Current API available since 0.014. =head2 realpath $real = path("/baz/foo/../bar")->realpath; $real = path("foo/../bar")->realpath; Returns a new C<Path::Tiny> object with all symbolic links and upward directory parts resolved using L<Cwd>'s C<realpath>. Compared to C<absolute>, this is more expensive as it must actually consult the filesystem. If the parent path can't be resolved (e.g. if it includes directories that don't exist), an exception will be thrown: $real = path("doesnt_exist/foo")->realpath; # dies However, if the parent path exists and only the last component (e.g. filename) doesn't exist, the realpath will be the realpath of the parent plus the non-existent last component: $real = path("./aasdlfasdlf")->realpath; # works The underlying L<Cwd> module usually worked this way on Unix, but died on Windows (and some Unixes) if the full path didn't exist. As of version 0.064, it's safe to use anywhere. Current API available since 0.001. =head2 relative $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar Returns a C<Path::Tiny> object with a path relative to a new base path given as an argument. If no argument is given, the current directory will be used as the new base path. If either path is already relative, it will be made absolute based on the current directly before determining the new relative path. The algorithm is roughly as follows: =over 4 =item * If the original and new base path are on different volumes, an exception will be thrown. =item * If the original and new base are identical, the relative path is C<".">. =item * If the new base subsumes the original, the relative path is the original path with the new base chopped off the front =item * If the new base does not subsume the original, a common prefix path is determined (possibly the root directory) and the relative path will consist of updirs (C<"..">) to reach the common prefix, followed by the original path less the common prefix. =back Unlike C<File::Spec::abs2rel>, in the last case above, the calculation based on a common prefix takes into account symlinks that could affect the updir process. Given an original path "/A/B" and a new base "/A/C", (where "A", "B" and "C" could each have multiple path components): =over 4 =item * Symlinks in "A" don't change the result unless the last component of A is a symlink and the first component of "C" is an updir. =item * Symlinks in "B" don't change the result and will exist in the result as given. =item * Symlinks and updirs in "C" must be resolved to actual paths, taking into account the possibility that not all path components might exist on the filesystem. =back Current API available since 0.001. New algorithm (that accounts for symlinks) available since 0.079. =head2 remove path("foo.txt")->remove; This is just like C<unlink>, except for its error handling: if the path does not exist, it returns false; if deleting the file fails, it throws an exception. Current API available since 0.012. =head2 remove_tree # directory path("foo/bar/baz")->remove_tree; path("foo/bar/baz")->remove_tree( \%options ); path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove Like calling C<remove_tree> from L<File::Path>, but defaults to C<safe> mode. An optional hash reference is passed through to C<remove_tree>. Errors will be trapped and an exception thrown. Returns the number of directories deleted, just like C<remove_tree>. If you want to remove a directory only if it is empty, use the built-in C<rmdir> function instead. rmdir path("foo/bar/baz/"); Current API available since 0.013. =head2 sibling $foo = path("/tmp/foo.txt"); $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt Returns a new C<Path::Tiny> object relative to the parent of the original. This is slightly more efficient than C<< $path->parent->child(...) >>. Current API available since 0.058. =head2 size, size_human my $p = path("foo"); # with size 1025 bytes $p->size; # "1025" $p->size_human; # "1.1 K" $p->size_human( {format => "iec"} ); # "1.1 KiB" Returns the size of a file. The C<size> method is just a wrapper around C<-s>. The C<size_human> method provides a human-readable string similar to C<ls -lh>. Like C<ls>, it rounds upwards and provides one decimal place for single-digit sizes and no decimal places for larger sizes. The only available option is C<format>, which has three valid values: =over 4 =item * 'ls' (the default): base-2 sizes, with C<ls> style single-letter suffixes (K, M, etc.) =item * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) =item * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) =back If C<-s> would return C<undef>, C<size_human> returns the empty string. Current API available since 0.122. =head2 slurp, slurp_raw, slurp_utf8 $data = path("foo.txt")->slurp; $data = path("foo.txt")->slurp( {binmode => ":raw"} ); $data = path("foo.txt")->slurp_raw; $data = path("foo.txt")->slurp_utf8; Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is C<binmode>, which is passed to C<binmode()> on the handle used for reading. C<slurp_raw> is like C<slurp> with a C<binmode> of C<:unix> for a fast, unbuffered, raw read. C<slurp_utf8> is like C<slurp> with a C<binmode> of C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a unbuffered, raw slurp will be done instead and the result decoded with C<Unicode::UTF8>. This is just as strict and is roughly an order of magnitude faster than using C<:encoding(UTF-8)>. B<Note>: C<slurp> and friends lock the filehandle before slurping. If you plan to slurp from a file created with L<File::Temp>, be sure to close other handles or open without locking to avoid a deadlock: my $tempfile = File::Temp->new(EXLOCK => 0); my $guts = path($tempfile)->slurp; Current API available since 0.004. =head2 spew, spew_raw, spew_utf8 path("foo.txt")->spew(@data); path("foo.txt")->spew(\@data); path("foo.txt")->spew({binmode => ":raw"}, @data); path("foo.txt")->spew_raw(@data); path("foo.txt")->spew_utf8(@data); Writes data to a file atomically. The file is written to a temporary file in the same directory, then renamed over the original. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to C<binmode()> on the handle used for writing. C<spew_raw> is like C<spew> with a C<binmode> of C<:unix> for a fast, unbuffered, raw write. C<spew_utf8> is like C<spew> with a C<binmode> of C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a raw, unbuffered spew will be done instead on the data encoded with C<Unicode::UTF8>. B<NOTE>: because the file is written to a temporary file and then renamed, the new file will wind up with permissions based on your current umask. This is a feature to protect you from a race condition that would otherwise give different permissions than you might expect. If you really want to keep the original mode flags, use L</append> with the C<truncate> option. Current API available since 0.011. =head2 stat, lstat $stat = path("foo.txt")->stat; $stat = path("/some/symlink")->lstat; Like calling C<stat> or C<lstat> from L<File::stat>. Current API available since 0.001. =head2 stringify $path = path("foo.txt"); say $path->stringify; # same as "$path" Returns a string representation of the path. Unlike C<canonpath>, this method returns the path standardized with Unix-style C</> directory separators. Current API available since 0.001. =head2 subsumes path("foo/bar")->subsumes("foo/bar/baz"); # true path("/foo/bar")->subsumes("/foo/baz"); # false Returns true if the first path is a prefix of the second path at a directory boundary. This B<does not> resolve parent directory entries (C<..>) or symlinks: path("foo/bar")->subsumes("foo/bar/../baz"); # true If such things are important to you, ensure that both paths are resolved to the filesystem with C<realpath>: my $p1 = path("foo/bar")->realpath; my $p2 = path("foo/bar/../baz")->realpath; if ( $p1->subsumes($p2) ) { ... } Current API available since 0.048. =head2 touch path("foo.txt")->touch; path("foo.txt")->touch($epoch_secs); Like the Unix C<touch> utility. Creates the file if it doesn't exist, or else changes the modification and access times to the current time. If the first argument is the epoch seconds then it will be used. Returns the path object so it can be easily chained with other methods: # won't die if foo.txt doesn't exist $content = path("foo.txt")->touch->slurp; Current API available since 0.015. =head2 touchpath path("bar/baz/foo.txt")->touchpath; Combines C<mkdir> and C<touch>. Creates the parent directory if it doesn't exist, before touching the file. Returns the path object like C<touch> does. If you need to pass options, use C<mkdir> and C<touch> separately: path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); Current API available since 0.022. =head2 visit path("/tmp")->visit( \&callback, \%options ); Executes a callback for each child of a directory. It returns a hash reference with any state accumulated during iteration. The options are the same as for L</iterator> (which it uses internally): C<recurse> and C<follow_symlinks>. Both default to false. The callback function will receive a C<Path::Tiny> object as the first argument and a hash reference to accumulate state as the second argument. For example: # collect files sizes my $sizes = path("/tmp")->visit( sub { my ($path, $state) = @_; return if $path->is_dir; $state->{$path} = -s $path; }, { recurse => 1 } ); For convenience, the C<Path::Tiny> object will also be locally aliased as the C<$_> global variable: # print paths matching /foo/ path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); If the callback returns a B<reference> to a false scalar value, iteration will terminate. This is not the same as "pruning" a directory search; this just stops all iteration and returns the state hash reference. # find up to 10 files larger than 100K my $files = path("/tmp")->visit( sub { my ($path, $state) = @_; $state->{$path}++ if -s $path > 102400 return \0 if keys %$state == 10; }, { recurse => 1 } ); If you want more flexible iteration, use a module like L<Path::Iterator::Rule>. Current API available since 0.062. =head2 volume $vol = path("/tmp/foo.txt")->volume; # "" $vol = path("C:/tmp/foo.txt")->volume; # "C:" Returns the volume portion of the path. This is equivalent to what L<File::Spec> would give from C<splitpath> and thus usually is the empty string on Unix-like operating systems or the drive letter for an absolute path on C<MSWin32>. Current API available since 0.001. =for Pod::Coverage openr_utf8 opena_utf8 openw_utf8 openrw_utf8 openr_raw opena_raw openw_raw openrw_raw IS_WIN32 FREEZE THAW TO_JSON abs2rel =head1 EXCEPTION HANDLING Simple usage errors will generally croak. Failures of underlying Perl functions will be thrown as exceptions in the class C<Path::Tiny::Error>. A C<Path::Tiny::Error> object will be a hash reference with the following fields: =over 4 =item * C<op> — a description of the operation, usually function call and any extra info =item * C<file> — the file or directory relating to the error =item * C<err> — hold C<$!> at the time the error was thrown =item * C<msg> — a string combining the above data and a Carp-like short stack trace =back Exception objects will stringify as the C<msg> field. =head1 ENVIRONMENT =head2 PERL_PATH_TINY_NO_FLOCK If the environment variable C<PERL_PATH_TINY_NO_FLOCK> is set to a true value then flock will NOT be used when accessing files (this is not recommended). =head1 CAVEATS =head2 Subclassing not supported For speed, this class is implemented as an array based object and uses many direct function calls internally. You must not subclass it and expect things to work properly. =head2 Tilde expansion (deprecated) Tilde expansion was a nice idea, but it can't easily be applied consistently across the entire API. This was a source of bugs and confusion for users. Therefore, it is B<deprecated> and its use is discouraged. Limitations to the existing, legacy behavior follow. Tilde expansion will only occur if the B<first> argument to C<path> begins with a tilde. B<No other method does tilde expansion on its arguments>. If you want tilde expansion on arguments, you must explicitly wrap them in a call to C<path>. path( "~/foo.txt" )->copy( path( "~/bar.txt" ) ); If you need a literal leading tilde, use C<path("./~whatever")> so that the argument to C<path> doesn't start with a tilde, but the path still resolves to the current directory. Behaviour of tilde expansion with a username for non-existent users depends on the output of C<glob> on the system. =head2 File locking If flock is not supported on a platform, it will not be used, even if locking is requested. In situations where a platform normally would support locking, but the flock fails due to a filesystem limitation, Path::Tiny has some heuristics to detect this and will warn once and continue in an unsafe mode. If you want this failure to be fatal, you can fatalize the 'flock' warnings category: use warnings FATAL => 'flock'; See additional caveats below. =head3 NFS and BSD On BSD, Perl's flock implementation may not work to lock files on an NFS filesystem. If detected, this situation will warn once, as described above. =head3 Lustre The Lustre filesystem does not support flock. If detected, this situation will warn once, as described above. =head3 AIX and locking AIX requires a write handle for locking. Therefore, calls that normally open a read handle and take a shared lock instead will open a read-write handle and take an exclusive lock. If the user does not have write permission, no lock will be used. =head2 utf8 vs UTF-8 All the C<*_utf8> methods by default use C<:encoding(UTF-8)> -- either as C<:unix:encoding(UTF-8)> (unbuffered, for whole file operations) or C<:raw:encoding(UTF-8)> (buffered, for line-by-line operations). These are strict against the Unicode spec and disallows illegal Unicode codepoints or UTF-8 sequences. Unfortunately, C<:encoding(UTF-8)> is very, very slow. If you install L<Unicode::UTF8> 0.58 or later, that module will be used by some C<*_utf8> methods to encode or decode data after a raw, binary input/output operation, which is much faster. Alternatively, if you install L<PerlIO::utf8_strict>, that will be used instead of C<:encoding(UTF-8)> and is also very fast. If you need the performance and can accept the security risk, C<< slurp({binmode => ":unix:utf8"}) >> will be faster than C<:unix:encoding(UTF-8)> (but not as fast as C<Unicode::UTF8>). Note that the C<*_utf8> methods read in B<raw> mode. There is no CRLF translation on Windows. If you must have CRLF translation, use the regular input/output methods with an appropriate binmode: $path->spew_utf8($data); # raw $path->spew({binmode => ":encoding(UTF-8)"}, $data; # LF -> CRLF =head2 Default IO layers and the open pragma If you have Perl 5.10 or later, file input/output methods (C<slurp>, C<spew>, etc.) and high-level handle opening methods ( C<filehandle>, C<openr>, C<openw>, etc. ) respect default encodings set by the C<-C> switch or lexical L<open> settings of the caller. For UTF-8, this is almost certainly slower than using the dedicated C<_utf8> methods if you have L<Unicode::UTF8> or L<PerlIP::utf8_strict>. =head1 TYPE CONSTRAINTS AND COERCION A standard L<MooseX::Types> library is available at L<MooseX::Types::Path::Tiny>. A L<Type::Tiny> equivalent is available as L<Types::Path::Tiny>. =head1 SEE ALSO These are other file/path utilities, which may offer a different feature set than C<Path::Tiny>. =over 4 =item * L<File::chmod> =item * L<File::Fu> =item * L<IO::All> =item * L<Path::Class> =back These iterators may be slightly faster than the recursive iterator in C<Path::Tiny>: =over 4 =item * L<Path::Iterator::Rule> =item * L<File::Next> =back There are probably comparable, non-Tiny tools. Let me know if you want me to add a module to the list. This module was featured in the L<2013 Perl Advent Calendar|http://www.perladvent.org/2013/2013-12-18.html>. =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L<https://github.com/dagolden/Path-Tiny/issues>. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L<https://github.com/dagolden/Path-Tiny> git clone https://github.com/dagolden/Path-Tiny.git =head1 AUTHOR David Golden <dagolden@cpan.org> =head1 CONTRIBUTORS =for stopwords Alex Efros Aristotle Pagaltzis Chris Williams Dan Book Dave Rolsky David Steinbrunner Doug Bell Elvin Aslanov Flavio Poletti Gabor Szabo Gabriel Andrade George Hartzell Geraud Continsouzas Goro Fuji Graham Knop Ollis Ian Sillitoe James Hunt John Karr Karen Etheridge Mark Ellis Martin H. Sluka Kjeldsen Mary Ehlers Michael G. Schwern Nicolas R Rochelemagne Nigel Gregoire Philippe Bruhat (BooK) regina-verbae Roy Ivy III Shlomi Fish Smylers Tatsuhiko Miyagawa Toby Inkster Yanick Champoux 김도형 - Keedi Kim =over 4 =item * Alex Efros <powerman@powerman.name> =item * Aristotle Pagaltzis <pagaltzis@gmx.de> =item * Chris Williams <bingos@cpan.org> =item * Dan Book <grinnz@grinnz.com> =item * Dave Rolsky <autarch@urth.org> =item * David Steinbrunner <dsteinbrunner@pobox.com> =item * Doug Bell <madcityzen@gmail.com> =item * Elvin Aslanov <rwp.primary@gmail.com> =item * Flavio Poletti <flavio@polettix.it> =item * Gabor Szabo <szabgab@cpan.org> =item * Gabriel Andrade <gabiruh@gmail.com> =item * George Hartzell <hartzell@cpan.org> =item * Geraud Continsouzas <geraud@scsi.nc> =item * Goro Fuji <gfuji@cpan.org> =item * Graham Knop <haarg@haarg.org> =item * Graham Ollis <plicease@cpan.org> =item * Ian Sillitoe <ian@sillit.com> =item * James Hunt <james@niftylogic.com> =item * John Karr <brainbuz@brainbuz.org> =item * Karen Etheridge <ether@cpan.org> =item * Mark Ellis <mark.ellis@cartridgesave.co.uk> =item * Martin H. Sluka <fany@cpan.org> =item * Martin Kjeldsen <mk@bluepipe.dk> =item * Mary Ehlers <regina.verb.ae@gmail.com> =item * Michael G. Schwern <mschwern@cpan.org> =item * Nicolas R <nicolas@atoomic.org> =item * Nicolas Rochelemagne <rochelemagne@cpanel.net> =item * Nigel Gregoire <nigelgregoire@gmail.com> =item * Philippe Bruhat (BooK) <book@cpan.org> =item * regina-verbae <regina-verbae@users.noreply.github.com> =item * Roy Ivy III <rivy@cpan.org> =item * Shlomi Fish <shlomif@shlomifish.org> =item * Smylers <Smylers@stripey.com> =item * Tatsuhiko Miyagawa <miyagawa@bulknews.net> =item * Toby Inkster <tobyink@cpan.org> =item * Yanick Champoux <yanick@babyl.dyndns.org> =item * 김도형 - Keedi Kim <keedi@cpan.org> =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut blib/lib/auto/Path/Tiny/.exists 0000644 00000000000 15125124546 0012324 0 ustar 00 MYMETA.yml 0000644 00000006065 15125124546 0006277 0 ustar 00 --- abstract: 'File path utility' author: - 'David Golden <dagolden@cpan.org>' build_requires: Digest::MD5: '0' ExtUtils::MakeMaker: '0' File::Basename: '0' File::Spec: '0.86' File::Spec::Functions: '0' File::Spec::Unix: '0' File::Temp: '0.19' Test::More: '0.96' lib: '0' open: '0' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Path-Tiny no_index: directory: - corpus - examples - t - xt package: - DB - flock provides: Path::Tiny: file: lib/Path/Tiny.pm version: '0.146' Path::Tiny::Error: file: lib/Path/Tiny.pm version: '0.146' recommends: Unicode::UTF8: '0.58' requires: Carp: '0' Cwd: '0' Digest: '1.03' Digest::SHA: '5.45' Encode: '0' Exporter: '5.57' Fcntl: '0' File::Compare: '0' File::Copy: '0' File::Glob: '0' File::Path: '2.07' File::Spec: '0.86' File::Temp: '0.19' File::stat: '0' constant: '0' overload: '0' perl: '5.008001' strict: '0' warnings: '0' warnings::register: '0' resources: bugtracker: https://github.com/dagolden/Path-Tiny/issues homepage: https://github.com/dagolden/Path-Tiny repository: https://github.com/dagolden/Path-Tiny.git version: '0.146' x_authority: cpan:DAGOLDEN x_contributors: - 'Alex Efros <powerman@powerman.name>' - 'Aristotle Pagaltzis <pagaltzis@gmx.de>' - 'Chris Williams <bingos@cpan.org>' - 'Dan Book <grinnz@grinnz.com>' - 'Dave Rolsky <autarch@urth.org>' - 'David Steinbrunner <dsteinbrunner@pobox.com>' - 'Doug Bell <madcityzen@gmail.com>' - 'Elvin Aslanov <rwp.primary@gmail.com>' - 'Flavio Poletti <flavio@polettix.it>' - 'Gabor Szabo <szabgab@cpan.org>' - 'Gabriel Andrade <gabiruh@gmail.com>' - 'George Hartzell <hartzell@cpan.org>' - 'Geraud Continsouzas <geraud@scsi.nc>' - 'Goro Fuji <gfuji@cpan.org>' - 'Graham Knop <haarg@haarg.org>' - 'Graham Ollis <plicease@cpan.org>' - 'Ian Sillitoe <ian@sillit.com>' - 'James Hunt <james@niftylogic.com>' - 'John Karr <brainbuz@brainbuz.org>' - 'Karen Etheridge <ether@cpan.org>' - 'Mark Ellis <mark.ellis@cartridgesave.co.uk>' - 'Martin H. Sluka <fany@cpan.org>' - 'Martin Kjeldsen <mk@bluepipe.dk>' - 'Mary Ehlers <regina.verb.ae@gmail.com>' - 'Michael G. Schwern <mschwern@cpan.org>' - 'Nicolas R <nicolas@atoomic.org>' - 'Nicolas Rochelemagne <rochelemagne@cpanel.net>' - 'Nigel Gregoire <nigelgregoire@gmail.com>' - 'Philippe Bruhat (BooK) <book@cpan.org>' - 'regina-verbae <regina-verbae@users.noreply.github.com>' - 'Roy Ivy III <rivy@cpan.org>' - 'Shlomi Fish <shlomif@shlomifish.org>' - 'Smylers <Smylers@stripey.com>' - 'Tatsuhiko Miyagawa <miyagawa@bulknews.net>' - 'Toby Inkster <tobyink@cpan.org>' - 'Yanick Champoux <yanick@babyl.dyndns.org>' - '김도형 - Keedi Kim <keedi@cpan.org>' x_generated_by_perl: v5.36.0 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_spdx_expression: Apache-2.0 MANIFEST 0000644 00000001734 15125124546 0005707 0 ustar 00 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.031. CONTRIBUTING.mkdn Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Path/Tiny.pm perlcritic.rc t/00-report-prereqs.dd t/00-report-prereqs.t t/README t/basename.t t/basic.t t/children.t t/chmod.t t/data/chmod.txt t/digest.t t/exception.t t/exports.t t/fakelib/PerlIO/utf8_strict.pm t/fakelib/Unicode/UTF8.pm t/filesystem.t t/has_same_bytes.t t/input_output.t t/input_output_no_PU_UU.t t/input_output_no_UU.t t/lib/TestUtils.pm t/locking.t t/mkdir.t t/mkpath.t t/mutable_tree_while_iterating.t t/normalize.t t/overloading.t t/parent.t t/recurse.t t/rel-abs.t t/sig_die.t t/size.t t/subsumes.t t/symlinks.t t/temp.t t/visit.t t/zz-atomic.t t/zzz-spec.t tidyall.ini xt/author/00-compile.t xt/author/critic.t xt/author/distmeta.t xt/author/minimum-version.t xt/author/pod-coverage.t xt/author/pod-spell.t xt/author/pod-syntax.t xt/author/portability.t xt/author/test-version.t lib/Path/Tiny.pm 0000644 00000373402 15125124546 0007505 0 ustar 00 use 5.008001; use strict; use warnings; package Path::Tiny; # ABSTRACT: File path utility our $VERSION = '0.146'; # Dependencies use Config; use Exporter 5.57 (qw/import/); use File::Spec 0.86 (); # shipped with 5.8.1 use Carp (); our @EXPORT = qw/path/; our @EXPORT_OK = qw/cwd rootdir tempfile tempdir/; use constant { PATH => 0, CANON => 1, VOL => 2, DIR => 3, FILE => 4, TEMP => 5, IS_WIN32 => ( $^O eq 'MSWin32' ), }; use overload ( q{""} => 'stringify', bool => sub () { 1 }, fallback => 1, ); # FREEZE/THAW per Sereal/CBOR/Types::Serialiser protocol sub THAW { return path( $_[2] ) } { no warnings 'once'; *TO_JSON = *FREEZE = \&stringify }; my $HAS_UU; # has Unicode::UTF8; lazily populated sub _check_UU { local $SIG{__DIE__}; # prevent outer handler from being called !!eval { require Unicode::UTF8; Unicode::UTF8->VERSION(0.58); 1; }; } my $HAS_PU; # has PerlIO::utf8_strict; lazily populated sub _check_PU { local $SIG{__DIE__}; # prevent outer handler from being called !!eval { # MUST preload Encode or $SIG{__DIE__} localization fails # on some Perl 5.8.8 (maybe other 5.8.*) compiled with -O2. require Encode; require PerlIO::utf8_strict; PerlIO::utf8_strict->VERSION(0.003); 1; }; } my $HAS_FLOCK = $Config{d_flock} || $Config{d_fcntl_can_lock} || $Config{d_lockf}; # notions of "root" directories differ on Win32: \\server\dir\ or C:\ or \ my $SLASH = qr{[\\/]}; my $NOTSLASH = qr{[^\\/]}; my $DRV_VOL = qr{[a-z]:}i; my $UNC_VOL = qr{$SLASH $SLASH $NOTSLASH+ $SLASH $NOTSLASH+}x; my $WIN32_ROOT = qr{(?: $UNC_VOL $SLASH | $DRV_VOL $SLASH | $SLASH )}x; sub _win32_vol { my ( $path, $drv ) = @_; require Cwd; my $dcwd = eval { Cwd::getdcwd($drv) }; # C: -> C:\some\cwd # getdcwd on non-existent drive returns empty string # so just use the original drive Z: -> Z: $dcwd = "$drv" unless defined $dcwd && length $dcwd; # normalize dwcd to end with a slash: might be C:\some\cwd or D:\ or Z: $dcwd =~ s{$SLASH?\z}{/}; # make the path absolute with dcwd $path =~ s{^$DRV_VOL}{$dcwd}; return $path; } # This is a string test for before we have the object; see is_rootdir for well-formed # object test sub _is_root { return IS_WIN32() ? ( $_[0] =~ /^$WIN32_ROOT\z/ ) : ( $_[0] eq '/' ); } BEGIN { *_same = IS_WIN32() ? sub { lc( $_[0] ) eq lc( $_[1] ) } : sub { $_[0] eq $_[1] }; } # mode bits encoded for chmod in symbolic mode my %MODEBITS = ( om => 0007, gm => 0070, um => 0700 ); ## no critic { my $m = 0; $MODEBITS{$_} = ( 1 << $m++ ) for qw/ox ow or gx gw gr ux uw ur/ }; sub _symbolic_chmod { my ( $mode, $symbolic ) = @_; for my $clause ( split /,\s*/, $symbolic ) { if ( $clause =~ m{\A([augo]+)([=+-])([rwx]+)\z} ) { my ( $who, $action, $perms ) = ( $1, $2, $3 ); $who =~ s/a/ugo/g; for my $w ( split //, $who ) { my $p = 0; $p |= $MODEBITS{"$w$_"} for split //, $perms; if ( $action eq '=' ) { $mode = ( $mode & ~$MODEBITS{"${w}m"} ) | $p; } else { $mode = $action eq "+" ? ( $mode | $p ) : ( $mode & ~$p ); } } } else { Carp::croak("Invalid mode clause '$clause' for chmod()"); } } return $mode; } # flock doesn't work on NFS on BSD or on some filesystems like lustre. # Since program authors often can't control or detect that, we warn once # instead of being fatal if we can detect it and people who need it strict # can fatalize the 'flock' category #<<< No perltidy { package flock; use warnings::register } #>>> my $WARNED_NO_FLOCK = 0; sub _throw { my ( $self, $function, $file, $msg ) = @_; if ( $function =~ /^flock/ && $! =~ /operation not supported|function not implemented/i && !warnings::fatal_enabled('flock') ) { if ( !$WARNED_NO_FLOCK ) { warnings::warn( flock => "Flock not available: '$!': continuing in unsafe mode" ); $WARNED_NO_FLOCK++; } } else { $msg = $! unless defined $msg; Path::Tiny::Error->throw( $function, ( defined $file ? $file : $self->[PATH] ), $msg ); } return; } # cheapo option validation sub _get_args { my ( $raw, @valid ) = @_; if ( defined($raw) && ref($raw) ne 'HASH' ) { my ( undef, undef, undef, $called_as ) = caller(1); $called_as =~ s{^.*::}{}; Carp::croak("Options for $called_as must be a hash reference"); } my $cooked = {}; for my $k (@valid) { $cooked->{$k} = delete $raw->{$k} if exists $raw->{$k}; } if ( keys %$raw ) { my ( undef, undef, undef, $called_as ) = caller(1); $called_as =~ s{^.*::}{}; Carp::croak( "Invalid option(s) for $called_as: " . join( ", ", keys %$raw ) ); } return $cooked; } #--------------------------------------------------------------------------# # Constructors #--------------------------------------------------------------------------# #pod =construct path #pod #pod $path = path("foo/bar"); #pod $path = path("/tmp", "file.txt"); # list #pod $path = path("."); # cwd #pod #pod Constructs a C<Path::Tiny> object. It doesn't matter if you give a file or #pod directory path. It's still up to you to call directory-like methods only on #pod directories and file-like methods only on files. This function is exported #pod automatically by default. #pod #pod The first argument must be defined and have non-zero length or an exception #pod will be thrown. This prevents subtle, dangerous errors with code like #pod C<< path( maybe_undef() )->remove_tree >>. #pod #pod B<DEPRECATED>: If and only if the B<first> character of the B<first> argument #pod to C<path> is a tilde ('~'), then tilde replacement will be applied to the #pod first path segment. A single tilde will be replaced with C<glob('~')> and a #pod tilde followed by a username will be replaced with output of #pod C<glob('~username')>. B<No other method does tilde expansion on its arguments>. #pod See L</Tilde expansion (deprecated)> for more. #pod #pod On Windows, if the path consists of a drive identifier without a path component #pod (C<C:> or C<D:>), it will be expanded to the absolute path of the current #pod directory on that volume using C<Cwd::getdcwd()>. #pod #pod If called with a single C<Path::Tiny> argument, the original is returned unless #pod the original is holding a temporary file or directory reference in which case a #pod stringified copy is made. #pod #pod $path = path("foo/bar"); #pod $temp = Path::Tiny->tempfile; #pod #pod $p2 = path($path); # like $p2 = $path #pod $t2 = path($temp); # like $t2 = path( "$temp" ) #pod #pod This optimizes copies without proliferating references unexpectedly if a copy is #pod made by code outside your control. #pod #pod Current API available since 0.017. #pod #pod =cut sub path { my $path = shift; Carp::croak("Path::Tiny paths require defined, positive-length parts") unless 1 + @_ == grep { defined && length } $path, @_; # non-temp Path::Tiny objects are effectively immutable and can be reused if ( !@_ && ref($path) eq __PACKAGE__ && !$path->[TEMP] ) { return $path; } # stringify objects $path = "$path"; # do any tilde expansions my ($tilde) = $path =~ m{^(~[^/]*)}; if ( defined $tilde ) { # Escape File::Glob metacharacters (my $escaped = $tilde) =~ s/([\[\{\*\?\\])/\\$1/g; require File::Glob; my ($homedir) = File::Glob::bsd_glob($escaped); if (defined $homedir && ! $File::Glob::ERROR) { $homedir =~ tr[\\][/] if IS_WIN32(); $path =~ s{^\Q$tilde\E}{$homedir}; } } unshift @_, $path; goto &_pathify; } # _path is like path but without tilde expansion sub _path { my $path = shift; Carp::croak("Path::Tiny paths require defined, positive-length parts") unless 1 + @_ == grep { defined && length } $path, @_; # non-temp Path::Tiny objects are effectively immutable and can be reused if ( !@_ && ref($path) eq __PACKAGE__ && !$path->[TEMP] ) { return $path; } # stringify objects $path = "$path"; unshift @_, $path; goto &_pathify; } # _pathify expects one or more string arguments, then joins and canonicalizes # them into an object. sub _pathify { my $path = shift; # expand relative volume paths on windows; put trailing slash on UNC root if ( IS_WIN32() ) { $path = _win32_vol( $path, $1 ) if $path =~ m{^($DRV_VOL)(?:$NOTSLASH|\z)}; $path .= "/" if $path =~ m{^$UNC_VOL\z}; } # concatenations stringifies objects, too if (@_) { $path .= ( _is_root($path) ? "" : "/" ) . join( "/", @_ ); } # canonicalize, but with unix slashes and put back trailing volume slash my $cpath = $path = File::Spec->canonpath($path); $path =~ tr[\\][/] if IS_WIN32(); $path = "/" if $path eq '/..'; # for old File::Spec $path .= "/" if IS_WIN32() && $path =~ m{^$UNC_VOL\z}; # root paths must always have a trailing slash, but other paths must not if ( _is_root($path) ) { $path =~ s{/?\z}{/}; } else { $path =~ s{/\z}{}; } bless [ $path, $cpath ], __PACKAGE__; } #pod =construct new #pod #pod $path = Path::Tiny->new("foo/bar"); #pod #pod This is just like C<path>, but with method call overhead. (Why would you #pod do that?) #pod #pod Current API available since 0.001. #pod #pod =cut sub new { shift; path(@_) } #pod =construct cwd #pod #pod $path = Path::Tiny->cwd; # path( Cwd::getcwd ) #pod $path = cwd; # optional export #pod #pod Gives you the absolute path to the current directory as a C<Path::Tiny> object. #pod This is slightly faster than C<< path(".")->absolute >>. #pod #pod C<cwd> may be exported on request and used as a function instead of as a #pod method. #pod #pod Current API available since 0.018. #pod #pod =cut sub cwd { require Cwd; return _path( Cwd::getcwd() ); } #pod =construct rootdir #pod #pod $path = Path::Tiny->rootdir; # / #pod $path = rootdir; # optional export #pod #pod Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if you're too #pod picky for C<path("/")>. #pod #pod C<rootdir> may be exported on request and used as a function instead of as a #pod method. #pod #pod Current API available since 0.018. #pod #pod =cut sub rootdir { _path( File::Spec->rootdir ) } #pod =construct tempfile, tempdir #pod #pod $temp = Path::Tiny->tempfile( @options ); #pod $temp = Path::Tiny->tempdir( @options ); #pod $temp = $dirpath->tempfile( @options ); #pod $temp = $dirpath->tempdir( @options ); #pod $temp = tempfile( @options ); # optional export #pod $temp = tempdir( @options ); # optional export #pod #pod C<tempfile> passes the options to C<< File::Temp->new >> and returns a #pod C<Path::Tiny> object with the file name. The C<TMPDIR> option will be enabled #pod by default, but you can override that by passing C<< TMPDIR => 0 >> along with #pod the options. (If you use an absolute C<TEMPLATE> option, you will want to #pod disable C<TMPDIR>.) #pod #pod The resulting C<File::Temp> object is cached. When the C<Path::Tiny> object is #pod destroyed, the C<File::Temp> object will be as well. #pod #pod C<File::Temp> annoyingly requires you to specify a custom template in slightly #pod different ways depending on which function or method you call, but #pod C<Path::Tiny> lets you ignore that and can take either a leading template or a #pod C<TEMPLATE> option and does the right thing. #pod #pod $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok #pod $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok #pod #pod The tempfile path object will be normalized to have an absolute path, even if #pod created in a relative directory using C<DIR>. If you want it to have #pod the C<realpath> instead, pass a leading options hash like this: #pod #pod $real_temp = tempfile({realpath => 1}, @options); #pod #pod C<tempdir> is just like C<tempfile>, except it calls #pod C<< File::Temp->newdir >> instead. #pod #pod Both C<tempfile> and C<tempdir> may be exported on request and used as #pod functions instead of as methods. #pod #pod The methods can be called on an instances representing a #pod directory. In this case, the directory is used as the base to create the #pod temporary file/directory, setting the C<DIR> option in File::Temp. #pod #pod my $target_dir = path('/to/destination'); #pod my $tempfile = $target_dir->tempfile('foobarXXXXXX'); #pod $tempfile->spew('A lot of data...'); # not atomic #pod $tempfile->move($target_dir->child('foobar')); # hopefully atomic #pod #pod In this case, any value set for option C<DIR> is ignored. #pod #pod B<Note>: for tempfiles, the filehandles from File::Temp are closed and not #pod reused. This is not as secure as using File::Temp handles directly, but is #pod less prone to deadlocks or access problems on some platforms. Think of what #pod C<Path::Tiny> gives you to be just a temporary file B<name> that gets cleaned #pod up. #pod #pod B<Note 2>: if you don't want these cleaned up automatically when the object #pod is destroyed, File::Temp requires different options for directories and #pod files. Use C<< CLEANUP => 0 >> for directories and C<< UNLINK => 0 >> for #pod files. #pod #pod B<Note 3>: Don't lose the temporary object by chaining a method call instead #pod of storing it: #pod #pod my $lost = tempdir()->child("foo"); # tempdir cleaned up right away #pod #pod B<Note 4>: The cached object may be accessed with the L</cached_temp> method. #pod Keeping a reference to, or modifying the cached object may break the #pod behavior documented above and is not supported. Use at your own risk. #pod #pod Current API available since 0.119. #pod #pod =cut sub tempfile { my ( $opts, $maybe_template, $args ) = _parse_file_temp_args(tempfile => @_); # File::Temp->new demands TEMPLATE $args->{TEMPLATE} = $maybe_template->[0] if @$maybe_template; require File::Temp; my $temp = File::Temp->new( TMPDIR => 1, %$args ); close $temp; my $self = $opts->{realpath} ? _path($temp)->realpath : _path($temp)->absolute; $self->[TEMP] = $temp; # keep object alive while we are return $self; } sub tempdir { my ( $opts, $maybe_template, $args ) = _parse_file_temp_args(tempdir => @_); require File::Temp; my $temp = File::Temp->newdir( @$maybe_template, TMPDIR => 1, %$args ); my $self = $opts->{realpath} ? _path($temp)->realpath : _path($temp)->absolute; $self->[TEMP] = $temp; # keep object alive while we are # Some ActiveState Perls for Windows break Cwd in ways that lead # File::Temp to get confused about what path to remove; this # monkey-patches the object with our own view of the absolute path $temp->{REALNAME} = $self->[CANON] if IS_WIN32; return $self; } # normalize the various ways File::Temp does templates sub _parse_file_temp_args { my $called_as = shift; if ( @_ && $_[0] eq 'Path::Tiny' ) { shift } # class method elsif ( @_ && eval{$_[0]->isa('Path::Tiny')} ) { my $dir = shift; if (! $dir->is_dir) { $dir->_throw( $called_as, $dir, "is not a directory object" ); } push @_, DIR => $dir->stringify; # no overriding } my $opts = ( @_ && ref $_[0] eq 'HASH' ) ? shift @_ : {}; $opts = _get_args( $opts, qw/realpath/ ); my $leading_template = ( scalar(@_) % 2 == 1 ? shift(@_) : '' ); my %args = @_; %args = map { uc($_), $args{$_} } keys %args; my @template = ( exists $args{TEMPLATE} ? delete $args{TEMPLATE} : $leading_template ? $leading_template : () ); return ( $opts, \@template, \%args ); } #--------------------------------------------------------------------------# # Private methods #--------------------------------------------------------------------------# sub _splitpath { my ($self) = @_; @{$self}[ VOL, DIR, FILE ] = File::Spec->splitpath( $self->[PATH] ); } sub _resolve_symlinks { my ($self) = @_; my $new = $self; my ( $count, %seen ) = 0; while ( -l $new->[PATH] ) { if ( $seen{ $new->[PATH] }++ ) { $self->_throw( 'readlink', $self->[PATH], "symlink loop detected" ); } if ( ++$count > 100 ) { $self->_throw( 'readlink', $self->[PATH], "maximum symlink depth exceeded" ); } my $resolved = readlink $new->[PATH]; $new->_throw( 'readlink', $new->[PATH] ) unless defined $resolved; $resolved = _path($resolved); $new = $resolved->is_absolute ? $resolved : $new->sibling($resolved); } return $new; } sub _replacment_path { my ($self) = @_; my $unique_suffix = $$ . int( rand( 2**31 ) ); my $temp = _path( $self . $unique_suffix ); # If filename with process+random suffix is too long, use a shorter # version that doesn't preserve the basename. if ( length $temp->basename > 255 ) { $temp = $self->sibling( "temp" . $unique_suffix ); } return $temp; } #--------------------------------------------------------------------------# # Public methods #--------------------------------------------------------------------------# #pod =method absolute #pod #pod $abs = path("foo/bar")->absolute; #pod $abs = path("foo/bar")->absolute("/tmp"); #pod #pod Returns a new C<Path::Tiny> object with an absolute path (or itself if already #pod absolute). If no argument is given, the current directory is used as the #pod absolute base path. If an argument is given, it will be converted to an #pod absolute path (if it is not already) and used as the absolute base path. #pod #pod This will not resolve upward directories ("foo/../bar") unless C<canonpath> #pod in L<File::Spec> would normally do so on your platform. If you need them #pod resolved, you must call the more expensive C<realpath> method instead. #pod #pod On Windows, an absolute path without a volume component will have it added #pod based on the current drive. #pod #pod Current API available since 0.101. #pod #pod =cut sub absolute { my ( $self, $base ) = @_; # absolute paths handled differently by OS if (IS_WIN32) { return $self if length $self->volume; # add missing volume if ( $self->is_absolute ) { require Cwd; # use Win32::GetCwd not Cwd::getdcwd because we're sure # to have the former but not necessarily the latter my ($drv) = Win32::GetCwd() =~ /^($DRV_VOL | $UNC_VOL)/x; return _path( $drv . $self->[PATH] ); } } else { return $self if $self->is_absolute; } # no base means use current directory as base require Cwd; return _path( Cwd::getcwd(), $_[0]->[PATH] ) unless defined $base; # relative base should be made absolute; we check is_absolute rather # than unconditionally make base absolute so that "/foo" doesn't become # "C:/foo" on Windows. $base = _path($base); return _path( ( $base->is_absolute ? $base : $base->absolute ), $_[0]->[PATH] ); } #pod =method append, append_raw, append_utf8 #pod #pod path("foo.txt")->append(@data); #pod path("foo.txt")->append(\@data); #pod path("foo.txt")->append({binmode => ":raw"}, @data); #pod path("foo.txt")->append_raw(@data); #pod path("foo.txt")->append_utf8(@data); #pod #pod Appends data to a file. The file is locked with C<flock> prior to writing #pod and closed afterwards. An optional hash reference may be used to pass #pod options. Valid options are: #pod #pod =for :list #pod * C<binmode>: passed to C<binmode()> on the handle used for writing. #pod * C<truncate>: truncates the file after locking and before appending #pod #pod The C<truncate> option is a way to replace the contents of a file #pod B<in place>, unlike L</spew> which writes to a temporary file and then #pod replaces the original (if it exists). #pod #pod C<append_raw> is like C<append> with a C<binmode> of C<:unix> for a fast, #pod unbuffered, raw write. #pod #pod C<append_utf8> is like C<append> with an unbuffered C<binmode> #pod C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with #pod L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, an #pod unbuffered, raw append will be done instead on the data encoded with #pod C<Unicode::UTF8>. #pod #pod Current API available since 0.060. #pod #pod =cut sub append { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; my $mode = $args->{truncate} ? ">" : ">>"; my $fh = $self->filehandle( { locked => 1 }, $mode, $binmode ); print( {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data ) or self->_throw('print'); close $fh or $self->_throw('close'); } sub append_raw { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); $args->{binmode} = ':unix'; append( $self, $args, @data ); } sub append_utf8 { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode truncate/ ); if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { $args->{binmode} = ":unix"; append( $self, $args, map { Unicode::UTF8::encode_utf8($_) } @data ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $args->{binmode} = ":unix:utf8_strict"; append( $self, $args, @data ); } else { $args->{binmode} = ":unix:encoding(UTF-8)"; append( $self, $args, @data ); } } #pod =method assert #pod #pod $path = path("foo.txt")->assert( sub { $_->exists } ); #pod #pod Returns the invocant after asserting that a code reference argument returns #pod true. When the assertion code reference runs, it will have the invocant #pod object in the C<$_> variable. If it returns false, an exception will be #pod thrown. The assertion code reference may also throw its own exception. #pod #pod If no assertion is provided, the invocant is returned without error. #pod #pod Current API available since 0.062. #pod #pod =cut sub assert { my ( $self, $assertion ) = @_; return $self unless $assertion; if ( ref $assertion eq 'CODE' ) { local $_ = $self; $assertion->() or Path::Tiny::Error->throw( "assert", $self->[PATH], "failed assertion" ); } else { Carp::croak("argument to assert must be a code reference argument"); } return $self; } #pod =method basename #pod #pod $name = path("foo/bar.txt")->basename; # bar.txt #pod $name = path("foo.txt")->basename('.txt'); # foo #pod $name = path("foo.txt")->basename(qr/.txt/); # foo #pod $name = path("foo.txt")->basename(@suffixes); #pod #pod Returns the file portion or last directory portion of a path. #pod #pod Given a list of suffixes as strings or regular expressions, any that match at #pod the end of the file portion or last directory portion will be removed before #pod the result is returned. #pod #pod Current API available since 0.054. #pod #pod =cut sub basename { my ( $self, @suffixes ) = @_; $self->_splitpath unless defined $self->[FILE]; my $file = $self->[FILE]; for my $s (@suffixes) { my $re = ref($s) eq 'Regexp' ? qr/$s\z/ : qr/\Q$s\E\z/; last if $file =~ s/$re//; } return $file; } #pod =method canonpath #pod #pod $canonical = path("foo/bar")->canonpath; # foo\bar on Windows #pod #pod Returns a string with the canonical format of the path name for #pod the platform. In particular, this means directory separators #pod will be C<\> on Windows. #pod #pod Current API available since 0.001. #pod #pod =cut sub canonpath { $_[0]->[CANON] } #pod =method cached_temp #pod #pod Returns the cached C<File::Temp> or C<File::Temp::Dir> object if the #pod C<Path::Tiny> object was created with C</tempfile> or C</tempdir>. #pod If there is no such object, this method throws. #pod #pod B<WARNING>: Keeping a reference to, or modifying the cached object may #pod break the behavior documented for temporary files and directories created #pod with C<Path::Tiny> and is not supported. Use at your own risk. #pod #pod Current API available since 0.101. #pod #pod =cut sub cached_temp { my $self = shift; $self->_throw( "cached_temp", $self, "has no cached File::Temp object" ) unless defined $self->[TEMP]; return $self->[TEMP]; } #pod =method child #pod #pod $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" #pod $file = path("/tmp")->child(@parts); #pod #pod Returns a new C<Path::Tiny> object relative to the original. Works #pod like C<catfile> or C<catdir> from File::Spec, but without caring about #pod file or directories. #pod #pod B<WARNING>: because the argument could contain C<..> or refer to symlinks, #pod there is no guarantee that the new path refers to an actual descendent of #pod the original. If this is important to you, transform parent and child with #pod L</realpath> and check them with L</subsumes>. #pod #pod Current API available since 0.001. #pod #pod =cut sub child { my ( $self, @parts ) = @_; return _path( $self->[PATH], @parts ); } #pod =method children #pod #pod @paths = path("/tmp")->children; #pod @paths = path("/tmp")->children( qr/\.txt\z/ ); #pod #pod Returns a list of C<Path::Tiny> objects for all files and directories #pod within a directory. Excludes "." and ".." automatically. #pod #pod If an optional C<qr//> argument is provided, it only returns objects for child #pod names that match the given regular expression. Only the base name is used #pod for matching: #pod #pod @paths = path("/tmp")->children( qr/^foo/ ); #pod # matches children like the glob foo* #pod #pod Current API available since 0.028. #pod #pod =cut sub children { my ( $self, $filter ) = @_; my $dh; opendir $dh, $self->[PATH] or $self->_throw('opendir'); my @children = readdir $dh; closedir $dh or $self->_throw('closedir'); if ( not defined $filter ) { @children = grep { $_ ne '.' && $_ ne '..' } @children; } elsif ( $filter && ref($filter) eq 'Regexp' ) { @children = grep { $_ ne '.' && $_ ne '..' && $_ =~ $filter } @children; } else { Carp::croak("Invalid argument '$filter' for children()"); } return map { _path( $self->[PATH], $_ ) } @children; } #pod =method chmod #pod #pod path("foo.txt")->chmod(0777); #pod path("foo.txt")->chmod("0755"); #pod path("foo.txt")->chmod("go-w"); #pod path("foo.txt")->chmod("a=r,u+wx"); #pod #pod Sets file or directory permissions. The argument can be a numeric mode, a #pod octal string beginning with a "0" or a limited subset of the symbolic mode use #pod by F</bin/chmod>. #pod #pod The symbolic mode must be a comma-delimited list of mode clauses. Clauses must #pod match C<< qr/\A([augo]+)([=+-])([rwx]+)\z/ >>, which defines "who", "op" and #pod "perms" parameters for each clause. Unlike F</bin/chmod>, all three parameters #pod are required for each clause, multiple ops are not allowed and permissions #pod C<stugoX> are not supported. (See L<File::chmod> for more complex needs.) #pod #pod Current API available since 0.053. #pod #pod =cut sub chmod { my ( $self, $new_mode ) = @_; my $mode; if ( $new_mode =~ /\d/ ) { $mode = ( $new_mode =~ /^0/ ? oct($new_mode) : $new_mode ); } elsif ( $new_mode =~ /[=+-]/ ) { $mode = _symbolic_chmod( $self->stat->mode & 07777, $new_mode ); ## no critic } else { Carp::croak("Invalid mode argument '$new_mode' for chmod()"); } CORE::chmod( $mode, $self->[PATH] ) or $self->_throw("chmod"); return 1; } #pod =method copy #pod #pod path("/tmp/foo.txt")->copy("/tmp/bar.txt"); #pod #pod Copies the current path to the given destination using L<File::Copy>'s #pod C<copy> function. Upon success, returns the C<Path::Tiny> object for the #pod newly copied file. #pod #pod Current API available since 0.070. #pod #pod =cut # XXX do recursively for directories? sub copy { my ( $self, $dest ) = @_; require File::Copy; File::Copy::copy( $self->[PATH], $dest ) or Carp::croak("copy failed for $self to $dest: $!"); return -d $dest ? _path( $dest, $self->basename ) : _path($dest); } #pod =method digest #pod #pod $obj = path("/tmp/foo.txt")->digest; # SHA-256 #pod $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected #pod $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); #pod #pod Returns a hexadecimal digest for a file. An optional hash reference of options may #pod be given. The only option is C<chunk_size>. If C<chunk_size> is given, that many #pod bytes will be read at a time. If not provided, the entire file will be slurped #pod into memory to compute the digest. #pod #pod Any subsequent arguments are passed to the constructor for L<Digest> to select #pod an algorithm. If no arguments are given, the default is SHA-256. #pod #pod Current API available since 0.056. #pod #pod =cut sub digest { my ( $self, @opts ) = @_; my $args = ( @opts && ref $opts[0] eq 'HASH' ) ? shift @opts : {}; $args = _get_args( $args, qw/chunk_size/ ); unshift @opts, 'SHA-256' unless @opts; require Digest; my $digest = Digest->new(@opts); if ( $args->{chunk_size} ) { my $fh = $self->filehandle( { locked => 1 }, "<", ":unix" ); my $buf; while (!eof($fh)) { my $rc = read $fh, $buf, $args->{chunk_size}; $self->_throw('read') unless defined $rc; $digest->add($buf); } } else { $digest->add( $self->slurp_raw ); } return $digest->hexdigest; } #pod =method dirname (deprecated) #pod #pod $name = path("/tmp/foo.txt")->dirname; # "/tmp/" #pod #pod Returns the directory portion you would get from calling #pod C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a path without a #pod parent directory portion. Because L<File::Spec> is inconsistent, the result #pod might or might not have a trailing slash. Because of this, this method is #pod B<deprecated>. #pod #pod A better, more consistently approach is likely C<< $path->parent->stringify >>, #pod which will not have a trailing slash except for a root directory. #pod #pod Deprecated in 0.056. #pod #pod =cut sub dirname { my ($self) = @_; $self->_splitpath unless defined $self->[DIR]; return length $self->[DIR] ? $self->[DIR] : "."; } #pod =method edit, edit_raw, edit_utf8 #pod #pod path("foo.txt")->edit( \&callback, $options ); #pod path("foo.txt")->edit_utf8( \&callback ); #pod path("foo.txt")->edit_raw( \&callback ); #pod #pod These are convenience methods that allow "editing" a file using a single #pod callback argument. They slurp the file using C<slurp>, place the contents #pod inside a localized C<$_> variable, call the callback function (without #pod arguments), and then write C<$_> (presumably mutated) back to the #pod file with C<spew>. #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<binmode>, which is passed to C<slurp> and C<spew>. #pod #pod C<edit_utf8> and C<edit_raw> act like their respective C<slurp_*> and #pod C<spew_*> methods. #pod #pod Current API available since 0.077. #pod #pod =cut sub edit { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/binmode/ ); Carp::croak("Callback for edit() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; local $_ = $self->slurp( exists( $args->{binmode} ) ? { binmode => $args->{binmode} } : () ); $cb->(); $self->spew( $args, $_ ); return; } # this is done long-hand to benefit from slurp_utf8 optimizations sub edit_utf8 { my ( $self, $cb ) = @_; Carp::croak("Callback for edit_utf8() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; local $_ = $self->slurp_utf8; $cb->(); $self->spew_utf8($_); return; } sub edit_raw { $_[2] = { binmode => ":unix" }; goto &edit } #pod =method edit_lines, edit_lines_utf8, edit_lines_raw #pod #pod path("foo.txt")->edit_lines( \&callback, $options ); #pod path("foo.txt")->edit_lines_utf8( \&callback ); #pod path("foo.txt")->edit_lines_raw( \&callback ); #pod #pod These are convenience methods that allow "editing" a file's lines using a #pod single callback argument. They iterate over the file: for each line, the #pod line is put into a localized C<$_> variable, the callback function is #pod executed (without arguments) and then C<$_> is written to a temporary file. #pod When iteration is finished, the temporary file is atomically renamed over #pod the original. #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<binmode>, which is passed to the method that open handles for reading and #pod writing. #pod #pod C<edit_lines_raw> is like C<edit_lines> with a buffered C<binmode> of #pod C<:raw>. #pod #pod C<edit_lines_utf8> is like C<edit_lines> with a buffered C<binmode> #pod C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with #pod L<PerlIO::utf8_strict>). #pod #pod Current API available since 0.077. #pod #pod =cut sub edit_lines { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/binmode/ ); Carp::croak("Callback for edit_lines() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; my $binmode = $args->{binmode}; # get default binmode from caller's lexical scope (see "perldoc open") $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; # writing needs to follow the link and create the tempfile in the same # dir for later atomic rename my $resolved_path = $self->_resolve_symlinks; my $temp = $resolved_path->_replacment_path; my $temp_fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode ); my $in_fh = $self->filehandle( { locked => 1 }, '<', $binmode ); local $_; while (! eof($in_fh) ) { defined( $_ = readline($in_fh) ) or $self->_throw('readline'); $cb->(); $temp_fh->print($_) or self->_throw('print', $temp); } close $temp_fh or $self->_throw( 'close', $temp ); close $in_fh or $self->_throw('close'); return $temp->move($resolved_path); } sub edit_lines_raw { $_[2] = { binmode => ":raw" }; goto &edit_lines } sub edit_lines_utf8 { if ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $_[2] = { binmode => ":raw:utf8_strict" }; } else { $_[2] = { binmode => ":raw:encoding(UTF-8)" }; } goto &edit_lines; } #pod =method exists, is_file, is_dir #pod #pod if ( path("/tmp")->exists ) { ... } # -e #pod if ( path("/tmp")->is_dir ) { ... } # -d #pod if ( path("/tmp")->is_file ) { ... } # -e && ! -d #pod #pod Implements file test operations, this means the file or directory actually has #pod to exist on the filesystem. Until then, it's just a path. #pod #pod B<Note>: C<is_file> is not C<-f> because C<-f> is not the opposite of C<-d>. #pod C<-f> means "plain file", excluding symlinks, devices, etc. that often can be #pod read just like files. #pod #pod Use C<-f> instead if you really mean to check for a plain file. #pod #pod Current API available since 0.053. #pod #pod =cut sub exists { -e $_[0]->[PATH] } sub is_file { -e $_[0]->[PATH] && !-d _ } sub is_dir { -d $_[0]->[PATH] } #pod =method filehandle #pod #pod $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); #pod $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); #pod $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); #pod #pod Returns an open file handle. The C<$mode> argument must be a Perl-style #pod read/write mode string ("<" ,">", ">>", etc.). If a C<$binmode> #pod is given, it is set during the C<open> call. #pod #pod An optional hash reference may be used to pass options. #pod #pod The C<locked> option governs file locking; if true, handles opened for writing, #pod appending or read-write are locked with C<LOCK_EX>; otherwise, they are #pod locked with C<LOCK_SH>. When using C<locked>, ">" or "+>" modes will delay #pod truncation until after the lock is acquired. #pod #pod The C<exclusive> option causes the open() call to fail if the file already #pod exists. This corresponds to the O_EXCL flag to sysopen / open(2). #pod C<exclusive> implies C<locked> and will set it for you if you forget it. #pod #pod See C<openr>, C<openw>, C<openrw>, and C<opena> for sugar. #pod #pod Current API available since 0.066. #pod #pod =cut # Note: must put binmode on open line, not subsequent binmode() call, so things # like ":unix" actually stop perlio/crlf from being added sub filehandle { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked exclusive/ ); $args->{locked} = 1 if $args->{exclusive}; my ( $opentype, $binmode ) = @args; $opentype = "<" unless defined $opentype; Carp::croak("Invalid file mode '$opentype'") unless grep { $opentype eq $_ } qw/< +< > +> >> +>>/; $binmode = ( ( caller(0) )[10] || {} )->{ 'open' . substr( $opentype, -1, 1 ) } unless defined $binmode; $binmode = "" unless defined $binmode; my ( $fh, $lock, $trunc ); if ( $HAS_FLOCK && $args->{locked} && !$ENV{PERL_PATH_TINY_NO_FLOCK} ) { require Fcntl; # truncating file modes shouldn't truncate until lock acquired if ( grep { $opentype eq $_ } qw( > +> ) ) { # sysopen in write mode without truncation my $flags = $opentype eq ">" ? Fcntl::O_WRONLY() : Fcntl::O_RDWR(); $flags |= Fcntl::O_CREAT(); $flags |= Fcntl::O_EXCL() if $args->{exclusive}; sysopen( $fh, $self->[PATH], $flags ) or $self->_throw("sysopen"); # fix up the binmode since sysopen() can't specify layers like # open() and binmode() can't start with just :unix like open() if ( $binmode =~ s/^:unix// ) { # eliminate pseudo-layers binmode( $fh, ":raw" ) or $self->_throw("binmode (:raw)"); # strip off real layers until only :unix is left while ( 1 < ( my $layers =()= PerlIO::get_layers( $fh, output => 1 ) ) ) { binmode( $fh, ":pop" ) or $self->_throw("binmode (:pop)"); } } # apply any remaining binmode layers if ( length $binmode ) { binmode( $fh, $binmode ) or $self->_throw("binmode ($binmode)"); } # ask for lock and truncation $lock = Fcntl::LOCK_EX(); $trunc = 1; } elsif ( $^O eq 'aix' && $opentype eq "<" ) { # AIX can only lock write handles, so upgrade to RW and LOCK_EX if # the file is writable; otherwise give up on locking. N.B. # checking -w before open to determine the open mode is an # unavoidable race condition if ( -w $self->[PATH] ) { $opentype = "+<"; $lock = Fcntl::LOCK_EX(); } } else { $lock = $opentype eq "<" ? Fcntl::LOCK_SH() : Fcntl::LOCK_EX(); } } unless ($fh) { my $mode = $opentype . $binmode; open $fh, $mode, $self->[PATH] or $self->_throw("open ($mode)"); } do { flock( $fh, $lock ) or $self->_throw("flock ($lock)") } if $lock; do { truncate( $fh, 0 ) or $self->_throw("truncate") } if $trunc; return $fh; } #pod =method has_same_bytes #pod #pod if ( path("foo.txt")->has_same_bytes("bar.txt") ) { #pod # ... #pod } #pod #pod This method returns true if both the invocant and the argument can be opened as #pod file handles and the handles contain the same bytes. It returns false if their #pod contents differ. If either can't be opened as a file (e.g. a directory or #pod non-existent file), the method throws an exception. If both can be opened and #pod both have the same C<realpath>, the method returns true without scanning any #pod data. #pod #pod Current API available since 0.125. #pod #pod =cut sub has_same_bytes { my ($self, $other_path) = @_; my $other = _path($other_path); my $fh1 = $self->openr_raw({ locked => 1 }); my $fh2 = $other->openr_raw({ locked => 1 }); # check for directories if (-d $fh1) { $self->_throw('has_same_bytes', $self->[PATH], "directory not allowed"); } if (-d $fh2) { $self->_throw('has_same_bytes', $other->[PATH], "directory not allowed"); } # Now that handles are open, we know the inputs are readable files that # exist, so it's safe to compare via realpath if ($self->realpath eq $other->realpath) { return 1 } # result is 0 for equal, 1 for unequal, -1 for error require File::Compare; my $res = File::Compare::compare($fh1, $fh2, 65536); if ($res < 0) { $self->_throw('has_same_bytes') } return $res == 0; } #pod =method is_absolute, is_relative #pod #pod if ( path("/tmp")->is_absolute ) { ... } #pod if ( path("/tmp")->is_relative ) { ... } #pod #pod Booleans for whether the path appears absolute or relative. #pod #pod Current API available since 0.001. #pod #pod =cut sub is_absolute { substr( $_[0]->dirname, 0, 1 ) eq '/' } sub is_relative { substr( $_[0]->dirname, 0, 1 ) ne '/' } #pod =method is_rootdir #pod #pod while ( ! $path->is_rootdir ) { #pod $path = $path->parent; #pod ... #pod } #pod #pod Boolean for whether the path is the root directory of the volume. I.e. the #pod C<dirname> is C<q[/]> and the C<basename> is C<q[]>. #pod #pod This works even on C<MSWin32> with drives and UNC volumes: #pod #pod path("C:/")->is_rootdir; # true #pod path("//server/share/")->is_rootdir; #true #pod #pod Current API available since 0.038. #pod #pod =cut sub is_rootdir { my ($self) = @_; $self->_splitpath unless defined $self->[DIR]; return $self->[DIR] eq '/' && $self->[FILE] eq ''; } #pod =method iterator #pod #pod $iter = path("/tmp")->iterator( \%options ); #pod #pod Returns a code reference that walks a directory lazily. Each invocation #pod returns a C<Path::Tiny> object or undef when the iterator is exhausted. #pod #pod $iter = path("/tmp")->iterator; #pod while ( $path = $iter->() ) { #pod ... #pod } #pod #pod The current and parent directory entries ("." and "..") will not #pod be included. #pod #pod If the C<recurse> option is true, the iterator will walk the directory #pod recursively, breadth-first. If the C<follow_symlinks> option is also true, #pod directory links will be followed recursively. There is no protection against #pod loops when following links. If a directory is not readable, it will not be #pod followed. #pod #pod The default is the same as: #pod #pod $iter = path("/tmp")->iterator( { #pod recurse => 0, #pod follow_symlinks => 0, #pod } ); #pod #pod For a more powerful, recursive iterator with built-in loop avoidance, see #pod L<Path::Iterator::Rule>. #pod #pod See also L</visit>. #pod #pod Current API available since 0.016. #pod #pod =cut sub iterator { my $self = shift; my $args = _get_args( shift, qw/recurse follow_symlinks/ ); my @dirs = $self; my $current; return sub { my $next; while (@dirs) { if ( ref $dirs[0] eq 'Path::Tiny' ) { if ( !-r $dirs[0] ) { # Directory is missing or not readable, so skip it. There # is still a race condition possible between the check and # the opendir, but we can't easily differentiate between # error cases that are OK to skip and those that we want # to be exceptions, so we live with the race and let opendir # be fatal. shift @dirs and next; } $current = $dirs[0]; my $dh; opendir( $dh, $current->[PATH] ) or $self->_throw( 'opendir', $current->[PATH] ); $dirs[0] = $dh; if ( -l $current->[PATH] && !$args->{follow_symlinks} ) { # Symlink attack! It was a real dir, but is now a symlink! # N.B. we check *after* opendir so the attacker has to win # two races: replace dir with symlink before opendir and # replace symlink with dir before -l check above shift @dirs and next; } } while ( defined( $next = readdir $dirs[0] ) ) { next if $next eq '.' || $next eq '..'; my $path = $current->child($next); push @dirs, $path if $args->{recurse} && -d $path && !( !$args->{follow_symlinks} && -l $path ); return $path; } shift @dirs; } return; }; } #pod =method lines, lines_raw, lines_utf8 #pod #pod @contents = path("/tmp/foo.txt")->lines; #pod @contents = path("/tmp/foo.txt")->lines(\%options); #pod @contents = path("/tmp/foo.txt")->lines_raw; #pod @contents = path("/tmp/foo.txt")->lines_utf8; #pod #pod @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); #pod #pod Returns a list of lines from a file. Optionally takes a hash-reference of #pod options. Valid options are C<binmode>, C<count> and C<chomp>. #pod #pod If C<binmode> is provided, it will be set on the handle prior to reading. #pod #pod If a positive C<count> is provided, that many lines will be returned from the #pod start of the file. If a negative C<count> is provided, the entire file will be #pod read, but only C<abs(count)> will be kept and returned. If C<abs(count)> #pod exceeds the number of lines in the file, all lines will be returned. #pod #pod If C<chomp> is set, any end-of-line character sequences (C<CR>, C<CRLF>, or #pod C<LF>) will be removed from the lines returned. #pod #pod Because the return is a list, C<lines> in scalar context will return the number #pod of lines (and throw away the data). #pod #pod $number_of_lines = path("/tmp/foo.txt")->lines; #pod #pod C<lines_raw> is like C<lines> with a C<binmode> of C<:raw>. We use C<:raw> #pod instead of C<:unix> so PerlIO buffering can manage reading by line. #pod #pod C<lines_utf8> is like C<lines> with a C<binmode> of C<:raw:encoding(UTF-8)> #pod (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> #pod 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the #pod lines will be split. This is actually faster than relying on #pod IO layers, though a bit memory intensive. If memory use is a #pod concern, consider C<openr_utf8> and iterating directly on the handle. #pod #pod Current API available since 0.065. #pod #pod =cut sub lines { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open<'} unless defined $binmode; my $fh = $self->filehandle( { locked => 1 }, "<", $binmode ); my $chomp = $args->{chomp}; # XXX more efficient to read @lines then chomp(@lines) vs map? if ( $args->{count} ) { my ( $counter, $mod, @result ) = ( 0, abs( $args->{count} ) ); my $line; while ( !eof($fh) ) { defined( $line = readline($fh) ) or $self->_throw('readline'); $line =~ s/(?:\x{0d}?\x{0a}|\x{0d})\z// if $chomp; $result[ $counter++ ] = $line; # for positive count, terminate after right number of lines last if $counter == $args->{count}; # for negative count, eventually wrap around in the result array $counter %= $mod; } # reorder results if full and wrapped somewhere in the middle splice( @result, 0, 0, splice( @result, $counter ) ) if @result == $mod && $counter % $mod; return @result; } elsif ($chomp) { local $!; my @lines = map { s/(?:\x{0d}?\x{0a}|\x{0d})\z//; $_ } <$fh>; ## no critic $self->_throw('readline') if $!; return @lines; } else { if ( wantarray ) { local $!; my @lines = <$fh>; $self->_throw('readline') if $!; return @lines; } else { local $!; my $count =()= <$fh>; $self->_throw('readline') if $!; return $count; } } } sub lines_raw { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); if ( $args->{chomp} && !$args->{count} ) { return split /\n/, slurp_raw($self); ## no critic } else { $args->{binmode} = ":raw"; return lines( $self, $args ); } } my $CRLF = qr/(?:\x{0d}?\x{0a}|\x{0d})/; sub lines_utf8 { my $self = shift; my $args = _get_args( shift, qw/binmode chomp count/ ); if ( ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) && $args->{chomp} && !$args->{count} ) { my $slurp = slurp_utf8($self); $slurp =~ s/$CRLF\z//; # like chomp, but full CR?LF|CR return split $CRLF, $slurp, -1; ## no critic } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $args->{binmode} = ":raw:utf8_strict"; return lines( $self, $args ); } else { $args->{binmode} = ":raw:encoding(UTF-8)"; return lines( $self, $args ); } } #pod =method mkdir #pod #pod path("foo/bar/baz")->mkdir; #pod path("foo/bar/baz")->mkdir( \%options ); #pod #pod Like calling C<make_path> from L<File::Path>. An optional hash reference #pod is passed through to C<make_path>. Errors will be trapped and an exception #pod thrown. Returns the the path object to facilitate chaining. #pod #pod B<NOTE>: unlike Perl's builtin C<mkdir>, this will create intermediate paths #pod similar to the Unix C<mkdir -p> command. It will not error if applied to an #pod existing directory. #pod #pod Current API available since 0.125. #pod #pod =cut sub mkdir { my ( $self, $args ) = @_; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; require File::Path; my @dirs; my $ok = eval { File::Path::make_path( $self->[PATH], $args ); 1; }; if (!$ok) { $self->_throw('mkdir', $self->[PATH], "error creating path: $@"); } if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; $self->_throw('mkdir', $file, $message); } return $self; } #pod =method mkpath (deprecated) #pod #pod Like calling C<mkdir>, but returns the list of directories created or an empty list if #pod the directories already exist, just like C<make_path>. #pod #pod Deprecated in 0.125. #pod #pod =cut sub mkpath { my ( $self, $args ) = @_; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; require File::Path; my @dirs = File::Path::make_path( $self->[PATH], $args ); if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; Carp::croak("mkpath failed for $file: $message"); } return @dirs; } #pod =method move #pod #pod path("foo.txt")->move("bar.txt"); #pod #pod Moves the current path to the given destination using L<File::Copy>'s #pod C<move> function. Upon success, returns the C<Path::Tiny> object for the #pod newly moved file. #pod #pod If the destination already exists and is a directory, and the source is not a #pod directory, then the source file will be renamed into the directory #pod specified by the destination. #pod #pod If possible, move() will simply rename the file. Otherwise, it #pod copies the file to the new location and deletes the original. If an #pod error occurs during this copy-and-delete process, you may be left #pod with a (possibly partial) copy of the file under the destination #pod name. #pod #pod Current API available since 0.124. Prior versions used Perl's #pod -built-in (and less robust) L<rename|perlfunc/rename> function #pod and did not return an object. #pod #pod =cut sub move { my ( $self, $dest ) = @_; require File::Copy; File::Copy::move( $self->[PATH], $dest ) or $self->_throw( 'move', $self->[PATH] . "' -> '$dest" ); return -d $dest ? _path( $dest, $self->basename ) : _path($dest); } #pod =method openr, openw, openrw, opena #pod #pod $fh = path("foo.txt")->openr($binmode); # read #pod $fh = path("foo.txt")->openr_raw; #pod $fh = path("foo.txt")->openr_utf8; #pod #pod $fh = path("foo.txt")->openw($binmode); # write #pod $fh = path("foo.txt")->openw_raw; #pod $fh = path("foo.txt")->openw_utf8; #pod #pod $fh = path("foo.txt")->opena($binmode); # append #pod $fh = path("foo.txt")->opena_raw; #pod $fh = path("foo.txt")->opena_utf8; #pod #pod $fh = path("foo.txt")->openrw($binmode); # read/write #pod $fh = path("foo.txt")->openrw_raw; #pod $fh = path("foo.txt")->openrw_utf8; #pod #pod Returns a file handle opened in the specified mode. The C<openr> style methods #pod take a single C<binmode> argument. All of the C<open*> methods have #pod C<open*_raw> and C<open*_utf8> equivalents that use buffered I/O layers C<:raw> #pod and C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with #pod L<PerlIO::utf8_strict>). #pod #pod An optional hash reference may be used to pass options. The only option is #pod C<locked>. If true, handles opened for writing, appending or read-write are #pod locked with C<LOCK_EX>; otherwise, they are locked for C<LOCK_SH>. #pod #pod $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); #pod #pod See L</filehandle> for more on locking. #pod #pod Current API available since 0.011. #pod #pod =cut # map method names to corresponding open mode my %opens = ( opena => ">>", openr => "<", openw => ">", openrw => "+<" ); while ( my ( $k, $v ) = each %opens ) { no strict 'refs'; # must check for lexical IO mode hint *{$k} = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); my ($binmode) = @args; $binmode = ( ( caller(0) )[10] || {} )->{ 'open' . substr( $v, -1, 1 ) } unless defined $binmode; $self->filehandle( $args, $v, $binmode ); }; *{ $k . "_raw" } = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); $self->filehandle( $args, $v, ":raw" ); }; *{ $k . "_utf8" } = sub { my ( $self, @args ) = @_; my $args = ( @args && ref $args[0] eq 'HASH' ) ? shift @args : {}; $args = _get_args( $args, qw/locked/ ); my $layer; if ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $layer = ":raw:utf8_strict"; } else { $layer = ":raw:encoding(UTF-8)"; } $self->filehandle( $args, $v, $layer ); }; } #pod =method parent #pod #pod $parent = path("foo/bar/baz")->parent; # foo/bar #pod $parent = path("foo/wibble.txt")->parent; # foo #pod #pod $parent = path("foo/bar/baz")->parent(2); # foo #pod #pod Returns a C<Path::Tiny> object corresponding to the parent directory of the #pod original directory or file. An optional positive integer argument is the number #pod of parent directories upwards to return. C<parent> by itself is equivalent to #pod C<parent(1)>. #pod #pod Current API available since 0.014. #pod #pod =cut # XXX this is ugly and coverage is incomplete. I think it's there for windows # so need to check coverage there and compare sub parent { my ( $self, $level ) = @_; $level = 1 unless defined $level && $level > 0; $self->_splitpath unless defined $self->[FILE]; my $parent; if ( length $self->[FILE] ) { if ( $self->[FILE] eq '.' || $self->[FILE] eq ".." ) { $parent = _path( $self->[PATH] . "/.." ); } else { $parent = _path( _non_empty( $self->[VOL] . $self->[DIR] ) ); } } elsif ( length $self->[DIR] ) { # because of symlinks, any internal updir requires us to # just add more updirs at the end if ( $self->[DIR] =~ m{(?:^\.\./|/\.\./|/\.\.\z)} ) { $parent = _path( $self->[VOL] . $self->[DIR] . "/.." ); } else { ( my $dir = $self->[DIR] ) =~ s{/[^\/]+/\z}{/}; $parent = _path( $self->[VOL] . $dir ); } } else { $parent = _path( _non_empty( $self->[VOL] ) ); } return $level == 1 ? $parent : $parent->parent( $level - 1 ); } sub _non_empty { my ($string) = shift; return ( ( defined($string) && length($string) ) ? $string : "." ); } #pod =method realpath #pod #pod $real = path("/baz/foo/../bar")->realpath; #pod $real = path("foo/../bar")->realpath; #pod #pod Returns a new C<Path::Tiny> object with all symbolic links and upward directory #pod parts resolved using L<Cwd>'s C<realpath>. Compared to C<absolute>, this is #pod more expensive as it must actually consult the filesystem. #pod #pod If the parent path can't be resolved (e.g. if it includes directories that #pod don't exist), an exception will be thrown: #pod #pod $real = path("doesnt_exist/foo")->realpath; # dies #pod #pod However, if the parent path exists and only the last component (e.g. filename) #pod doesn't exist, the realpath will be the realpath of the parent plus the #pod non-existent last component: #pod #pod $real = path("./aasdlfasdlf")->realpath; # works #pod #pod The underlying L<Cwd> module usually worked this way on Unix, but died on #pod Windows (and some Unixes) if the full path didn't exist. As of version 0.064, #pod it's safe to use anywhere. #pod #pod Current API available since 0.001. #pod #pod =cut # Win32 and some Unixes need parent path resolved separately so realpath # doesn't throw an error resolving non-existent basename sub realpath { my $self = shift; $self = $self->_resolve_symlinks; require Cwd; $self->_splitpath if !defined $self->[FILE]; my $check_parent = length $self->[FILE] && $self->[FILE] ne '.' && $self->[FILE] ne '..'; my $realpath = eval { # pure-perl Cwd can carp local $SIG{__WARN__} = sub { }; Cwd::realpath( $check_parent ? $self->parent->[PATH] : $self->[PATH] ); }; # parent realpath must exist; not all Cwd::realpath will error if it doesn't $self->_throw("resolving realpath") unless defined $realpath && length $realpath && -e $realpath; return ( $check_parent ? _path( $realpath, $self->[FILE] ) : _path($realpath) ); } #pod =method relative #pod #pod $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar #pod #pod Returns a C<Path::Tiny> object with a path relative to a new base path #pod given as an argument. If no argument is given, the current directory will #pod be used as the new base path. #pod #pod If either path is already relative, it will be made absolute based on the #pod current directly before determining the new relative path. #pod #pod The algorithm is roughly as follows: #pod #pod =for :list #pod * If the original and new base path are on different volumes, an exception #pod will be thrown. #pod * If the original and new base are identical, the relative path is C<".">. #pod * If the new base subsumes the original, the relative path is the original #pod path with the new base chopped off the front #pod * If the new base does not subsume the original, a common prefix path is #pod determined (possibly the root directory) and the relative path will #pod consist of updirs (C<"..">) to reach the common prefix, followed by the #pod original path less the common prefix. #pod #pod Unlike C<File::Spec::abs2rel>, in the last case above, the calculation based #pod on a common prefix takes into account symlinks that could affect the updir #pod process. Given an original path "/A/B" and a new base "/A/C", #pod (where "A", "B" and "C" could each have multiple path components): #pod #pod =for :list #pod * Symlinks in "A" don't change the result unless the last component of A is #pod a symlink and the first component of "C" is an updir. #pod * Symlinks in "B" don't change the result and will exist in the result as #pod given. #pod * Symlinks and updirs in "C" must be resolved to actual paths, taking into #pod account the possibility that not all path components might exist on the #pod filesystem. #pod #pod Current API available since 0.001. New algorithm (that accounts for #pod symlinks) available since 0.079. #pod #pod =cut sub relative { my ( $self, $base ) = @_; $base = _path( defined $base && length $base ? $base : '.' ); # relative paths must be converted to absolute first $self = $self->absolute if $self->is_relative; $base = $base->absolute if $base->is_relative; # normalize volumes if they exist $self = $self->absolute if !length $self->volume && length $base->volume; $base = $base->absolute if length $self->volume && !length $base->volume; # can't make paths relative across volumes if ( !_same( $self->volume, $base->volume ) ) { Carp::croak("relative() can't cross volumes: '$self' vs '$base'"); } # if same absolute path, relative is current directory return _path(".") if _same( $self->[PATH], $base->[PATH] ); # if base is a prefix of self, chop prefix off self if ( $base->subsumes($self) ) { $base = "" if $base->is_rootdir; my $relative = "$self"; $relative =~ s{\A\Q$base/}{}; return _path(".", $relative); } # base is not a prefix, so must find a common prefix (even if root) my ( @common, @self_parts, @base_parts ); @base_parts = split /\//, $base->_just_filepath; # if self is rootdir, then common directory is root (shown as empty # string for later joins); otherwise, must be computed from path parts. if ( $self->is_rootdir ) { @common = (""); shift @base_parts; } else { @self_parts = split /\//, $self->_just_filepath; while ( @self_parts && @base_parts && _same( $self_parts[0], $base_parts[0] ) ) { push @common, shift @base_parts; shift @self_parts; } } # if there are any symlinks from common to base, we have a problem, as # you can't guarantee that updir from base reaches the common prefix; # we must resolve symlinks and try again; likewise, any updirs are # a problem as it throws off calculation of updirs needed to get from # self's path to the common prefix. if ( my $new_base = $self->_resolve_between( \@common, \@base_parts ) ) { return $self->relative($new_base); } # otherwise, symlinks in common or from common to A don't matter as # those don't involve updirs my @new_path = ( ("..") x ( 0+ @base_parts ), @self_parts ); return _path(@new_path); } sub _just_filepath { my $self = shift; my $self_vol = $self->volume; return "$self" if !length $self_vol; ( my $self_path = "$self" ) =~ s{\A\Q$self_vol}{}; return $self_path; } sub _resolve_between { my ( $self, $common, $base ) = @_; my $path = $self->volume . join( "/", @$common ); my $changed = 0; for my $p (@$base) { $path .= "/$p"; if ( $p eq '..' ) { $changed = 1; if ( -e $path ) { $path = _path($path)->realpath->[PATH]; } else { $path =~ s{/[^/]+/..\z}{/}; } } if ( -l $path ) { $changed = 1; $path = _path($path)->realpath->[PATH]; } } return $changed ? _path($path) : undef; } #pod =method remove #pod #pod path("foo.txt")->remove; #pod #pod This is just like C<unlink>, except for its error handling: if the path does #pod not exist, it returns false; if deleting the file fails, it throws an #pod exception. #pod #pod Current API available since 0.012. #pod #pod =cut sub remove { my $self = shift; return 0 if !-e $self->[PATH] && !-l $self->[PATH]; return unlink( $self->[PATH] ) || $self->_throw('unlink'); } #pod =method remove_tree #pod #pod # directory #pod path("foo/bar/baz")->remove_tree; #pod path("foo/bar/baz")->remove_tree( \%options ); #pod path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove #pod #pod Like calling C<remove_tree> from L<File::Path>, but defaults to C<safe> mode. #pod An optional hash reference is passed through to C<remove_tree>. Errors will be #pod trapped and an exception thrown. Returns the number of directories deleted, #pod just like C<remove_tree>. #pod #pod If you want to remove a directory only if it is empty, use the built-in #pod C<rmdir> function instead. #pod #pod rmdir path("foo/bar/baz/"); #pod #pod Current API available since 0.013. #pod #pod =cut sub remove_tree { my ( $self, $args ) = @_; return 0 if !-e $self->[PATH] && !-l $self->[PATH]; $args = {} unless ref $args eq 'HASH'; my $err; $args->{error} = \$err unless defined $args->{error}; $args->{safe} = 1 unless defined $args->{safe}; require File::Path; my $count = File::Path::remove_tree( $self->[PATH], $args ); if ( $err && @$err ) { my ( $file, $message ) = %{ $err->[0] }; Carp::croak("remove_tree failed for $file: $message"); } return $count; } #pod =method sibling #pod #pod $foo = path("/tmp/foo.txt"); #pod $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt #pod $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt #pod #pod Returns a new C<Path::Tiny> object relative to the parent of the original. #pod This is slightly more efficient than C<< $path->parent->child(...) >>. #pod #pod Current API available since 0.058. #pod #pod =cut sub sibling { my $self = shift; return _path( $self->parent->[PATH], @_ ); } #pod =method size, size_human #pod #pod my $p = path("foo"); # with size 1025 bytes #pod #pod $p->size; # "1025" #pod $p->size_human; # "1.1 K" #pod $p->size_human( {format => "iec"} ); # "1.1 KiB" #pod #pod Returns the size of a file. The C<size> method is just a wrapper around C<-s>. #pod #pod The C<size_human> method provides a human-readable string similar to #pod C<ls -lh>. Like C<ls>, it rounds upwards and provides one decimal place for #pod single-digit sizes and no decimal places for larger sizes. The only available #pod option is C<format>, which has three valid values: #pod #pod =for :list #pod * 'ls' (the default): base-2 sizes, with C<ls> style single-letter suffixes (K, M, etc.) #pod * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) #pod * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) #pod #pod If C<-s> would return C<undef>, C<size_human> returns the empty string. #pod #pod Current API available since 0.122. #pod #pod =cut sub size { -s $_[0]->[PATH] } my %formats = ( 'ls' => [ 1024, log(1024), [ "", map { " $_" } qw/K M G T/ ] ], 'iec' => [ 1024, log(1024), [ "", map { " $_" } qw/KiB MiB GiB TiB/ ] ], 'si' => [ 1000, log(1000), [ "", map { " $_" } qw/kB MB GB TB/ ] ], ); sub _formats { return $formats{$_[0]} } sub size_human { my $self = shift; my $args = _get_args( shift, qw/format/ ); my $format = defined $args->{format} ? $args->{format} : "ls"; my $fmt_opts = $formats{$format} or Carp::croak("Invalid format '$format' for size_human()"); my $size = -s $self->[PATH]; return defined $size ? _human_size( $size, @$fmt_opts ) : ""; } sub _ceil { return $_[0] == int($_[0]) ? $_[0] : int($_[0]+1); } sub _human_size { my ( $size, $base, $log_base, $suffixes ) = @_; return "0" if $size == 0; my $mag = int( log($size) / $log_base ); $size /= $base**$mag; $size = $mag == 0 ? $size : length( int($size) ) == 1 ? _ceil( $size * 10 ) / 10 : _ceil($size); if ( $size >= $base ) { $size /= $base; $mag++; } my $fmt = ( $mag == 0 || length( int($size) ) > 1 ) ? "%.0f%s" : "%.1f%s"; return sprintf( $fmt, $size, $suffixes->[$mag] ); } #pod =method slurp, slurp_raw, slurp_utf8 #pod #pod $data = path("foo.txt")->slurp; #pod $data = path("foo.txt")->slurp( {binmode => ":raw"} ); #pod $data = path("foo.txt")->slurp_raw; #pod $data = path("foo.txt")->slurp_utf8; #pod #pod Reads file contents into a scalar. Takes an optional hash reference which may #pod be used to pass options. The only available option is C<binmode>, which is #pod passed to C<binmode()> on the handle used for reading. #pod #pod C<slurp_raw> is like C<slurp> with a C<binmode> of C<:unix> for #pod a fast, unbuffered, raw read. #pod #pod C<slurp_utf8> is like C<slurp> with a C<binmode> of #pod C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with #pod L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a #pod unbuffered, raw slurp will be done instead and the result decoded with #pod C<Unicode::UTF8>. This is just as strict and is roughly an order of #pod magnitude faster than using C<:encoding(UTF-8)>. #pod #pod B<Note>: C<slurp> and friends lock the filehandle before slurping. If #pod you plan to slurp from a file created with L<File::Temp>, be sure to #pod close other handles or open without locking to avoid a deadlock: #pod #pod my $tempfile = File::Temp->new(EXLOCK => 0); #pod my $guts = path($tempfile)->slurp; #pod #pod Current API available since 0.004. #pod #pod =cut sub slurp { my $self = shift; my $args = _get_args( shift, qw/binmode/ ); my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open<'} unless defined $binmode; my $fh = $self->filehandle( { locked => 1 }, "<", $binmode ); if ( ( defined($binmode) ? $binmode : "" ) eq ":unix" and my $size = -s $fh ) { my $buf; my $rc = read $fh, $buf, $size; # File::Slurp in a nutshell $self->_throw('read') unless defined $rc; return $buf; } else { local $/; my $buf = scalar <$fh>; $self->_throw('read') unless defined $buf; return $buf; } } sub slurp_raw { $_[1] = { binmode => ":unix" }; goto &slurp } sub slurp_utf8 { if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { return Unicode::UTF8::decode_utf8( slurp( $_[0], { binmode => ":unix" } ) ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { $_[1] = { binmode => ":unix:utf8_strict" }; goto &slurp; } else { $_[1] = { binmode => ":unix:encoding(UTF-8)" }; goto &slurp; } } #pod =method spew, spew_raw, spew_utf8 #pod #pod path("foo.txt")->spew(@data); #pod path("foo.txt")->spew(\@data); #pod path("foo.txt")->spew({binmode => ":raw"}, @data); #pod path("foo.txt")->spew_raw(@data); #pod path("foo.txt")->spew_utf8(@data); #pod #pod Writes data to a file atomically. The file is written to a temporary file in #pod the same directory, then renamed over the original. An optional hash reference #pod may be used to pass options. The only option is C<binmode>, which is passed to #pod C<binmode()> on the handle used for writing. #pod #pod C<spew_raw> is like C<spew> with a C<binmode> of C<:unix> for a fast, #pod unbuffered, raw write. #pod #pod C<spew_utf8> is like C<spew> with a C<binmode> of C<:unix:encoding(UTF-8)> #pod (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> #pod 0.58+ is installed, a raw, unbuffered spew will be done instead on the data #pod encoded with C<Unicode::UTF8>. #pod #pod B<NOTE>: because the file is written to a temporary file and then renamed, the #pod new file will wind up with permissions based on your current umask. This is a #pod feature to protect you from a race condition that would otherwise give #pod different permissions than you might expect. If you really want to keep the #pod original mode flags, use L</append> with the C<truncate> option. #pod #pod Current API available since 0.011. #pod #pod =cut sub spew { my ( $self, @data ) = @_; my $args = ( @data && ref $data[0] eq 'HASH' ) ? shift @data : {}; $args = _get_args( $args, qw/binmode/ ); my $binmode = $args->{binmode}; # get default binmode from caller's lexical scope (see "perldoc open") $binmode = ( ( caller(0) )[10] || {} )->{'open>'} unless defined $binmode; # writing needs to follow the link and create the tempfile in the same # dir for later atomic rename my $resolved_path = $self->_resolve_symlinks; my $temp = $resolved_path->_replacment_path; my $fh; my $ok = eval { $fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode ); 1 }; if (!$ok) { my $msg = ref($@) eq 'Path::Tiny::Error' ? "error opening temp file '$@->{file}' for atomic write: $@->{err}" : "error opening temp file for atomic write: $@"; $self->_throw('spew', $self->[PATH], $msg); } print( {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data) or self->_throw('print', $temp->[PATH]); close $fh or $self->_throw( 'close', $temp->[PATH] ); return $temp->move($resolved_path); } sub spew_raw { splice @_, 1, 0, { binmode => ":unix" }; goto &spew } sub spew_utf8 { if ( defined($HAS_UU) ? $HAS_UU : ( $HAS_UU = _check_UU() ) ) { my $self = shift; spew( $self, { binmode => ":unix" }, map { Unicode::UTF8::encode_utf8($_) } map { ref eq 'ARRAY' ? @$_ : $_ } @_ ); } elsif ( defined($HAS_PU) ? $HAS_PU : ( $HAS_PU = _check_PU() ) ) { splice @_, 1, 0, { binmode => ":unix:utf8_strict" }; goto &spew; } else { splice @_, 1, 0, { binmode => ":unix:encoding(UTF-8)" }; goto &spew; } } #pod =method stat, lstat #pod #pod $stat = path("foo.txt")->stat; #pod $stat = path("/some/symlink")->lstat; #pod #pod Like calling C<stat> or C<lstat> from L<File::stat>. #pod #pod Current API available since 0.001. #pod #pod =cut # XXX break out individual stat() components as subs? sub stat { my $self = shift; require File::stat; return File::stat::stat( $self->[PATH] ) || $self->_throw('stat'); } sub lstat { my $self = shift; require File::stat; return File::stat::lstat( $self->[PATH] ) || $self->_throw('lstat'); } #pod =method stringify #pod #pod $path = path("foo.txt"); #pod say $path->stringify; # same as "$path" #pod #pod Returns a string representation of the path. Unlike C<canonpath>, this method #pod returns the path standardized with Unix-style C</> directory separators. #pod #pod Current API available since 0.001. #pod #pod =cut sub stringify { $_[0]->[PATH] =~ /^~/ ? './' . $_[0]->[PATH] : $_[0]->[PATH] } #pod =method subsumes #pod #pod path("foo/bar")->subsumes("foo/bar/baz"); # true #pod path("/foo/bar")->subsumes("/foo/baz"); # false #pod #pod Returns true if the first path is a prefix of the second path at a directory #pod boundary. #pod #pod This B<does not> resolve parent directory entries (C<..>) or symlinks: #pod #pod path("foo/bar")->subsumes("foo/bar/../baz"); # true #pod #pod If such things are important to you, ensure that both paths are resolved to #pod the filesystem with C<realpath>: #pod #pod my $p1 = path("foo/bar")->realpath; #pod my $p2 = path("foo/bar/../baz")->realpath; #pod if ( $p1->subsumes($p2) ) { ... } #pod #pod Current API available since 0.048. #pod #pod =cut sub subsumes { my $self = shift; Carp::croak("subsumes() requires a defined, positive-length argument") unless defined $_[0]; my $other = _path(shift); # normalize absolute vs relative if ( $self->is_absolute && !$other->is_absolute ) { $other = $other->absolute; } elsif ( $other->is_absolute && !$self->is_absolute ) { $self = $self->absolute; } # normalize volume vs non-volume; do this after absolute path # adjustments above since that might add volumes already if ( length $self->volume && !length $other->volume ) { $other = $other->absolute; } elsif ( length $other->volume && !length $self->volume ) { $self = $self->absolute; } if ( $self->[PATH] eq '.' ) { return !!1; # cwd subsumes everything relative } elsif ( $self->is_rootdir ) { # a root directory ("/", "c:/") already ends with a separator return $other->[PATH] =~ m{^\Q$self->[PATH]\E}; } else { # exact match or prefix breaking at a separator return $other->[PATH] =~ m{^\Q$self->[PATH]\E(?:/|\z)}; } } #pod =method touch #pod #pod path("foo.txt")->touch; #pod path("foo.txt")->touch($epoch_secs); #pod #pod Like the Unix C<touch> utility. Creates the file if it doesn't exist, or else #pod changes the modification and access times to the current time. If the first #pod argument is the epoch seconds then it will be used. #pod #pod Returns the path object so it can be easily chained with other methods: #pod #pod # won't die if foo.txt doesn't exist #pod $content = path("foo.txt")->touch->slurp; #pod #pod Current API available since 0.015. #pod #pod =cut sub touch { my ( $self, $epoch ) = @_; if ( !-e $self->[PATH] ) { my $fh = $self->openw; close $fh or $self->_throw('close'); } if ( defined $epoch ) { utime $epoch, $epoch, $self->[PATH] or $self->_throw("utime ($epoch)"); } else { # literal undef prevents warnings :-( utime undef, undef, $self->[PATH] or $self->_throw("utime ()"); } return $self; } #pod =method touchpath #pod #pod path("bar/baz/foo.txt")->touchpath; #pod #pod Combines C<mkdir> and C<touch>. Creates the parent directory if it doesn't exist, #pod before touching the file. Returns the path object like C<touch> does. #pod #pod If you need to pass options, use C<mkdir> and C<touch> separately: #pod #pod path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); #pod #pod Current API available since 0.022. #pod #pod =cut sub touchpath { my ($self) = @_; my $parent = $self->parent; $parent->mkdir unless $parent->exists; $self->touch; } #pod =method visit #pod #pod path("/tmp")->visit( \&callback, \%options ); #pod #pod Executes a callback for each child of a directory. It returns a hash #pod reference with any state accumulated during iteration. #pod #pod The options are the same as for L</iterator> (which it uses internally): #pod C<recurse> and C<follow_symlinks>. Both default to false. #pod #pod The callback function will receive a C<Path::Tiny> object as the first argument #pod and a hash reference to accumulate state as the second argument. For example: #pod #pod # collect files sizes #pod my $sizes = path("/tmp")->visit( #pod sub { #pod my ($path, $state) = @_; #pod return if $path->is_dir; #pod $state->{$path} = -s $path; #pod }, #pod { recurse => 1 } #pod ); #pod #pod For convenience, the C<Path::Tiny> object will also be locally aliased as the #pod C<$_> global variable: #pod #pod # print paths matching /foo/ #pod path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); #pod #pod If the callback returns a B<reference> to a false scalar value, iteration will #pod terminate. This is not the same as "pruning" a directory search; this just #pod stops all iteration and returns the state hash reference. #pod #pod # find up to 10 files larger than 100K #pod my $files = path("/tmp")->visit( #pod sub { #pod my ($path, $state) = @_; #pod $state->{$path}++ if -s $path > 102400 #pod return \0 if keys %$state == 10; #pod }, #pod { recurse => 1 } #pod ); #pod #pod If you want more flexible iteration, use a module like L<Path::Iterator::Rule>. #pod #pod Current API available since 0.062. #pod #pod =cut sub visit { my $self = shift; my $cb = shift; my $args = _get_args( shift, qw/recurse follow_symlinks/ ); Carp::croak("Callback for visit() must be a code reference") unless defined($cb) && ref($cb) eq 'CODE'; my $next = $self->iterator($args); my $state = {}; while ( my $file = $next->() ) { local $_ = $file; my $r = $cb->( $file, $state ); last if ref($r) eq 'SCALAR' && !$$r; } return $state; } #pod =method volume #pod #pod $vol = path("/tmp/foo.txt")->volume; # "" #pod $vol = path("C:/tmp/foo.txt")->volume; # "C:" #pod #pod Returns the volume portion of the path. This is equivalent #pod to what L<File::Spec> would give from C<splitpath> and thus #pod usually is the empty string on Unix-like operating systems or the #pod drive letter for an absolute path on C<MSWin32>. #pod #pod Current API available since 0.001. #pod #pod =cut sub volume { my ($self) = @_; $self->_splitpath unless defined $self->[VOL]; return $self->[VOL]; } package Path::Tiny::Error; our @CARP_NOT = qw/Path::Tiny/; use overload ( q{""} => sub { (shift)->{msg} }, fallback => 1 ); sub throw { my ( $class, $op, $file, $err ) = @_; chomp( my $trace = Carp::shortmess ); my $msg = "Error $op on '$file': $err$trace\n"; die bless { op => $op, file => $file, err => $err, msg => $msg }, $class; } 1; # vim: ts=4 sts=4 sw=4 et: __END__ =pod =encoding UTF-8 =head1 NAME Path::Tiny - File path utility =head1 VERSION version 0.146 =head1 SYNOPSIS use Path::Tiny; # Creating Path::Tiny objects my $dir = path("/tmp"); my $foo = path("foo.txt"); my $subdir = $dir->child("foo"); my $bar = $subdir->child("bar.txt"); # Stringifies as cleaned up path my $file = path("./foo.txt"); print $file; # "foo.txt" # Reading files my $guts = $file->slurp; $guts = $file->slurp_utf8; my @lines = $file->lines; @lines = $file->lines_utf8; my ($head) = $file->lines( {count => 1} ); my ($tail) = $file->lines( {count => -1} ); # Writing files $bar->spew( @data ); $bar->spew_utf8( @data ); # Reading directories for ( $dir->children ) { ... } my $iter = $dir->iterator; while ( my $next = $iter->() ) { ... } =head1 DESCRIPTION This module provides a small, fast utility for working with file paths. It is friendlier to use than L<File::Spec> and provides easy access to functions from several other core file handling modules. It aims to be smaller and faster than many alternatives on CPAN, while helping people do many common things in consistent and less error-prone ways. Path::Tiny does not try to work for anything except Unix-like and Win32 platforms. Even then, it might break if you try something particularly obscure or tortuous. (Quick! What does this mean: C<< ///../../..//./././a//b/.././c/././ >>? And how does it differ on Win32?) All paths are forced to have Unix-style forward slashes. Stringifying the object gives you back the path (after some clean up). File input/output methods C<flock> handles before reading or writing, as appropriate (if supported by the platform and/or filesystem). The C<*_utf8> methods (C<slurp_utf8>, C<lines_utf8>, etc.) operate in raw mode. On Windows, that means they will not have CRLF translation from the C<:crlf> IO layer. Installing L<Unicode::UTF8> 0.58 or later will speed up C<*_utf8> situations in many cases and is highly recommended. Alternatively, installing L<PerlIO::utf8_strict> 0.003 or later will be used in place of the default C<:encoding(UTF-8)>. This module depends heavily on PerlIO layers for correct operation and thus requires Perl 5.008001 or later. =head1 CONSTRUCTORS =head2 path $path = path("foo/bar"); $path = path("/tmp", "file.txt"); # list $path = path("."); # cwd Constructs a C<Path::Tiny> object. It doesn't matter if you give a file or directory path. It's still up to you to call directory-like methods only on directories and file-like methods only on files. This function is exported automatically by default. The first argument must be defined and have non-zero length or an exception will be thrown. This prevents subtle, dangerous errors with code like C<< path( maybe_undef() )->remove_tree >>. B<DEPRECATED>: If and only if the B<first> character of the B<first> argument to C<path> is a tilde ('~'), then tilde replacement will be applied to the first path segment. A single tilde will be replaced with C<glob('~')> and a tilde followed by a username will be replaced with output of C<glob('~username')>. B<No other method does tilde expansion on its arguments>. See L</Tilde expansion (deprecated)> for more. On Windows, if the path consists of a drive identifier without a path component (C<C:> or C<D:>), it will be expanded to the absolute path of the current directory on that volume using C<Cwd::getdcwd()>. If called with a single C<Path::Tiny> argument, the original is returned unless the original is holding a temporary file or directory reference in which case a stringified copy is made. $path = path("foo/bar"); $temp = Path::Tiny->tempfile; $p2 = path($path); # like $p2 = $path $t2 = path($temp); # like $t2 = path( "$temp" ) This optimizes copies without proliferating references unexpectedly if a copy is made by code outside your control. Current API available since 0.017. =head2 new $path = Path::Tiny->new("foo/bar"); This is just like C<path>, but with method call overhead. (Why would you do that?) Current API available since 0.001. =head2 cwd $path = Path::Tiny->cwd; # path( Cwd::getcwd ) $path = cwd; # optional export Gives you the absolute path to the current directory as a C<Path::Tiny> object. This is slightly faster than C<< path(".")->absolute >>. C<cwd> may be exported on request and used as a function instead of as a method. Current API available since 0.018. =head2 rootdir $path = Path::Tiny->rootdir; # / $path = rootdir; # optional export Gives you C<< File::Spec->rootdir >> as a C<Path::Tiny> object if you're too picky for C<path("/")>. C<rootdir> may be exported on request and used as a function instead of as a method. Current API available since 0.018. =head2 tempfile, tempdir $temp = Path::Tiny->tempfile( @options ); $temp = Path::Tiny->tempdir( @options ); $temp = $dirpath->tempfile( @options ); $temp = $dirpath->tempdir( @options ); $temp = tempfile( @options ); # optional export $temp = tempdir( @options ); # optional export C<tempfile> passes the options to C<< File::Temp->new >> and returns a C<Path::Tiny> object with the file name. The C<TMPDIR> option will be enabled by default, but you can override that by passing C<< TMPDIR => 0 >> along with the options. (If you use an absolute C<TEMPLATE> option, you will want to disable C<TMPDIR>.) The resulting C<File::Temp> object is cached. When the C<Path::Tiny> object is destroyed, the C<File::Temp> object will be as well. C<File::Temp> annoyingly requires you to specify a custom template in slightly different ways depending on which function or method you call, but C<Path::Tiny> lets you ignore that and can take either a leading template or a C<TEMPLATE> option and does the right thing. $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok The tempfile path object will be normalized to have an absolute path, even if created in a relative directory using C<DIR>. If you want it to have the C<realpath> instead, pass a leading options hash like this: $real_temp = tempfile({realpath => 1}, @options); C<tempdir> is just like C<tempfile>, except it calls C<< File::Temp->newdir >> instead. Both C<tempfile> and C<tempdir> may be exported on request and used as functions instead of as methods. The methods can be called on an instances representing a directory. In this case, the directory is used as the base to create the temporary file/directory, setting the C<DIR> option in File::Temp. my $target_dir = path('/to/destination'); my $tempfile = $target_dir->tempfile('foobarXXXXXX'); $tempfile->spew('A lot of data...'); # not atomic $tempfile->move($target_dir->child('foobar')); # hopefully atomic In this case, any value set for option C<DIR> is ignored. B<Note>: for tempfiles, the filehandles from File::Temp are closed and not reused. This is not as secure as using File::Temp handles directly, but is less prone to deadlocks or access problems on some platforms. Think of what C<Path::Tiny> gives you to be just a temporary file B<name> that gets cleaned up. B<Note 2>: if you don't want these cleaned up automatically when the object is destroyed, File::Temp requires different options for directories and files. Use C<< CLEANUP => 0 >> for directories and C<< UNLINK => 0 >> for files. B<Note 3>: Don't lose the temporary object by chaining a method call instead of storing it: my $lost = tempdir()->child("foo"); # tempdir cleaned up right away B<Note 4>: The cached object may be accessed with the L</cached_temp> method. Keeping a reference to, or modifying the cached object may break the behavior documented above and is not supported. Use at your own risk. Current API available since 0.119. =head1 METHODS =head2 absolute $abs = path("foo/bar")->absolute; $abs = path("foo/bar")->absolute("/tmp"); Returns a new C<Path::Tiny> object with an absolute path (or itself if already absolute). If no argument is given, the current directory is used as the absolute base path. If an argument is given, it will be converted to an absolute path (if it is not already) and used as the absolute base path. This will not resolve upward directories ("foo/../bar") unless C<canonpath> in L<File::Spec> would normally do so on your platform. If you need them resolved, you must call the more expensive C<realpath> method instead. On Windows, an absolute path without a volume component will have it added based on the current drive. Current API available since 0.101. =head2 append, append_raw, append_utf8 path("foo.txt")->append(@data); path("foo.txt")->append(\@data); path("foo.txt")->append({binmode => ":raw"}, @data); path("foo.txt")->append_raw(@data); path("foo.txt")->append_utf8(@data); Appends data to a file. The file is locked with C<flock> prior to writing and closed afterwards. An optional hash reference may be used to pass options. Valid options are: =over 4 =item * C<binmode>: passed to C<binmode()> on the handle used for writing. =item * C<truncate>: truncates the file after locking and before appending =back The C<truncate> option is a way to replace the contents of a file B<in place>, unlike L</spew> which writes to a temporary file and then replaces the original (if it exists). C<append_raw> is like C<append> with a C<binmode> of C<:unix> for a fast, unbuffered, raw write. C<append_utf8> is like C<append> with an unbuffered C<binmode> C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, an unbuffered, raw append will be done instead on the data encoded with C<Unicode::UTF8>. Current API available since 0.060. =head2 assert $path = path("foo.txt")->assert( sub { $_->exists } ); Returns the invocant after asserting that a code reference argument returns true. When the assertion code reference runs, it will have the invocant object in the C<$_> variable. If it returns false, an exception will be thrown. The assertion code reference may also throw its own exception. If no assertion is provided, the invocant is returned without error. Current API available since 0.062. =head2 basename $name = path("foo/bar.txt")->basename; # bar.txt $name = path("foo.txt")->basename('.txt'); # foo $name = path("foo.txt")->basename(qr/.txt/); # foo $name = path("foo.txt")->basename(@suffixes); Returns the file portion or last directory portion of a path. Given a list of suffixes as strings or regular expressions, any that match at the end of the file portion or last directory portion will be removed before the result is returned. Current API available since 0.054. =head2 canonpath $canonical = path("foo/bar")->canonpath; # foo\bar on Windows Returns a string with the canonical format of the path name for the platform. In particular, this means directory separators will be C<\> on Windows. Current API available since 0.001. =head2 cached_temp Returns the cached C<File::Temp> or C<File::Temp::Dir> object if the C<Path::Tiny> object was created with C</tempfile> or C</tempdir>. If there is no such object, this method throws. B<WARNING>: Keeping a reference to, or modifying the cached object may break the behavior documented for temporary files and directories created with C<Path::Tiny> and is not supported. Use at your own risk. Current API available since 0.101. =head2 child $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" $file = path("/tmp")->child(@parts); Returns a new C<Path::Tiny> object relative to the original. Works like C<catfile> or C<catdir> from File::Spec, but without caring about file or directories. B<WARNING>: because the argument could contain C<..> or refer to symlinks, there is no guarantee that the new path refers to an actual descendent of the original. If this is important to you, transform parent and child with L</realpath> and check them with L</subsumes>. Current API available since 0.001. =head2 children @paths = path("/tmp")->children; @paths = path("/tmp")->children( qr/\.txt\z/ ); Returns a list of C<Path::Tiny> objects for all files and directories within a directory. Excludes "." and ".." automatically. If an optional C<qr//> argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching: @paths = path("/tmp")->children( qr/^foo/ ); # matches children like the glob foo* Current API available since 0.028. =head2 chmod path("foo.txt")->chmod(0777); path("foo.txt")->chmod("0755"); path("foo.txt")->chmod("go-w"); path("foo.txt")->chmod("a=r,u+wx"); Sets file or directory permissions. The argument can be a numeric mode, a octal string beginning with a "0" or a limited subset of the symbolic mode use by F</bin/chmod>. The symbolic mode must be a comma-delimited list of mode clauses. Clauses must match C<< qr/\A([augo]+)([=+-])([rwx]+)\z/ >>, which defines "who", "op" and "perms" parameters for each clause. Unlike F</bin/chmod>, all three parameters are required for each clause, multiple ops are not allowed and permissions C<stugoX> are not supported. (See L<File::chmod> for more complex needs.) Current API available since 0.053. =head2 copy path("/tmp/foo.txt")->copy("/tmp/bar.txt"); Copies the current path to the given destination using L<File::Copy>'s C<copy> function. Upon success, returns the C<Path::Tiny> object for the newly copied file. Current API available since 0.070. =head2 digest $obj = path("/tmp/foo.txt")->digest; # SHA-256 $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); Returns a hexadecimal digest for a file. An optional hash reference of options may be given. The only option is C<chunk_size>. If C<chunk_size> is given, that many bytes will be read at a time. If not provided, the entire file will be slurped into memory to compute the digest. Any subsequent arguments are passed to the constructor for L<Digest> to select an algorithm. If no arguments are given, the default is SHA-256. Current API available since 0.056. =head2 dirname (deprecated) $name = path("/tmp/foo.txt")->dirname; # "/tmp/" Returns the directory portion you would get from calling C<< File::Spec->splitpath( $path->stringify ) >> or C<"."> for a path without a parent directory portion. Because L<File::Spec> is inconsistent, the result might or might not have a trailing slash. Because of this, this method is B<deprecated>. A better, more consistently approach is likely C<< $path->parent->stringify >>, which will not have a trailing slash except for a root directory. Deprecated in 0.056. =head2 edit, edit_raw, edit_utf8 path("foo.txt")->edit( \&callback, $options ); path("foo.txt")->edit_utf8( \&callback ); path("foo.txt")->edit_raw( \&callback ); These are convenience methods that allow "editing" a file using a single callback argument. They slurp the file using C<slurp>, place the contents inside a localized C<$_> variable, call the callback function (without arguments), and then write C<$_> (presumably mutated) back to the file with C<spew>. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to C<slurp> and C<spew>. C<edit_utf8> and C<edit_raw> act like their respective C<slurp_*> and C<spew_*> methods. Current API available since 0.077. =head2 edit_lines, edit_lines_utf8, edit_lines_raw path("foo.txt")->edit_lines( \&callback, $options ); path("foo.txt")->edit_lines_utf8( \&callback ); path("foo.txt")->edit_lines_raw( \&callback ); These are convenience methods that allow "editing" a file's lines using a single callback argument. They iterate over the file: for each line, the line is put into a localized C<$_> variable, the callback function is executed (without arguments) and then C<$_> is written to a temporary file. When iteration is finished, the temporary file is atomically renamed over the original. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to the method that open handles for reading and writing. C<edit_lines_raw> is like C<edit_lines> with a buffered C<binmode> of C<:raw>. C<edit_lines_utf8> is like C<edit_lines> with a buffered C<binmode> C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). Current API available since 0.077. =head2 exists, is_file, is_dir if ( path("/tmp")->exists ) { ... } # -e if ( path("/tmp")->is_dir ) { ... } # -d if ( path("/tmp")->is_file ) { ... } # -e && ! -d Implements file test operations, this means the file or directory actually has to exist on the filesystem. Until then, it's just a path. B<Note>: C<is_file> is not C<-f> because C<-f> is not the opposite of C<-d>. C<-f> means "plain file", excluding symlinks, devices, etc. that often can be read just like files. Use C<-f> instead if you really mean to check for a plain file. Current API available since 0.053. =head2 filehandle $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); Returns an open file handle. The C<$mode> argument must be a Perl-style read/write mode string ("<" ,">", ">>", etc.). If a C<$binmode> is given, it is set during the C<open> call. An optional hash reference may be used to pass options. The C<locked> option governs file locking; if true, handles opened for writing, appending or read-write are locked with C<LOCK_EX>; otherwise, they are locked with C<LOCK_SH>. When using C<locked>, ">" or "+>" modes will delay truncation until after the lock is acquired. The C<exclusive> option causes the open() call to fail if the file already exists. This corresponds to the O_EXCL flag to sysopen / open(2). C<exclusive> implies C<locked> and will set it for you if you forget it. See C<openr>, C<openw>, C<openrw>, and C<opena> for sugar. Current API available since 0.066. =head2 has_same_bytes if ( path("foo.txt")->has_same_bytes("bar.txt") ) { # ... } This method returns true if both the invocant and the argument can be opened as file handles and the handles contain the same bytes. It returns false if their contents differ. If either can't be opened as a file (e.g. a directory or non-existent file), the method throws an exception. If both can be opened and both have the same C<realpath>, the method returns true without scanning any data. Current API available since 0.125. =head2 is_absolute, is_relative if ( path("/tmp")->is_absolute ) { ... } if ( path("/tmp")->is_relative ) { ... } Booleans for whether the path appears absolute or relative. Current API available since 0.001. =head2 is_rootdir while ( ! $path->is_rootdir ) { $path = $path->parent; ... } Boolean for whether the path is the root directory of the volume. I.e. the C<dirname> is C<q[/]> and the C<basename> is C<q[]>. This works even on C<MSWin32> with drives and UNC volumes: path("C:/")->is_rootdir; # true path("//server/share/")->is_rootdir; #true Current API available since 0.038. =head2 iterator $iter = path("/tmp")->iterator( \%options ); Returns a code reference that walks a directory lazily. Each invocation returns a C<Path::Tiny> object or undef when the iterator is exhausted. $iter = path("/tmp")->iterator; while ( $path = $iter->() ) { ... } The current and parent directory entries ("." and "..") will not be included. If the C<recurse> option is true, the iterator will walk the directory recursively, breadth-first. If the C<follow_symlinks> option is also true, directory links will be followed recursively. There is no protection against loops when following links. If a directory is not readable, it will not be followed. The default is the same as: $iter = path("/tmp")->iterator( { recurse => 0, follow_symlinks => 0, } ); For a more powerful, recursive iterator with built-in loop avoidance, see L<Path::Iterator::Rule>. See also L</visit>. Current API available since 0.016. =head2 lines, lines_raw, lines_utf8 @contents = path("/tmp/foo.txt")->lines; @contents = path("/tmp/foo.txt")->lines(\%options); @contents = path("/tmp/foo.txt")->lines_raw; @contents = path("/tmp/foo.txt")->lines_utf8; @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); Returns a list of lines from a file. Optionally takes a hash-reference of options. Valid options are C<binmode>, C<count> and C<chomp>. If C<binmode> is provided, it will be set on the handle prior to reading. If a positive C<count> is provided, that many lines will be returned from the start of the file. If a negative C<count> is provided, the entire file will be read, but only C<abs(count)> will be kept and returned. If C<abs(count)> exceeds the number of lines in the file, all lines will be returned. If C<chomp> is set, any end-of-line character sequences (C<CR>, C<CRLF>, or C<LF>) will be removed from the lines returned. Because the return is a list, C<lines> in scalar context will return the number of lines (and throw away the data). $number_of_lines = path("/tmp/foo.txt")->lines; C<lines_raw> is like C<lines> with a C<binmode> of C<:raw>. We use C<:raw> instead of C<:unix> so PerlIO buffering can manage reading by line. C<lines_utf8> is like C<lines> with a C<binmode> of C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the lines will be split. This is actually faster than relying on IO layers, though a bit memory intensive. If memory use is a concern, consider C<openr_utf8> and iterating directly on the handle. Current API available since 0.065. =head2 mkdir path("foo/bar/baz")->mkdir; path("foo/bar/baz")->mkdir( \%options ); Like calling C<make_path> from L<File::Path>. An optional hash reference is passed through to C<make_path>. Errors will be trapped and an exception thrown. Returns the the path object to facilitate chaining. B<NOTE>: unlike Perl's builtin C<mkdir>, this will create intermediate paths similar to the Unix C<mkdir -p> command. It will not error if applied to an existing directory. Current API available since 0.125. =head2 mkpath (deprecated) Like calling C<mkdir>, but returns the list of directories created or an empty list if the directories already exist, just like C<make_path>. Deprecated in 0.125. =head2 move path("foo.txt")->move("bar.txt"); Moves the current path to the given destination using L<File::Copy>'s C<move> function. Upon success, returns the C<Path::Tiny> object for the newly moved file. If the destination already exists and is a directory, and the source is not a directory, then the source file will be renamed into the directory specified by the destination. If possible, move() will simply rename the file. Otherwise, it copies the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. Current API available since 0.124. Prior versions used Perl's -built-in (and less robust) L<rename|perlfunc/rename> function and did not return an object. =head2 openr, openw, openrw, opena $fh = path("foo.txt")->openr($binmode); # read $fh = path("foo.txt")->openr_raw; $fh = path("foo.txt")->openr_utf8; $fh = path("foo.txt")->openw($binmode); # write $fh = path("foo.txt")->openw_raw; $fh = path("foo.txt")->openw_utf8; $fh = path("foo.txt")->opena($binmode); # append $fh = path("foo.txt")->opena_raw; $fh = path("foo.txt")->opena_utf8; $fh = path("foo.txt")->openrw($binmode); # read/write $fh = path("foo.txt")->openrw_raw; $fh = path("foo.txt")->openrw_utf8; Returns a file handle opened in the specified mode. The C<openr> style methods take a single C<binmode> argument. All of the C<open*> methods have C<open*_raw> and C<open*_utf8> equivalents that use buffered I/O layers C<:raw> and C<:raw:encoding(UTF-8)> (or C<:raw:utf8_strict> with L<PerlIO::utf8_strict>). An optional hash reference may be used to pass options. The only option is C<locked>. If true, handles opened for writing, appending or read-write are locked with C<LOCK_EX>; otherwise, they are locked for C<LOCK_SH>. $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); See L</filehandle> for more on locking. Current API available since 0.011. =head2 parent $parent = path("foo/bar/baz")->parent; # foo/bar $parent = path("foo/wibble.txt")->parent; # foo $parent = path("foo/bar/baz")->parent(2); # foo Returns a C<Path::Tiny> object corresponding to the parent directory of the original directory or file. An optional positive integer argument is the number of parent directories upwards to return. C<parent> by itself is equivalent to C<parent(1)>. Current API available since 0.014. =head2 realpath $real = path("/baz/foo/../bar")->realpath; $real = path("foo/../bar")->realpath; Returns a new C<Path::Tiny> object with all symbolic links and upward directory parts resolved using L<Cwd>'s C<realpath>. Compared to C<absolute>, this is more expensive as it must actually consult the filesystem. If the parent path can't be resolved (e.g. if it includes directories that don't exist), an exception will be thrown: $real = path("doesnt_exist/foo")->realpath; # dies However, if the parent path exists and only the last component (e.g. filename) doesn't exist, the realpath will be the realpath of the parent plus the non-existent last component: $real = path("./aasdlfasdlf")->realpath; # works The underlying L<Cwd> module usually worked this way on Unix, but died on Windows (and some Unixes) if the full path didn't exist. As of version 0.064, it's safe to use anywhere. Current API available since 0.001. =head2 relative $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar Returns a C<Path::Tiny> object with a path relative to a new base path given as an argument. If no argument is given, the current directory will be used as the new base path. If either path is already relative, it will be made absolute based on the current directly before determining the new relative path. The algorithm is roughly as follows: =over 4 =item * If the original and new base path are on different volumes, an exception will be thrown. =item * If the original and new base are identical, the relative path is C<".">. =item * If the new base subsumes the original, the relative path is the original path with the new base chopped off the front =item * If the new base does not subsume the original, a common prefix path is determined (possibly the root directory) and the relative path will consist of updirs (C<"..">) to reach the common prefix, followed by the original path less the common prefix. =back Unlike C<File::Spec::abs2rel>, in the last case above, the calculation based on a common prefix takes into account symlinks that could affect the updir process. Given an original path "/A/B" and a new base "/A/C", (where "A", "B" and "C" could each have multiple path components): =over 4 =item * Symlinks in "A" don't change the result unless the last component of A is a symlink and the first component of "C" is an updir. =item * Symlinks in "B" don't change the result and will exist in the result as given. =item * Symlinks and updirs in "C" must be resolved to actual paths, taking into account the possibility that not all path components might exist on the filesystem. =back Current API available since 0.001. New algorithm (that accounts for symlinks) available since 0.079. =head2 remove path("foo.txt")->remove; This is just like C<unlink>, except for its error handling: if the path does not exist, it returns false; if deleting the file fails, it throws an exception. Current API available since 0.012. =head2 remove_tree # directory path("foo/bar/baz")->remove_tree; path("foo/bar/baz")->remove_tree( \%options ); path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove Like calling C<remove_tree> from L<File::Path>, but defaults to C<safe> mode. An optional hash reference is passed through to C<remove_tree>. Errors will be trapped and an exception thrown. Returns the number of directories deleted, just like C<remove_tree>. If you want to remove a directory only if it is empty, use the built-in C<rmdir> function instead. rmdir path("foo/bar/baz/"); Current API available since 0.013. =head2 sibling $foo = path("/tmp/foo.txt"); $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt Returns a new C<Path::Tiny> object relative to the parent of the original. This is slightly more efficient than C<< $path->parent->child(...) >>. Current API available since 0.058. =head2 size, size_human my $p = path("foo"); # with size 1025 bytes $p->size; # "1025" $p->size_human; # "1.1 K" $p->size_human( {format => "iec"} ); # "1.1 KiB" Returns the size of a file. The C<size> method is just a wrapper around C<-s>. The C<size_human> method provides a human-readable string similar to C<ls -lh>. Like C<ls>, it rounds upwards and provides one decimal place for single-digit sizes and no decimal places for larger sizes. The only available option is C<format>, which has three valid values: =over 4 =item * 'ls' (the default): base-2 sizes, with C<ls> style single-letter suffixes (K, M, etc.) =item * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) =item * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) =back If C<-s> would return C<undef>, C<size_human> returns the empty string. Current API available since 0.122. =head2 slurp, slurp_raw, slurp_utf8 $data = path("foo.txt")->slurp; $data = path("foo.txt")->slurp( {binmode => ":raw"} ); $data = path("foo.txt")->slurp_raw; $data = path("foo.txt")->slurp_utf8; Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is C<binmode>, which is passed to C<binmode()> on the handle used for reading. C<slurp_raw> is like C<slurp> with a C<binmode> of C<:unix> for a fast, unbuffered, raw read. C<slurp_utf8> is like C<slurp> with a C<binmode> of C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a unbuffered, raw slurp will be done instead and the result decoded with C<Unicode::UTF8>. This is just as strict and is roughly an order of magnitude faster than using C<:encoding(UTF-8)>. B<Note>: C<slurp> and friends lock the filehandle before slurping. If you plan to slurp from a file created with L<File::Temp>, be sure to close other handles or open without locking to avoid a deadlock: my $tempfile = File::Temp->new(EXLOCK => 0); my $guts = path($tempfile)->slurp; Current API available since 0.004. =head2 spew, spew_raw, spew_utf8 path("foo.txt")->spew(@data); path("foo.txt")->spew(\@data); path("foo.txt")->spew({binmode => ":raw"}, @data); path("foo.txt")->spew_raw(@data); path("foo.txt")->spew_utf8(@data); Writes data to a file atomically. The file is written to a temporary file in the same directory, then renamed over the original. An optional hash reference may be used to pass options. The only option is C<binmode>, which is passed to C<binmode()> on the handle used for writing. C<spew_raw> is like C<spew> with a C<binmode> of C<:unix> for a fast, unbuffered, raw write. C<spew_utf8> is like C<spew> with a C<binmode> of C<:unix:encoding(UTF-8)> (or C<:unix:utf8_strict> with L<PerlIO::utf8_strict>). If L<Unicode::UTF8> 0.58+ is installed, a raw, unbuffered spew will be done instead on the data encoded with C<Unicode::UTF8>. B<NOTE>: because the file is written to a temporary file and then renamed, the new file will wind up with permissions based on your current umask. This is a feature to protect you from a race condition that would otherwise give different permissions than you might expect. If you really want to keep the original mode flags, use L</append> with the C<truncate> option. Current API available since 0.011. =head2 stat, lstat $stat = path("foo.txt")->stat; $stat = path("/some/symlink")->lstat; Like calling C<stat> or C<lstat> from L<File::stat>. Current API available since 0.001. =head2 stringify $path = path("foo.txt"); say $path->stringify; # same as "$path" Returns a string representation of the path. Unlike C<canonpath>, this method returns the path standardized with Unix-style C</> directory separators. Current API available since 0.001. =head2 subsumes path("foo/bar")->subsumes("foo/bar/baz"); # true path("/foo/bar")->subsumes("/foo/baz"); # false Returns true if the first path is a prefix of the second path at a directory boundary. This B<does not> resolve parent directory entries (C<..>) or symlinks: path("foo/bar")->subsumes("foo/bar/../baz"); # true If such things are important to you, ensure that both paths are resolved to the filesystem with C<realpath>: my $p1 = path("foo/bar")->realpath; my $p2 = path("foo/bar/../baz")->realpath; if ( $p1->subsumes($p2) ) { ... } Current API available since 0.048. =head2 touch path("foo.txt")->touch; path("foo.txt")->touch($epoch_secs); Like the Unix C<touch> utility. Creates the file if it doesn't exist, or else changes the modification and access times to the current time. If the first argument is the epoch seconds then it will be used. Returns the path object so it can be easily chained with other methods: # won't die if foo.txt doesn't exist $content = path("foo.txt")->touch->slurp; Current API available since 0.015. =head2 touchpath path("bar/baz/foo.txt")->touchpath; Combines C<mkdir> and C<touch>. Creates the parent directory if it doesn't exist, before touching the file. Returns the path object like C<touch> does. If you need to pass options, use C<mkdir> and C<touch> separately: path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); Current API available since 0.022. =head2 visit path("/tmp")->visit( \&callback, \%options ); Executes a callback for each child of a directory. It returns a hash reference with any state accumulated during iteration. The options are the same as for L</iterator> (which it uses internally): C<recurse> and C<follow_symlinks>. Both default to false. The callback function will receive a C<Path::Tiny> object as the first argument and a hash reference to accumulate state as the second argument. For example: # collect files sizes my $sizes = path("/tmp")->visit( sub { my ($path, $state) = @_; return if $path->is_dir; $state->{$path} = -s $path; }, { recurse => 1 } ); For convenience, the C<Path::Tiny> object will also be locally aliased as the C<$_> global variable: # print paths matching /foo/ path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); If the callback returns a B<reference> to a false scalar value, iteration will terminate. This is not the same as "pruning" a directory search; this just stops all iteration and returns the state hash reference. # find up to 10 files larger than 100K my $files = path("/tmp")->visit( sub { my ($path, $state) = @_; $state->{$path}++ if -s $path > 102400 return \0 if keys %$state == 10; }, { recurse => 1 } ); If you want more flexible iteration, use a module like L<Path::Iterator::Rule>. Current API available since 0.062. =head2 volume $vol = path("/tmp/foo.txt")->volume; # "" $vol = path("C:/tmp/foo.txt")->volume; # "C:" Returns the volume portion of the path. This is equivalent to what L<File::Spec> would give from C<splitpath> and thus usually is the empty string on Unix-like operating systems or the drive letter for an absolute path on C<MSWin32>. Current API available since 0.001. =for Pod::Coverage openr_utf8 opena_utf8 openw_utf8 openrw_utf8 openr_raw opena_raw openw_raw openrw_raw IS_WIN32 FREEZE THAW TO_JSON abs2rel =head1 EXCEPTION HANDLING Simple usage errors will generally croak. Failures of underlying Perl functions will be thrown as exceptions in the class C<Path::Tiny::Error>. A C<Path::Tiny::Error> object will be a hash reference with the following fields: =over 4 =item * C<op> — a description of the operation, usually function call and any extra info =item * C<file> — the file or directory relating to the error =item * C<err> — hold C<$!> at the time the error was thrown =item * C<msg> — a string combining the above data and a Carp-like short stack trace =back Exception objects will stringify as the C<msg> field. =head1 ENVIRONMENT =head2 PERL_PATH_TINY_NO_FLOCK If the environment variable C<PERL_PATH_TINY_NO_FLOCK> is set to a true value then flock will NOT be used when accessing files (this is not recommended). =head1 CAVEATS =head2 Subclassing not supported For speed, this class is implemented as an array based object and uses many direct function calls internally. You must not subclass it and expect things to work properly. =head2 Tilde expansion (deprecated) Tilde expansion was a nice idea, but it can't easily be applied consistently across the entire API. This was a source of bugs and confusion for users. Therefore, it is B<deprecated> and its use is discouraged. Limitations to the existing, legacy behavior follow. Tilde expansion will only occur if the B<first> argument to C<path> begins with a tilde. B<No other method does tilde expansion on its arguments>. If you want tilde expansion on arguments, you must explicitly wrap them in a call to C<path>. path( "~/foo.txt" )->copy( path( "~/bar.txt" ) ); If you need a literal leading tilde, use C<path("./~whatever")> so that the argument to C<path> doesn't start with a tilde, but the path still resolves to the current directory. Behaviour of tilde expansion with a username for non-existent users depends on the output of C<glob> on the system. =head2 File locking If flock is not supported on a platform, it will not be used, even if locking is requested. In situations where a platform normally would support locking, but the flock fails due to a filesystem limitation, Path::Tiny has some heuristics to detect this and will warn once and continue in an unsafe mode. If you want this failure to be fatal, you can fatalize the 'flock' warnings category: use warnings FATAL => 'flock'; See additional caveats below. =head3 NFS and BSD On BSD, Perl's flock implementation may not work to lock files on an NFS filesystem. If detected, this situation will warn once, as described above. =head3 Lustre The Lustre filesystem does not support flock. If detected, this situation will warn once, as described above. =head3 AIX and locking AIX requires a write handle for locking. Therefore, calls that normally open a read handle and take a shared lock instead will open a read-write handle and take an exclusive lock. If the user does not have write permission, no lock will be used. =head2 utf8 vs UTF-8 All the C<*_utf8> methods by default use C<:encoding(UTF-8)> -- either as C<:unix:encoding(UTF-8)> (unbuffered, for whole file operations) or C<:raw:encoding(UTF-8)> (buffered, for line-by-line operations). These are strict against the Unicode spec and disallows illegal Unicode codepoints or UTF-8 sequences. Unfortunately, C<:encoding(UTF-8)> is very, very slow. If you install L<Unicode::UTF8> 0.58 or later, that module will be used by some C<*_utf8> methods to encode or decode data after a raw, binary input/output operation, which is much faster. Alternatively, if you install L<PerlIO::utf8_strict>, that will be used instead of C<:encoding(UTF-8)> and is also very fast. If you need the performance and can accept the security risk, C<< slurp({binmode => ":unix:utf8"}) >> will be faster than C<:unix:encoding(UTF-8)> (but not as fast as C<Unicode::UTF8>). Note that the C<*_utf8> methods read in B<raw> mode. There is no CRLF translation on Windows. If you must have CRLF translation, use the regular input/output methods with an appropriate binmode: $path->spew_utf8($data); # raw $path->spew({binmode => ":encoding(UTF-8)"}, $data; # LF -> CRLF =head2 Default IO layers and the open pragma If you have Perl 5.10 or later, file input/output methods (C<slurp>, C<spew>, etc.) and high-level handle opening methods ( C<filehandle>, C<openr>, C<openw>, etc. ) respect default encodings set by the C<-C> switch or lexical L<open> settings of the caller. For UTF-8, this is almost certainly slower than using the dedicated C<_utf8> methods if you have L<Unicode::UTF8> or L<PerlIP::utf8_strict>. =head1 TYPE CONSTRAINTS AND COERCION A standard L<MooseX::Types> library is available at L<MooseX::Types::Path::Tiny>. A L<Type::Tiny> equivalent is available as L<Types::Path::Tiny>. =head1 SEE ALSO These are other file/path utilities, which may offer a different feature set than C<Path::Tiny>. =over 4 =item * L<File::chmod> =item * L<File::Fu> =item * L<IO::All> =item * L<Path::Class> =back These iterators may be slightly faster than the recursive iterator in C<Path::Tiny>: =over 4 =item * L<Path::Iterator::Rule> =item * L<File::Next> =back There are probably comparable, non-Tiny tools. Let me know if you want me to add a module to the list. This module was featured in the L<2013 Perl Advent Calendar|http://www.perladvent.org/2013/2013-12-18.html>. =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L<https://github.com/dagolden/Path-Tiny/issues>. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L<https://github.com/dagolden/Path-Tiny> git clone https://github.com/dagolden/Path-Tiny.git =head1 AUTHOR David Golden <dagolden@cpan.org> =head1 CONTRIBUTORS =for stopwords Alex Efros Aristotle Pagaltzis Chris Williams Dan Book Dave Rolsky David Steinbrunner Doug Bell Elvin Aslanov Flavio Poletti Gabor Szabo Gabriel Andrade George Hartzell Geraud Continsouzas Goro Fuji Graham Knop Ollis Ian Sillitoe James Hunt John Karr Karen Etheridge Mark Ellis Martin H. Sluka Kjeldsen Mary Ehlers Michael G. Schwern Nicolas R Rochelemagne Nigel Gregoire Philippe Bruhat (BooK) regina-verbae Roy Ivy III Shlomi Fish Smylers Tatsuhiko Miyagawa Toby Inkster Yanick Champoux 김도형 - Keedi Kim =over 4 =item * Alex Efros <powerman@powerman.name> =item * Aristotle Pagaltzis <pagaltzis@gmx.de> =item * Chris Williams <bingos@cpan.org> =item * Dan Book <grinnz@grinnz.com> =item * Dave Rolsky <autarch@urth.org> =item * David Steinbrunner <dsteinbrunner@pobox.com> =item * Doug Bell <madcityzen@gmail.com> =item * Elvin Aslanov <rwp.primary@gmail.com> =item * Flavio Poletti <flavio@polettix.it> =item * Gabor Szabo <szabgab@cpan.org> =item * Gabriel Andrade <gabiruh@gmail.com> =item * George Hartzell <hartzell@cpan.org> =item * Geraud Continsouzas <geraud@scsi.nc> =item * Goro Fuji <gfuji@cpan.org> =item * Graham Knop <haarg@haarg.org> =item * Graham Ollis <plicease@cpan.org> =item * Ian Sillitoe <ian@sillit.com> =item * James Hunt <james@niftylogic.com> =item * John Karr <brainbuz@brainbuz.org> =item * Karen Etheridge <ether@cpan.org> =item * Mark Ellis <mark.ellis@cartridgesave.co.uk> =item * Martin H. Sluka <fany@cpan.org> =item * Martin Kjeldsen <mk@bluepipe.dk> =item * Mary Ehlers <regina.verb.ae@gmail.com> =item * Michael G. Schwern <mschwern@cpan.org> =item * Nicolas R <nicolas@atoomic.org> =item * Nicolas Rochelemagne <rochelemagne@cpanel.net> =item * Nigel Gregoire <nigelgregoire@gmail.com> =item * Philippe Bruhat (BooK) <book@cpan.org> =item * regina-verbae <regina-verbae@users.noreply.github.com> =item * Roy Ivy III <rivy@cpan.org> =item * Shlomi Fish <shlomif@shlomifish.org> =item * Smylers <Smylers@stripey.com> =item * Tatsuhiko Miyagawa <miyagawa@bulknews.net> =item * Toby Inkster <tobyink@cpan.org> =item * Yanick Champoux <yanick@babyl.dyndns.org> =item * 김도형 - Keedi Kim <keedi@cpan.org> =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut MYMETA.json 0000644 00000013212 15125124546 0006437 0 ustar 00 { "abstract" : "File path utility", "author" : [ "David Golden <dagolden@cpan.org>" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.031, CPAN::Meta::Converter version 2.150010", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Path-Tiny", "no_index" : { "directory" : [ "corpus", "examples", "t", "xt" ], "package" : [ "DB", "flock" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" }, "suggests" : { "JSON::PP" : "2.27300" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::Plugin::MinimumPerl" : "0", "Dist::Zilla::Plugin::OnlyCorePrereqs" : "0", "Dist::Zilla::Plugin::Prereqs" : "0", "Dist::Zilla::Plugin::ReleaseStatus::FromVersion" : "0", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Pod::Wordlist" : "0", "Software::License::Apache_2_0" : "0", "Test::CPAN::Meta" : "0", "Test::MinimumVersion" : "0", "Test::More" : "0", "Test::Perl::Critic" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Portability::Files" : "0", "Test::Spelling" : "0.12", "Test::Version" : "1" } }, "runtime" : { "recommends" : { "Unicode::UTF8" : "0.58" }, "requires" : { "Carp" : "0", "Cwd" : "0", "Digest" : "1.03", "Digest::SHA" : "5.45", "Encode" : "0", "Exporter" : "5.57", "Fcntl" : "0", "File::Compare" : "0", "File::Copy" : "0", "File::Glob" : "0", "File::Path" : "2.07", "File::Spec" : "0.86", "File::Temp" : "0.19", "File::stat" : "0", "constant" : "0", "overload" : "0", "perl" : "5.008001", "strict" : "0", "warnings" : "0", "warnings::register" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900", "Test::FailWarnings" : "0", "Test::MockRandom" : "0" }, "requires" : { "Digest::MD5" : "0", "ExtUtils::MakeMaker" : "0", "File::Basename" : "0", "File::Spec" : "0.86", "File::Spec::Functions" : "0", "File::Spec::Unix" : "0", "File::Temp" : "0.19", "Test::More" : "0.96", "lib" : "0", "open" : "0" } } }, "provides" : { "Path::Tiny" : { "file" : "lib/Path/Tiny.pm", "version" : "0.146" }, "Path::Tiny::Error" : { "file" : "lib/Path/Tiny.pm", "version" : "0.146" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/Path-Tiny/issues" }, "homepage" : "https://github.com/dagolden/Path-Tiny", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/Path-Tiny.git", "web" : "https://github.com/dagolden/Path-Tiny" } }, "version" : "0.146", "x_authority" : "cpan:DAGOLDEN", "x_contributors" : [ "Alex Efros <powerman@powerman.name>", "Aristotle Pagaltzis <pagaltzis@gmx.de>", "Chris Williams <bingos@cpan.org>", "Dan Book <grinnz@grinnz.com>", "Dave Rolsky <autarch@urth.org>", "David Steinbrunner <dsteinbrunner@pobox.com>", "Doug Bell <madcityzen@gmail.com>", "Elvin Aslanov <rwp.primary@gmail.com>", "Flavio Poletti <flavio@polettix.it>", "Gabor Szabo <szabgab@cpan.org>", "Gabriel Andrade <gabiruh@gmail.com>", "George Hartzell <hartzell@cpan.org>", "Geraud Continsouzas <geraud@scsi.nc>", "Goro Fuji <gfuji@cpan.org>", "Graham Knop <haarg@haarg.org>", "Graham Ollis <plicease@cpan.org>", "Ian Sillitoe <ian@sillit.com>", "James Hunt <james@niftylogic.com>", "John Karr <brainbuz@brainbuz.org>", "Karen Etheridge <ether@cpan.org>", "Mark Ellis <mark.ellis@cartridgesave.co.uk>", "Martin H. Sluka <fany@cpan.org>", "Martin Kjeldsen <mk@bluepipe.dk>", "Mary Ehlers <regina.verb.ae@gmail.com>", "Michael G. Schwern <mschwern@cpan.org>", "Nicolas R <nicolas@atoomic.org>", "Nicolas Rochelemagne <rochelemagne@cpanel.net>", "Nigel Gregoire <nigelgregoire@gmail.com>", "Philippe Bruhat (BooK) <book@cpan.org>", "regina-verbae <regina-verbae@users.noreply.github.com>", "Roy Ivy III <rivy@cpan.org>", "Shlomi Fish <shlomif@shlomifish.org>", "Smylers <Smylers@stripey.com>", "Tatsuhiko Miyagawa <miyagawa@bulknews.net>", "Toby Inkster <tobyink@cpan.org>", "Yanick Champoux <yanick@babyl.dyndns.org>", "김도형 - Keedi Kim <keedi@cpan.org>" ], "x_generated_by_perl" : "v5.36.0", "x_serialization_backend" : "JSON::PP version 4.06", "x_spdx_expression" : "Apache-2.0" } README 0000644 00000132444 15125124546 0005441 0 ustar 00 NAME Path::Tiny - File path utility VERSION version 0.146 SYNOPSIS use Path::Tiny; # Creating Path::Tiny objects my $dir = path("/tmp"); my $foo = path("foo.txt"); my $subdir = $dir->child("foo"); my $bar = $subdir->child("bar.txt"); # Stringifies as cleaned up path my $file = path("./foo.txt"); print $file; # "foo.txt" # Reading files my $guts = $file->slurp; $guts = $file->slurp_utf8; my @lines = $file->lines; @lines = $file->lines_utf8; my ($head) = $file->lines( {count => 1} ); my ($tail) = $file->lines( {count => -1} ); # Writing files $bar->spew( @data ); $bar->spew_utf8( @data ); # Reading directories for ( $dir->children ) { ... } my $iter = $dir->iterator; while ( my $next = $iter->() ) { ... } DESCRIPTION This module provides a small, fast utility for working with file paths. It is friendlier to use than File::Spec and provides easy access to functions from several other core file handling modules. It aims to be smaller and faster than many alternatives on CPAN, while helping people do many common things in consistent and less error-prone ways. Path::Tiny does not try to work for anything except Unix-like and Win32 platforms. Even then, it might break if you try something particularly obscure or tortuous. (Quick! What does this mean: "///../../..//./././a//b/.././c/././"? And how does it differ on Win32?) All paths are forced to have Unix-style forward slashes. Stringifying the object gives you back the path (after some clean up). File input/output methods "flock" handles before reading or writing, as appropriate (if supported by the platform and/or filesystem). The *_utf8 methods ("slurp_utf8", "lines_utf8", etc.) operate in raw mode. On Windows, that means they will not have CRLF translation from the ":crlf" IO layer. Installing Unicode::UTF8 0.58 or later will speed up *_utf8 situations in many cases and is highly recommended. Alternatively, installing PerlIO::utf8_strict 0.003 or later will be used in place of the default ":encoding(UTF-8)". This module depends heavily on PerlIO layers for correct operation and thus requires Perl 5.008001 or later. CONSTRUCTORS path $path = path("foo/bar"); $path = path("/tmp", "file.txt"); # list $path = path("."); # cwd Constructs a "Path::Tiny" object. It doesn't matter if you give a file or directory path. It's still up to you to call directory-like methods only on directories and file-like methods only on files. This function is exported automatically by default. The first argument must be defined and have non-zero length or an exception will be thrown. This prevents subtle, dangerous errors with code like "path( maybe_undef() )->remove_tree". DEPRECATED: If and only if the first character of the first argument to "path" is a tilde ('~'), then tilde replacement will be applied to the first path segment. A single tilde will be replaced with "glob('~')" and a tilde followed by a username will be replaced with output of "glob('~username')". No other method does tilde expansion on its arguments. See "Tilde expansion (deprecated)" for more. On Windows, if the path consists of a drive identifier without a path component ("C:" or "D:"), it will be expanded to the absolute path of the current directory on that volume using "Cwd::getdcwd()". If called with a single "Path::Tiny" argument, the original is returned unless the original is holding a temporary file or directory reference in which case a stringified copy is made. $path = path("foo/bar"); $temp = Path::Tiny->tempfile; $p2 = path($path); # like $p2 = $path $t2 = path($temp); # like $t2 = path( "$temp" ) This optimizes copies without proliferating references unexpectedly if a copy is made by code outside your control. Current API available since 0.017. new $path = Path::Tiny->new("foo/bar"); This is just like "path", but with method call overhead. (Why would you do that?) Current API available since 0.001. cwd $path = Path::Tiny->cwd; # path( Cwd::getcwd ) $path = cwd; # optional export Gives you the absolute path to the current directory as a "Path::Tiny" object. This is slightly faster than "path(".")->absolute". "cwd" may be exported on request and used as a function instead of as a method. Current API available since 0.018. rootdir $path = Path::Tiny->rootdir; # / $path = rootdir; # optional export Gives you "File::Spec->rootdir" as a "Path::Tiny" object if you're too picky for "path("/")". "rootdir" may be exported on request and used as a function instead of as a method. Current API available since 0.018. tempfile, tempdir $temp = Path::Tiny->tempfile( @options ); $temp = Path::Tiny->tempdir( @options ); $temp = $dirpath->tempfile( @options ); $temp = $dirpath->tempdir( @options ); $temp = tempfile( @options ); # optional export $temp = tempdir( @options ); # optional export "tempfile" passes the options to "File::Temp->new" and returns a "Path::Tiny" object with the file name. The "TMPDIR" option will be enabled by default, but you can override that by passing "TMPDIR => 0" along with the options. (If you use an absolute "TEMPLATE" option, you will want to disable "TMPDIR".) The resulting "File::Temp" object is cached. When the "Path::Tiny" object is destroyed, the "File::Temp" object will be as well. "File::Temp" annoyingly requires you to specify a custom template in slightly different ways depending on which function or method you call, but "Path::Tiny" lets you ignore that and can take either a leading template or a "TEMPLATE" option and does the right thing. $temp = Path::Tiny->tempfile( "customXXXXXXXX" ); # ok $temp = Path::Tiny->tempfile( TEMPLATE => "customXXXXXXXX" ); # ok The tempfile path object will be normalized to have an absolute path, even if created in a relative directory using "DIR". If you want it to have the "realpath" instead, pass a leading options hash like this: $real_temp = tempfile({realpath => 1}, @options); "tempdir" is just like "tempfile", except it calls "File::Temp->newdir" instead. Both "tempfile" and "tempdir" may be exported on request and used as functions instead of as methods. The methods can be called on an instances representing a directory. In this case, the directory is used as the base to create the temporary file/directory, setting the "DIR" option in File::Temp. my $target_dir = path('/to/destination'); my $tempfile = $target_dir->tempfile('foobarXXXXXX'); $tempfile->spew('A lot of data...'); # not atomic $tempfile->move($target_dir->child('foobar')); # hopefully atomic In this case, any value set for option "DIR" is ignored. Note: for tempfiles, the filehandles from File::Temp are closed and not reused. This is not as secure as using File::Temp handles directly, but is less prone to deadlocks or access problems on some platforms. Think of what "Path::Tiny" gives you to be just a temporary file name that gets cleaned up. Note 2: if you don't want these cleaned up automatically when the object is destroyed, File::Temp requires different options for directories and files. Use "CLEANUP => 0" for directories and "UNLINK => 0" for files. Note 3: Don't lose the temporary object by chaining a method call instead of storing it: my $lost = tempdir()->child("foo"); # tempdir cleaned up right away Note 4: The cached object may be accessed with the "cached_temp" method. Keeping a reference to, or modifying the cached object may break the behavior documented above and is not supported. Use at your own risk. Current API available since 0.119. METHODS absolute $abs = path("foo/bar")->absolute; $abs = path("foo/bar")->absolute("/tmp"); Returns a new "Path::Tiny" object with an absolute path (or itself if already absolute). If no argument is given, the current directory is used as the absolute base path. If an argument is given, it will be converted to an absolute path (if it is not already) and used as the absolute base path. This will not resolve upward directories ("foo/../bar") unless "canonpath" in File::Spec would normally do so on your platform. If you need them resolved, you must call the more expensive "realpath" method instead. On Windows, an absolute path without a volume component will have it added based on the current drive. Current API available since 0.101. append, append_raw, append_utf8 path("foo.txt")->append(@data); path("foo.txt")->append(\@data); path("foo.txt")->append({binmode => ":raw"}, @data); path("foo.txt")->append_raw(@data); path("foo.txt")->append_utf8(@data); Appends data to a file. The file is locked with "flock" prior to writing and closed afterwards. An optional hash reference may be used to pass options. Valid options are: * "binmode": passed to "binmode()" on the handle used for writing. * "truncate": truncates the file after locking and before appending The "truncate" option is a way to replace the contents of a file in place, unlike "spew" which writes to a temporary file and then replaces the original (if it exists). "append_raw" is like "append" with a "binmode" of ":unix" for a fast, unbuffered, raw write. "append_utf8" is like "append" with an unbuffered "binmode" ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, an unbuffered, raw append will be done instead on the data encoded with "Unicode::UTF8". Current API available since 0.060. assert $path = path("foo.txt")->assert( sub { $_->exists } ); Returns the invocant after asserting that a code reference argument returns true. When the assertion code reference runs, it will have the invocant object in the $_ variable. If it returns false, an exception will be thrown. The assertion code reference may also throw its own exception. If no assertion is provided, the invocant is returned without error. Current API available since 0.062. basename $name = path("foo/bar.txt")->basename; # bar.txt $name = path("foo.txt")->basename('.txt'); # foo $name = path("foo.txt")->basename(qr/.txt/); # foo $name = path("foo.txt")->basename(@suffixes); Returns the file portion or last directory portion of a path. Given a list of suffixes as strings or regular expressions, any that match at the end of the file portion or last directory portion will be removed before the result is returned. Current API available since 0.054. canonpath $canonical = path("foo/bar")->canonpath; # foo\bar on Windows Returns a string with the canonical format of the path name for the platform. In particular, this means directory separators will be "\" on Windows. Current API available since 0.001. cached_temp Returns the cached "File::Temp" or "File::Temp::Dir" object if the "Path::Tiny" object was created with "/tempfile" or "/tempdir". If there is no such object, this method throws. WARNING: Keeping a reference to, or modifying the cached object may break the behavior documented for temporary files and directories created with "Path::Tiny" and is not supported. Use at your own risk. Current API available since 0.101. child $file = path("/tmp")->child("foo.txt"); # "/tmp/foo.txt" $file = path("/tmp")->child(@parts); Returns a new "Path::Tiny" object relative to the original. Works like "catfile" or "catdir" from File::Spec, but without caring about file or directories. WARNING: because the argument could contain ".." or refer to symlinks, there is no guarantee that the new path refers to an actual descendent of the original. If this is important to you, transform parent and child with "realpath" and check them with "subsumes". Current API available since 0.001. children @paths = path("/tmp")->children; @paths = path("/tmp")->children( qr/\.txt\z/ ); Returns a list of "Path::Tiny" objects for all files and directories within a directory. Excludes "." and ".." automatically. If an optional "qr//" argument is provided, it only returns objects for child names that match the given regular expression. Only the base name is used for matching: @paths = path("/tmp")->children( qr/^foo/ ); # matches children like the glob foo* Current API available since 0.028. chmod path("foo.txt")->chmod(0777); path("foo.txt")->chmod("0755"); path("foo.txt")->chmod("go-w"); path("foo.txt")->chmod("a=r,u+wx"); Sets file or directory permissions. The argument can be a numeric mode, a octal string beginning with a "0" or a limited subset of the symbolic mode use by /bin/chmod. The symbolic mode must be a comma-delimited list of mode clauses. Clauses must match "qr/\A([augo]+)([=+-])([rwx]+)\z/", which defines "who", "op" and "perms" parameters for each clause. Unlike /bin/chmod, all three parameters are required for each clause, multiple ops are not allowed and permissions "stugoX" are not supported. (See File::chmod for more complex needs.) Current API available since 0.053. copy path("/tmp/foo.txt")->copy("/tmp/bar.txt"); Copies the current path to the given destination using File::Copy's "copy" function. Upon success, returns the "Path::Tiny" object for the newly copied file. Current API available since 0.070. digest $obj = path("/tmp/foo.txt")->digest; # SHA-256 $obj = path("/tmp/foo.txt")->digest("MD5"); # user-selected $obj = path("/tmp/foo.txt")->digest( { chunk_size => 1e6 }, "MD5" ); Returns a hexadecimal digest for a file. An optional hash reference of options may be given. The only option is "chunk_size". If "chunk_size" is given, that many bytes will be read at a time. If not provided, the entire file will be slurped into memory to compute the digest. Any subsequent arguments are passed to the constructor for Digest to select an algorithm. If no arguments are given, the default is SHA-256. Current API available since 0.056. dirname (deprecated) $name = path("/tmp/foo.txt")->dirname; # "/tmp/" Returns the directory portion you would get from calling "File::Spec->splitpath( $path->stringify )" or "." for a path without a parent directory portion. Because File::Spec is inconsistent, the result might or might not have a trailing slash. Because of this, this method is deprecated. A better, more consistently approach is likely "$path->parent->stringify", which will not have a trailing slash except for a root directory. Deprecated in 0.056. edit, edit_raw, edit_utf8 path("foo.txt")->edit( \&callback, $options ); path("foo.txt")->edit_utf8( \&callback ); path("foo.txt")->edit_raw( \&callback ); These are convenience methods that allow "editing" a file using a single callback argument. They slurp the file using "slurp", place the contents inside a localized $_ variable, call the callback function (without arguments), and then write $_ (presumably mutated) back to the file with "spew". An optional hash reference may be used to pass options. The only option is "binmode", which is passed to "slurp" and "spew". "edit_utf8" and "edit_raw" act like their respective "slurp_*" and "spew_*" methods. Current API available since 0.077. edit_lines, edit_lines_utf8, edit_lines_raw path("foo.txt")->edit_lines( \&callback, $options ); path("foo.txt")->edit_lines_utf8( \&callback ); path("foo.txt")->edit_lines_raw( \&callback ); These are convenience methods that allow "editing" a file's lines using a single callback argument. They iterate over the file: for each line, the line is put into a localized $_ variable, the callback function is executed (without arguments) and then $_ is written to a temporary file. When iteration is finished, the temporary file is atomically renamed over the original. An optional hash reference may be used to pass options. The only option is "binmode", which is passed to the method that open handles for reading and writing. "edit_lines_raw" is like "edit_lines" with a buffered "binmode" of ":raw". "edit_lines_utf8" is like "edit_lines" with a buffered "binmode" ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). Current API available since 0.077. exists, is_file, is_dir if ( path("/tmp")->exists ) { ... } # -e if ( path("/tmp")->is_dir ) { ... } # -d if ( path("/tmp")->is_file ) { ... } # -e && ! -d Implements file test operations, this means the file or directory actually has to exist on the filesystem. Until then, it's just a path. Note: "is_file" is not "-f" because "-f" is not the opposite of "-d". "-f" means "plain file", excluding symlinks, devices, etc. that often can be read just like files. Use "-f" instead if you really mean to check for a plain file. Current API available since 0.053. filehandle $fh = path("/tmp/foo.txt")->filehandle($mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ locked => 1 }, $mode, $binmode); $fh = path("/tmp/foo.txt")->filehandle({ exclusive => 1 }, $mode, $binmode); Returns an open file handle. The $mode argument must be a Perl-style read/write mode string ("<" ,">", ">>", etc.). If a $binmode is given, it is set during the "open" call. An optional hash reference may be used to pass options. The "locked" option governs file locking; if true, handles opened for writing, appending or read-write are locked with "LOCK_EX"; otherwise, they are locked with "LOCK_SH". When using "locked", ">" or "+>" modes will delay truncation until after the lock is acquired. The "exclusive" option causes the open() call to fail if the file already exists. This corresponds to the O_EXCL flag to sysopen / open(2). "exclusive" implies "locked" and will set it for you if you forget it. See "openr", "openw", "openrw", and "opena" for sugar. Current API available since 0.066. has_same_bytes if ( path("foo.txt")->has_same_bytes("bar.txt") ) { # ... } This method returns true if both the invocant and the argument can be opened as file handles and the handles contain the same bytes. It returns false if their contents differ. If either can't be opened as a file (e.g. a directory or non-existent file), the method throws an exception. If both can be opened and both have the same "realpath", the method returns true without scanning any data. Current API available since 0.125. is_absolute, is_relative if ( path("/tmp")->is_absolute ) { ... } if ( path("/tmp")->is_relative ) { ... } Booleans for whether the path appears absolute or relative. Current API available since 0.001. is_rootdir while ( ! $path->is_rootdir ) { $path = $path->parent; ... } Boolean for whether the path is the root directory of the volume. I.e. the "dirname" is "q[/]" and the "basename" is "q[]". This works even on "MSWin32" with drives and UNC volumes: path("C:/")->is_rootdir; # true path("//server/share/")->is_rootdir; #true Current API available since 0.038. iterator $iter = path("/tmp")->iterator( \%options ); Returns a code reference that walks a directory lazily. Each invocation returns a "Path::Tiny" object or undef when the iterator is exhausted. $iter = path("/tmp")->iterator; while ( $path = $iter->() ) { ... } The current and parent directory entries ("." and "..") will not be included. If the "recurse" option is true, the iterator will walk the directory recursively, breadth-first. If the "follow_symlinks" option is also true, directory links will be followed recursively. There is no protection against loops when following links. If a directory is not readable, it will not be followed. The default is the same as: $iter = path("/tmp")->iterator( { recurse => 0, follow_symlinks => 0, } ); For a more powerful, recursive iterator with built-in loop avoidance, see Path::Iterator::Rule. See also "visit". Current API available since 0.016. lines, lines_raw, lines_utf8 @contents = path("/tmp/foo.txt")->lines; @contents = path("/tmp/foo.txt")->lines(\%options); @contents = path("/tmp/foo.txt")->lines_raw; @contents = path("/tmp/foo.txt")->lines_utf8; @contents = path("/tmp/foo.txt")->lines( { chomp => 1, count => 4 } ); Returns a list of lines from a file. Optionally takes a hash-reference of options. Valid options are "binmode", "count" and "chomp". If "binmode" is provided, it will be set on the handle prior to reading. If a positive "count" is provided, that many lines will be returned from the start of the file. If a negative "count" is provided, the entire file will be read, but only "abs(count)" will be kept and returned. If "abs(count)" exceeds the number of lines in the file, all lines will be returned. If "chomp" is set, any end-of-line character sequences ("CR", "CRLF", or "LF") will be removed from the lines returned. Because the return is a list, "lines" in scalar context will return the number of lines (and throw away the data). $number_of_lines = path("/tmp/foo.txt")->lines; "lines_raw" is like "lines" with a "binmode" of ":raw". We use ":raw" instead of ":unix" so PerlIO buffering can manage reading by line. "lines_utf8" is like "lines" with a "binmode" of ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered UTF-8 slurp will be done and then the lines will be split. This is actually faster than relying on IO layers, though a bit memory intensive. If memory use is a concern, consider "openr_utf8" and iterating directly on the handle. Current API available since 0.065. mkdir path("foo/bar/baz")->mkdir; path("foo/bar/baz")->mkdir( \%options ); Like calling "make_path" from File::Path. An optional hash reference is passed through to "make_path". Errors will be trapped and an exception thrown. Returns the the path object to facilitate chaining. NOTE: unlike Perl's builtin "mkdir", this will create intermediate paths similar to the Unix "mkdir -p" command. It will not error if applied to an existing directory. Current API available since 0.125. mkpath (deprecated) Like calling "mkdir", but returns the list of directories created or an empty list if the directories already exist, just like "make_path". Deprecated in 0.125. move path("foo.txt")->move("bar.txt"); Moves the current path to the given destination using File::Copy's "move" function. Upon success, returns the "Path::Tiny" object for the newly moved file. If the destination already exists and is a directory, and the source is not a directory, then the source file will be renamed into the directory specified by the destination. If possible, move() will simply rename the file. Otherwise, it copies the file to the new location and deletes the original. If an error occurs during this copy-and-delete process, you may be left with a (possibly partial) copy of the file under the destination name. Current API available since 0.124. Prior versions used Perl's -built-in (and less robust) rename function and did not return an object. openr, openw, openrw, opena $fh = path("foo.txt")->openr($binmode); # read $fh = path("foo.txt")->openr_raw; $fh = path("foo.txt")->openr_utf8; $fh = path("foo.txt")->openw($binmode); # write $fh = path("foo.txt")->openw_raw; $fh = path("foo.txt")->openw_utf8; $fh = path("foo.txt")->opena($binmode); # append $fh = path("foo.txt")->opena_raw; $fh = path("foo.txt")->opena_utf8; $fh = path("foo.txt")->openrw($binmode); # read/write $fh = path("foo.txt")->openrw_raw; $fh = path("foo.txt")->openrw_utf8; Returns a file handle opened in the specified mode. The "openr" style methods take a single "binmode" argument. All of the "open*" methods have "open*_raw" and "open*_utf8" equivalents that use buffered I/O layers ":raw" and ":raw:encoding(UTF-8)" (or ":raw:utf8_strict" with PerlIO::utf8_strict). An optional hash reference may be used to pass options. The only option is "locked". If true, handles opened for writing, appending or read-write are locked with "LOCK_EX"; otherwise, they are locked for "LOCK_SH". $fh = path("foo.txt")->openrw_utf8( { locked => 1 } ); See "filehandle" for more on locking. Current API available since 0.011. parent $parent = path("foo/bar/baz")->parent; # foo/bar $parent = path("foo/wibble.txt")->parent; # foo $parent = path("foo/bar/baz")->parent(2); # foo Returns a "Path::Tiny" object corresponding to the parent directory of the original directory or file. An optional positive integer argument is the number of parent directories upwards to return. "parent" by itself is equivalent to parent(1). Current API available since 0.014. realpath $real = path("/baz/foo/../bar")->realpath; $real = path("foo/../bar")->realpath; Returns a new "Path::Tiny" object with all symbolic links and upward directory parts resolved using Cwd's "realpath". Compared to "absolute", this is more expensive as it must actually consult the filesystem. If the parent path can't be resolved (e.g. if it includes directories that don't exist), an exception will be thrown: $real = path("doesnt_exist/foo")->realpath; # dies However, if the parent path exists and only the last component (e.g. filename) doesn't exist, the realpath will be the realpath of the parent plus the non-existent last component: $real = path("./aasdlfasdlf")->realpath; # works The underlying Cwd module usually worked this way on Unix, but died on Windows (and some Unixes) if the full path didn't exist. As of version 0.064, it's safe to use anywhere. Current API available since 0.001. relative $rel = path("/tmp/foo/bar")->relative("/tmp"); # foo/bar Returns a "Path::Tiny" object with a path relative to a new base path given as an argument. If no argument is given, the current directory will be used as the new base path. If either path is already relative, it will be made absolute based on the current directly before determining the new relative path. The algorithm is roughly as follows: * If the original and new base path are on different volumes, an exception will be thrown. * If the original and new base are identical, the relative path is ".". * If the new base subsumes the original, the relative path is the original path with the new base chopped off the front * If the new base does not subsume the original, a common prefix path is determined (possibly the root directory) and the relative path will consist of updirs ("..") to reach the common prefix, followed by the original path less the common prefix. Unlike "File::Spec::abs2rel", in the last case above, the calculation based on a common prefix takes into account symlinks that could affect the updir process. Given an original path "/A/B" and a new base "/A/C", (where "A", "B" and "C" could each have multiple path components): * Symlinks in "A" don't change the result unless the last component of A is a symlink and the first component of "C" is an updir. * Symlinks in "B" don't change the result and will exist in the result as given. * Symlinks and updirs in "C" must be resolved to actual paths, taking into account the possibility that not all path components might exist on the filesystem. Current API available since 0.001. New algorithm (that accounts for symlinks) available since 0.079. remove path("foo.txt")->remove; This is just like "unlink", except for its error handling: if the path does not exist, it returns false; if deleting the file fails, it throws an exception. Current API available since 0.012. remove_tree # directory path("foo/bar/baz")->remove_tree; path("foo/bar/baz")->remove_tree( \%options ); path("foo/bar/baz")->remove_tree( { safe => 0 } ); # force remove Like calling "remove_tree" from File::Path, but defaults to "safe" mode. An optional hash reference is passed through to "remove_tree". Errors will be trapped and an exception thrown. Returns the number of directories deleted, just like "remove_tree". If you want to remove a directory only if it is empty, use the built-in "rmdir" function instead. rmdir path("foo/bar/baz/"); Current API available since 0.013. sibling $foo = path("/tmp/foo.txt"); $sib = $foo->sibling("bar.txt"); # /tmp/bar.txt $sib = $foo->sibling("baz", "bam.txt"); # /tmp/baz/bam.txt Returns a new "Path::Tiny" object relative to the parent of the original. This is slightly more efficient than "$path->parent->child(...)". Current API available since 0.058. size, size_human my $p = path("foo"); # with size 1025 bytes $p->size; # "1025" $p->size_human; # "1.1 K" $p->size_human( {format => "iec"} ); # "1.1 KiB" Returns the size of a file. The "size" method is just a wrapper around "-s". The "size_human" method provides a human-readable string similar to "ls -lh". Like "ls", it rounds upwards and provides one decimal place for single-digit sizes and no decimal places for larger sizes. The only available option is "format", which has three valid values: * 'ls' (the default): base-2 sizes, with "ls" style single-letter suffixes (K, M, etc.) * 'iec': base-2 sizes, with IEC binary suffixes (KiB, MiB, etc.) * 'si': base-10 sizes, with SI decimal suffixes (kB, MB, etc.) If "-s" would return "undef", "size_human" returns the empty string. Current API available since 0.122. slurp, slurp_raw, slurp_utf8 $data = path("foo.txt")->slurp; $data = path("foo.txt")->slurp( {binmode => ":raw"} ); $data = path("foo.txt")->slurp_raw; $data = path("foo.txt")->slurp_utf8; Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is "binmode", which is passed to "binmode()" on the handle used for reading. "slurp_raw" is like "slurp" with a "binmode" of ":unix" for a fast, unbuffered, raw read. "slurp_utf8" is like "slurp" with a "binmode" of ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a unbuffered, raw slurp will be done instead and the result decoded with "Unicode::UTF8". This is just as strict and is roughly an order of magnitude faster than using ":encoding(UTF-8)". Note: "slurp" and friends lock the filehandle before slurping. If you plan to slurp from a file created with File::Temp, be sure to close other handles or open without locking to avoid a deadlock: my $tempfile = File::Temp->new(EXLOCK => 0); my $guts = path($tempfile)->slurp; Current API available since 0.004. spew, spew_raw, spew_utf8 path("foo.txt")->spew(@data); path("foo.txt")->spew(\@data); path("foo.txt")->spew({binmode => ":raw"}, @data); path("foo.txt")->spew_raw(@data); path("foo.txt")->spew_utf8(@data); Writes data to a file atomically. The file is written to a temporary file in the same directory, then renamed over the original. An optional hash reference may be used to pass options. The only option is "binmode", which is passed to "binmode()" on the handle used for writing. "spew_raw" is like "spew" with a "binmode" of ":unix" for a fast, unbuffered, raw write. "spew_utf8" is like "spew" with a "binmode" of ":unix:encoding(UTF-8)" (or ":unix:utf8_strict" with PerlIO::utf8_strict). If Unicode::UTF8 0.58+ is installed, a raw, unbuffered spew will be done instead on the data encoded with "Unicode::UTF8". NOTE: because the file is written to a temporary file and then renamed, the new file will wind up with permissions based on your current umask. This is a feature to protect you from a race condition that would otherwise give different permissions than you might expect. If you really want to keep the original mode flags, use "append" with the "truncate" option. Current API available since 0.011. stat, lstat $stat = path("foo.txt")->stat; $stat = path("/some/symlink")->lstat; Like calling "stat" or "lstat" from File::stat. Current API available since 0.001. stringify $path = path("foo.txt"); say $path->stringify; # same as "$path" Returns a string representation of the path. Unlike "canonpath", this method returns the path standardized with Unix-style "/" directory separators. Current API available since 0.001. subsumes path("foo/bar")->subsumes("foo/bar/baz"); # true path("/foo/bar")->subsumes("/foo/baz"); # false Returns true if the first path is a prefix of the second path at a directory boundary. This does not resolve parent directory entries ("..") or symlinks: path("foo/bar")->subsumes("foo/bar/../baz"); # true If such things are important to you, ensure that both paths are resolved to the filesystem with "realpath": my $p1 = path("foo/bar")->realpath; my $p2 = path("foo/bar/../baz")->realpath; if ( $p1->subsumes($p2) ) { ... } Current API available since 0.048. touch path("foo.txt")->touch; path("foo.txt")->touch($epoch_secs); Like the Unix "touch" utility. Creates the file if it doesn't exist, or else changes the modification and access times to the current time. If the first argument is the epoch seconds then it will be used. Returns the path object so it can be easily chained with other methods: # won't die if foo.txt doesn't exist $content = path("foo.txt")->touch->slurp; Current API available since 0.015. touchpath path("bar/baz/foo.txt")->touchpath; Combines "mkdir" and "touch". Creates the parent directory if it doesn't exist, before touching the file. Returns the path object like "touch" does. If you need to pass options, use "mkdir" and "touch" separately: path("bar/baz")->mkdir( \%options )->child("foo.txt")->touch($epoch_secs); Current API available since 0.022. visit path("/tmp")->visit( \&callback, \%options ); Executes a callback for each child of a directory. It returns a hash reference with any state accumulated during iteration. The options are the same as for "iterator" (which it uses internally): "recurse" and "follow_symlinks". Both default to false. The callback function will receive a "Path::Tiny" object as the first argument and a hash reference to accumulate state as the second argument. For example: # collect files sizes my $sizes = path("/tmp")->visit( sub { my ($path, $state) = @_; return if $path->is_dir; $state->{$path} = -s $path; }, { recurse => 1 } ); For convenience, the "Path::Tiny" object will also be locally aliased as the $_ global variable: # print paths matching /foo/ path("/tmp")->visit( sub { say if /foo/ }, { recurse => 1} ); If the callback returns a reference to a false scalar value, iteration will terminate. This is not the same as "pruning" a directory search; this just stops all iteration and returns the state hash reference. # find up to 10 files larger than 100K my $files = path("/tmp")->visit( sub { my ($path, $state) = @_; $state->{$path}++ if -s $path > 102400 return \0 if keys %$state == 10; }, { recurse => 1 } ); If you want more flexible iteration, use a module like Path::Iterator::Rule. Current API available since 0.062. volume $vol = path("/tmp/foo.txt")->volume; # "" $vol = path("C:/tmp/foo.txt")->volume; # "C:" Returns the volume portion of the path. This is equivalent to what File::Spec would give from "splitpath" and thus usually is the empty string on Unix-like operating systems or the drive letter for an absolute path on "MSWin32". Current API available since 0.001. EXCEPTION HANDLING Simple usage errors will generally croak. Failures of underlying Perl functions will be thrown as exceptions in the class "Path::Tiny::Error". A "Path::Tiny::Error" object will be a hash reference with the following fields: * "op" — a description of the operation, usually function call and any extra info * "file" — the file or directory relating to the error * "err" — hold $! at the time the error was thrown * "msg" — a string combining the above data and a Carp-like short stack trace Exception objects will stringify as the "msg" field. ENVIRONMENT PERL_PATH_TINY_NO_FLOCK If the environment variable "PERL_PATH_TINY_NO_FLOCK" is set to a true value then flock will NOT be used when accessing files (this is not recommended). CAVEATS Subclassing not supported For speed, this class is implemented as an array based object and uses many direct function calls internally. You must not subclass it and expect things to work properly. Tilde expansion (deprecated) Tilde expansion was a nice idea, but it can't easily be applied consistently across the entire API. This was a source of bugs and confusion for users. Therefore, it is deprecated and its use is discouraged. Limitations to the existing, legacy behavior follow. Tilde expansion will only occur if the first argument to "path" begins with a tilde. No other method does tilde expansion on its arguments. If you want tilde expansion on arguments, you must explicitly wrap them in a call to "path". path( "~/foo.txt" )->copy( path( "~/bar.txt" ) ); If you need a literal leading tilde, use "path("./~whatever")" so that the argument to "path" doesn't start with a tilde, but the path still resolves to the current directory. Behaviour of tilde expansion with a username for non-existent users depends on the output of "glob" on the system. File locking If flock is not supported on a platform, it will not be used, even if locking is requested. In situations where a platform normally would support locking, but the flock fails due to a filesystem limitation, Path::Tiny has some heuristics to detect this and will warn once and continue in an unsafe mode. If you want this failure to be fatal, you can fatalize the 'flock' warnings category: use warnings FATAL => 'flock'; See additional caveats below. NFS and BSD On BSD, Perl's flock implementation may not work to lock files on an NFS filesystem. If detected, this situation will warn once, as described above. Lustre The Lustre filesystem does not support flock. If detected, this situation will warn once, as described above. AIX and locking AIX requires a write handle for locking. Therefore, calls that normally open a read handle and take a shared lock instead will open a read-write handle and take an exclusive lock. If the user does not have write permission, no lock will be used. utf8 vs UTF-8 All the *_utf8 methods by default use ":encoding(UTF-8)" -- either as ":unix:encoding(UTF-8)" (unbuffered, for whole file operations) or ":raw:encoding(UTF-8)" (buffered, for line-by-line operations). These are strict against the Unicode spec and disallows illegal Unicode codepoints or UTF-8 sequences. Unfortunately, ":encoding(UTF-8)" is very, very slow. If you install Unicode::UTF8 0.58 or later, that module will be used by some *_utf8 methods to encode or decode data after a raw, binary input/output operation, which is much faster. Alternatively, if you install PerlIO::utf8_strict, that will be used instead of ":encoding(UTF-8)" and is also very fast. If you need the performance and can accept the security risk, "slurp({binmode => ":unix:utf8"})" will be faster than ":unix:encoding(UTF-8)" (but not as fast as "Unicode::UTF8"). Note that the *_utf8 methods read in raw mode. There is no CRLF translation on Windows. If you must have CRLF translation, use the regular input/output methods with an appropriate binmode: $path->spew_utf8($data); # raw $path->spew({binmode => ":encoding(UTF-8)"}, $data; # LF -> CRLF Default IO layers and the open pragma If you have Perl 5.10 or later, file input/output methods ("slurp", "spew", etc.) and high-level handle opening methods ( "filehandle", "openr", "openw", etc. ) respect default encodings set by the "-C" switch or lexical open settings of the caller. For UTF-8, this is almost certainly slower than using the dedicated "_utf8" methods if you have Unicode::UTF8 or PerlIP::utf8_strict. TYPE CONSTRAINTS AND COERCION A standard MooseX::Types library is available at MooseX::Types::Path::Tiny. A Type::Tiny equivalent is available as Types::Path::Tiny. SEE ALSO These are other file/path utilities, which may offer a different feature set than "Path::Tiny". * File::chmod * File::Fu * IO::All * Path::Class These iterators may be slightly faster than the recursive iterator in "Path::Tiny": * Path::Iterator::Rule * File::Next There are probably comparable, non-Tiny tools. Let me know if you want me to add a module to the list. This module was featured in the 2013 Perl Advent Calendar <http://www.perladvent.org/2013/2013-12-18.html>. SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Path-Tiny/issues>. You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/dagolden/Path-Tiny> git clone https://github.com/dagolden/Path-Tiny.git AUTHOR David Golden <dagolden@cpan.org> CONTRIBUTORS * Alex Efros <powerman@powerman.name> * Aristotle Pagaltzis <pagaltzis@gmx.de> * Chris Williams <bingos@cpan.org> * Dan Book <grinnz@grinnz.com> * Dave Rolsky <autarch@urth.org> * David Steinbrunner <dsteinbrunner@pobox.com> * Doug Bell <madcityzen@gmail.com> * Elvin Aslanov <rwp.primary@gmail.com> * Flavio Poletti <flavio@polettix.it> * Gabor Szabo <szabgab@cpan.org> * Gabriel Andrade <gabiruh@gmail.com> * George Hartzell <hartzell@cpan.org> * Geraud Continsouzas <geraud@scsi.nc> * Goro Fuji <gfuji@cpan.org> * Graham Knop <haarg@haarg.org> * Graham Ollis <plicease@cpan.org> * Ian Sillitoe <ian@sillit.com> * James Hunt <james@niftylogic.com> * John Karr <brainbuz@brainbuz.org> * Karen Etheridge <ether@cpan.org> * Mark Ellis <mark.ellis@cartridgesave.co.uk> * Martin H. Sluka <fany@cpan.org> * Martin Kjeldsen <mk@bluepipe.dk> * Mary Ehlers <regina.verb.ae@gmail.com> * Michael G. Schwern <mschwern@cpan.org> * Nicolas R <nicolas@atoomic.org> * Nicolas Rochelemagne <rochelemagne@cpanel.net> * Nigel Gregoire <nigelgregoire@gmail.com> * Philippe Bruhat (BooK) <book@cpan.org> * regina-verbae <regina-verbae@users.noreply.github.com> * Roy Ivy III <rivy@cpan.org> * Shlomi Fish <shlomif@shlomifish.org> * Smylers <Smylers@stripey.com> * Tatsuhiko Miyagawa <miyagawa@bulknews.net> * Toby Inkster <tobyink@cpan.org> * Yanick Champoux <yanick@babyl.dyndns.org> * 김도형 - Keedi Kim <keedi@cpan.org> COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0.02 |
proxy
|
phpinfo
|
???????????