summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2015-06-28 17:50:34 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2015-06-28 17:50:34 +0000
commitb7fb38421c30b0419a30311c1bde34706aa60fb8 (patch)
tree57f2bcea8db83589377c8bc0253a10c66df46d72
downloadPath-Tiny-tarball-master.tar.gz
-rw-r--r--CONTRIBUTING.mkdn87
-rw-r--r--Changes643
-rw-r--r--LICENSE207
-rw-r--r--MANIFEST51
-rw-r--r--META.json149
-rw-r--r--META.yml91
-rw-r--r--Makefile.PL94
-rw-r--r--README970
-rw-r--r--cpanfile62
-rw-r--r--dist.ini58
-rw-r--r--lib/Path/Tiny.pm2893
-rw-r--r--perlcritic.rc26
-rw-r--r--t/00-report-prereqs.dd74
-rw-r--r--t/00-report-prereqs.t183
-rw-r--r--t/README3
-rw-r--r--t/basename.t39
-rw-r--r--t/basic.t185
-rw-r--r--t/children.t51
-rw-r--r--t/chmod.t48
-rw-r--r--t/data/chmod.txt1171
-rw-r--r--t/digest.t51
-rw-r--r--t/exception.t46
-rw-r--r--t/exports.t27
-rw-r--r--t/filesystem.t415
-rw-r--r--t/input_output.t497
-rw-r--r--t/input_output_no_UU.t23
-rw-r--r--t/lib/TestUtils.pm51
-rw-r--r--t/locking.t45
-rw-r--r--t/mkpath.t37
-rw-r--r--t/mutable_tree_while_iterating.t59
-rw-r--r--t/normalize.t45
-rw-r--r--t/overloading.t26
-rw-r--r--t/parent.t114
-rw-r--r--t/recurse.t163
-rw-r--r--t/rel-abs.t29
-rw-r--r--t/subsumes.t105
-rw-r--r--t/temp.t71
-rw-r--r--t/visit.t22
-rw-r--r--t/zz-atomic.t35
-rw-r--r--t/zzz-spec.t223
-rw-r--r--tidyall.ini5
-rw-r--r--xt/author/00-compile.t57
-rw-r--r--xt/author/critic.t12
-rw-r--r--xt/author/pod-spell.t103
-rw-r--r--xt/release/distmeta.t6
-rw-r--r--xt/release/minimum-version.t8
-rw-r--r--xt/release/pod-coverage.t7
-rw-r--r--xt/release/pod-syntax.t6
-rw-r--r--xt/release/portability.t12
-rw-r--r--xt/release/test-version.t24
50 files changed, 9409 insertions, 0 deletions
diff --git a/CONTRIBUTING.mkdn b/CONTRIBUTING.mkdn
new file mode 100644
index 0000000..761c9db
--- /dev/null
+++ b/CONTRIBUTING.mkdn
@@ -0,0 +1,87 @@
+## 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 than 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.
+
+### Installing and using Dist::Zilla
+
+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/
+
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..cb58a65
--- /dev/null
+++ b/Changes
@@ -0,0 +1,643 @@
+Revision history for Path-Tiny
+
+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' menthod 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
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..71ec0f9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,207 @@
+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 [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..62f97c0
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,51 @@
+# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.037.
+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/filesystem.t
+t/input_output.t
+t/input_output_no_UU.t
+t/lib/TestUtils.pm
+t/locking.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/subsumes.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/pod-spell.t
+xt/release/distmeta.t
+xt/release/minimum-version.t
+xt/release/pod-coverage.t
+xt/release/pod-syntax.t
+xt/release/portability.t
+xt/release/test-version.t
diff --git a/META.json b/META.json
new file mode 100644
index 0000000..dd7914c
--- /dev/null
+++ b/META.json
@@ -0,0 +1,149 @@
+{
+ "abstract" : "File path utility",
+ "author" : [
+ "David Golden <dagolden@cpan.org>"
+ ],
+ "dynamic_config" : 0,
+ "generated_by" : "Dist::Zilla version 5.037, CPAN::Meta::Converter version 2.150005",
+ "license" : [
+ "apache_2_0"
+ ],
+ "meta-spec" : {
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+ "version" : 2
+ },
+ "name" : "Path-Tiny",
+ "no_index" : {
+ "directory" : [
+ "t",
+ "xt",
+ "examples",
+ "corpus"
+ ],
+ "package" : [
+ "DB",
+ "flock"
+ ]
+ },
+ "prereqs" : {
+ "configure" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "6.17",
+ "perl" : "5.008001"
+ }
+ },
+ "develop" : {
+ "requires" : {
+ "Dist::Zilla" : "5",
+ "Dist::Zilla::Plugin::MinimumPerl" : "0",
+ "Dist::Zilla::Plugin::OnlyCorePrereqs" : "0",
+ "Dist::Zilla::Plugin::Prereqs" : "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",
+ "Test::CPAN::Meta" : "0",
+ "Test::More" : "0",
+ "Test::Pod" : "1.41",
+ "Test::Pod::Coverage" : "1.08",
+ "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",
+ "Exporter" : "5.57",
+ "Fcntl" : "0",
+ "File::Copy" : "0",
+ "File::Glob" : "0",
+ "File::Path" : "2.07",
+ "File::Spec" : "3.40",
+ "File::Temp" : "0.19",
+ "File::stat" : "0",
+ "constant" : "0",
+ "if" : "0",
+ "overload" : "0",
+ "perl" : "5.008001",
+ "strict" : "0",
+ "warnings" : "0"
+ }
+ },
+ "test" : {
+ "recommends" : {
+ "CPAN::Meta" : "2.120900",
+ "Test::FailWarnings" : "0"
+ },
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0",
+ "File::Basename" : "0",
+ "File::Spec" : "3.40",
+ "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.070"
+ },
+ "Path::Tiny::Error" : {
+ "file" : "lib/Path/Tiny.pm",
+ "version" : "0.070"
+ }
+ },
+ "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.070",
+ "x_authority" : "cpan:DAGOLDEN",
+ "x_contributors" : [
+ "Alex Efros <powerman@powerman.name>",
+ "Chris Williams <bingos@cpan.org>",
+ "David Steinbrunner <dsteinbrunner@pobox.com>",
+ "Doug Bell <madcityzen@gmail.com>",
+ "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>",
+ "James Hunt <james@niftylogic.com>",
+ "Karen Etheridge <ether@cpan.org>",
+ "Martin Kjeldsen <mk@bluepipe.dk>",
+ "Michael G. Schwern <mschwern@cpan.org>",
+ "Philippe Bruhat (BooK) <book@cpan.org>",
+ "Regina Verbae <regina-verbae@users.noreply.github.com>",
+ "regina-verbae <regina-verbae@users.noreply.github.com>",
+ "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>"
+ ]
+}
+
diff --git a/META.yml b/META.yml
new file mode 100644
index 0000000..214c1aa
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,91 @@
+---
+abstract: 'File path utility'
+author:
+ - 'David Golden <dagolden@cpan.org>'
+build_requires:
+ ExtUtils::MakeMaker: '0'
+ File::Basename: '0'
+ File::Spec: '3.40'
+ 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 5.037, CPAN::Meta::Converter version 2.150005'
+license: apache
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: '1.4'
+name: Path-Tiny
+no_index:
+ directory:
+ - t
+ - xt
+ - examples
+ - corpus
+ package:
+ - DB
+ - flock
+provides:
+ Path::Tiny:
+ file: lib/Path/Tiny.pm
+ version: '0.070'
+ Path::Tiny::Error:
+ file: lib/Path/Tiny.pm
+ version: '0.070'
+recommends:
+ Unicode::UTF8: '0.58'
+requires:
+ Carp: '0'
+ Cwd: '0'
+ Digest: '1.03'
+ Digest::SHA: '5.45'
+ Exporter: '5.57'
+ Fcntl: '0'
+ File::Copy: '0'
+ File::Glob: '0'
+ File::Path: '2.07'
+ File::Spec: '3.40'
+ File::Temp: '0.19'
+ File::stat: '0'
+ constant: '0'
+ if: '0'
+ overload: '0'
+ perl: '5.008001'
+ strict: '0'
+ warnings: '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.070'
+x_authority: cpan:DAGOLDEN
+x_contributors:
+ - 'Alex Efros <powerman@powerman.name>'
+ - 'Chris Williams <bingos@cpan.org>'
+ - 'David Steinbrunner <dsteinbrunner@pobox.com>'
+ - 'Doug Bell <madcityzen@gmail.com>'
+ - '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>'
+ - 'James Hunt <james@niftylogic.com>'
+ - 'Karen Etheridge <ether@cpan.org>'
+ - 'Martin Kjeldsen <mk@bluepipe.dk>'
+ - 'Michael G. Schwern <mschwern@cpan.org>'
+ - 'Philippe Bruhat (BooK) <book@cpan.org>'
+ - 'Regina Verbae <regina-verbae@users.noreply.github.com>'
+ - 'regina-verbae <regina-verbae@users.noreply.github.com>'
+ - '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>'
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..14a5b8c
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,94 @@
+# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.037.
+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",
+ "EXE_FILES" => [],
+ "LICENSE" => "apache",
+ "MIN_PERL_VERSION" => "5.008001",
+ "NAME" => "Path::Tiny",
+ "PREREQ_PM" => {
+ "Carp" => 0,
+ "Cwd" => 0,
+ "Digest" => "1.03",
+ "Digest::SHA" => "5.45",
+ "Exporter" => "5.57",
+ "Fcntl" => 0,
+ "File::Copy" => 0,
+ "File::Glob" => 0,
+ "File::Path" => "2.07",
+ "File::Spec" => "3.40",
+ "File::Temp" => "0.19",
+ "File::stat" => 0,
+ "constant" => 0,
+ "if" => 0,
+ "overload" => 0,
+ "strict" => 0,
+ "warnings" => 0
+ },
+ "TEST_REQUIRES" => {
+ "ExtUtils::MakeMaker" => 0,
+ "File::Basename" => 0,
+ "File::Spec" => "3.40",
+ "File::Spec::Functions" => 0,
+ "File::Spec::Unix" => 0,
+ "File::Temp" => "0.19",
+ "Test::More" => "0.96",
+ "lib" => 0,
+ "open" => 0
+ },
+ "VERSION" => "0.070",
+ "test" => {
+ "TESTS" => "t/*.t"
+ }
+);
+
+
+my %FallbackPrereqs = (
+ "Carp" => 0,
+ "Cwd" => 0,
+ "Digest" => "1.03",
+ "Digest::SHA" => "5.45",
+ "Exporter" => "5.57",
+ "ExtUtils::MakeMaker" => "6.17",
+ "Fcntl" => 0,
+ "File::Basename" => 0,
+ "File::Copy" => 0,
+ "File::Glob" => 0,
+ "File::Path" => "2.07",
+ "File::Spec" => "3.40",
+ "File::Spec::Functions" => 0,
+ "File::Spec::Unix" => 0,
+ "File::Temp" => "0.19",
+ "File::stat" => 0,
+ "Test::More" => "0.96",
+ "constant" => 0,
+ "if" => 0,
+ "lib" => 0,
+ "open" => 0,
+ "overload" => 0,
+ "strict" => 0,
+ "warnings" => 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);
diff --git a/README b/README
new file mode 100644
index 0000000..58e256a
--- /dev/null
+++ b/README
@@ -0,0 +1,970 @@
+NAME
+ Path::Tiny - File path utility
+
+VERSION
+ version 0.070
+
+SYNOPSIS
+ use Path::Tiny;
+
+ # creating Path::Tiny objects
+
+ $dir = path("/tmp");
+ $foo = path("foo.txt");
+
+ $subdir = $dir->child("foo");
+ $bar = $subdir->child("bar.txt");
+
+ # stringifies as cleaned up path
+
+ $file = path("./foo.txt");
+ print $file; # "foo.txt"
+
+ # reading files
+
+ $guts = $file->slurp;
+ $guts = $file->slurp_utf8;
+
+ @lines = $file->lines;
+ @lines = $file->lines_utf8;
+
+ ($head) = $file->lines( {count => 1} );
+ ($tail) = $file->lines( {count => -1} );
+
+ # writing files
+
+ $bar->spew( @data );
+ $bar->spew_utf8( @data );
+
+ # reading directories
+
+ for ( $dir->children ) { ... }
+
+ $iter = $dir->iterator;
+ while ( my $next = $iter->() ) { ... }
+
+DESCRIPTION
+ This module provide 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).
+
+ 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.
+
+CONSTRUCTORS
+ path
+ $path = path("foo/bar");
+ $path = path("/tmp", "file.txt"); # list
+ $path = path("."); # cwd
+ $path = path("~user/file.txt"); # tilde processing
+
+ 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".
+
+ If the first component of the path is a tilde ('~') then the component
+ will be replaced with the output of "glob('~')". If the first component
+ of the path is a tilde followed by a user name then the component will
+ be replaced with output of "glob('~username')". Behaviour for
+ non-existent users depends on the output of "glob" on the system.
+
+ 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 = 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 is enabled
+ by default.
+
+ 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".
+
+ "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.
+
+ 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.
+
+ Current API available since 0.018.
+
+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). Unless an argument is given, the current directory is
+ used as the absolute base path. The argument must be absolute or you
+ won't get an absolute result.
+
+ 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.001.
+
+ 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. 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 fast,
+ unbuffered, raw write.
+
+ "append_utf8" is like "append" with a "binmode" of
+ ":unix:encoding(UTF-8)". If Unicode::UTF8 0.58+ is installed, a 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.
+
+ 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.
+
+ Current API available since 0.001.
+
+ children
+ @paths = path("/tmp")->children;
+ @paths = path("/tmp")->children( qr/\.txt$/ );
+
+ 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 a file 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.
+
+ 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.
+
+ 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)".
+ If Unicode::UTF8 0.58+ is installed, a raw UTF-8 slurp will be done and
+ then the lines will be split. This is actually faster than relying on
+ ":encoding(UTF-8)", 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.
+
+ mkpath
+ path("foo/bar/baz")->mkpath;
+ path("foo/bar/baz")->mkpath( \%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 list of directories created or an empty list if the
+ directories already exist, just like "make_path".
+
+ Current API available since 0.001.
+
+ move
+ path("foo.txt")->move("bar.txt");
+
+ Just like "rename".
+
+ Current API available since 0.001.
+
+ 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 ":raw" and
+ ":raw:encoding(UTF-8)", respectively.
+
+ 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 relative path name. Given the
+ trickiness of this, it's a thin wrapper around "File::Spec->abs2rel()".
+
+ Current API available since 0.001.
+
+ 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.
+
+ 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 may
+ be used to pass options. The only 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)". If Unicode::UTF8 0.58+ is installed, a 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)".
+ If Unicode::UTF8 0.58+ is installed, a raw 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 "mkpath" and "touch". Creates the parent directory if it
+ doesn't exist, before touching the file. Returns the path object like
+ "touch" does.
+
+ Current API available since 0.022.
+
+ visit
+ path("/tmp")->visit( \&callback, \%options );
+
+ Wraps the "iterator" method to execute a callback for each directory
+ entry. It returns a hash reference with any state accumulated during
+ iteration.
+
+ The options are the same as for "iterator": "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 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.
+
+CAVEATS
+ File locking
+ If flock is not supported on a platform, it will not be used, even if
+ locking is requested.
+
+ See additional caveats below.
+
+ NFS and BSD
+ On BSD, Perl's flock implementation may not work to lock files on an NFS
+ filesystem. Path::Tiny has some heuristics to detect this and will warn
+ once and let you continue in an unsafe mode. If you want this failure to
+ be fatal, you can fatalize the 'flock' warnings category:
+
+ use warnings FATAL => 'flock';
+
+ 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 use ":encoding(UTF-8)" -- either as
+ ":unix:encoding(UTF-8)" (unbuffered) or ":raw:encoding(UTF-8)"
+ (buffered) -- which is 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.
+
+ 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
+
+ Consider PerlIO::utf8_strict for a faster PerlIO layer alternative to
+ ":encoding(UTF-8)", though it does not appear to be as fast as the
+ "Unicode::UTF8" approach.
+
+ 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.
+
+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>
+
+ * Chris Williams <bingos@cpan.org>
+
+ * David Steinbrunner <dsteinbrunner@pobox.com>
+
+ * Doug Bell <madcityzen@gmail.com>
+
+ * 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>
+
+ * James Hunt <james@niftylogic.com>
+
+ * Karen Etheridge <ether@cpan.org>
+
+ * Martin Kjeldsen <mk@bluepipe.dk>
+
+ * Michael G. Schwern <mschwern@cpan.org>
+
+ * Philippe Bruhat (BooK) <book@cpan.org>
+
+ * Regina Verbae <regina-verbae@users.noreply.github.com>
+
+ * regina-verbae <regina-verbae@users.noreply.github.com>
+
+ * 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
+
diff --git a/cpanfile b/cpanfile
new file mode 100644
index 0000000..f2941bd
--- /dev/null
+++ b/cpanfile
@@ -0,0 +1,62 @@
+requires "Carp" => "0";
+requires "Cwd" => "0";
+requires "Digest" => "1.03";
+requires "Digest::SHA" => "5.45";
+requires "Exporter" => "5.57";
+requires "Fcntl" => "0";
+requires "File::Copy" => "0";
+requires "File::Glob" => "0";
+requires "File::Path" => "2.07";
+requires "File::Spec" => "3.40";
+requires "File::Temp" => "0.19";
+requires "File::stat" => "0";
+requires "constant" => "0";
+requires "if" => "0";
+requires "overload" => "0";
+requires "perl" => "5.008001";
+requires "strict" => "0";
+requires "warnings" => "0";
+recommends "Unicode::UTF8" => "0.58";
+
+on 'test' => sub {
+ requires "ExtUtils::MakeMaker" => "0";
+ requires "File::Basename" => "0";
+ requires "File::Spec" => "3.40";
+ 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";
+};
+
+on 'configure' => sub {
+ requires "ExtUtils::MakeMaker" => "6.17";
+ requires "perl" => "5.008001";
+};
+
+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::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 "Test::CPAN::Meta" => "0";
+ requires "Test::More" => "0";
+ requires "Test::Pod" => "1.41";
+ requires "Test::Pod::Coverage" => "1.08";
+ requires "Test::Spelling" => "0.12";
+ requires "Test::Version" => "1";
+};
diff --git a/dist.ini b/dist.ini
new file mode 100644
index 0000000..81a1216
--- /dev/null
+++ b/dist.ini
@@ -0,0 +1,58 @@
+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 = SHA
+stopwords = NFS
+stopwords = canonpath
+stopwords = codepoints
+stopwords = cwd
+stopwords = dirname
+stopwords = fatalize
+stopwords = lstat
+stopwords = mkpath
+stopwords = opena
+stopwords = openr
+stopwords = openrw
+stopwords = openw
+stopwords = realpath
+stopwords = stringifying
+stopwords = subclasses
+stopwords = touchpath
+stopwords = UNC
+stopwords = unlinked
+stopwords = utf
+MetaNoIndex.package = flock
+
+[MinimumPerl]
+
+[RemovePrereqs]
+remove = Unicode::UTF8
+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
+
+[OnlyCorePrereqs]
+starting_version = current
+check_dual_life_versions = 0
diff --git a/lib/Path/Tiny.pm b/lib/Path/Tiny.pm
new file mode 100644
index 0000000..3dbaad8
--- /dev/null
+++ b/lib/Path/Tiny.pm
@@ -0,0 +1,2893 @@
+use 5.008001;
+use strict;
+use warnings;
+
+package Path::Tiny;
+# ABSTRACT: File path utility
+
+our $VERSION = '0.070';
+
+# Dependencies
+use Config;
+use Exporter 5.57 (qw/import/);
+use File::Spec 3.40 ();
+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_BSD => ( scalar $^O =~ /bsd$/ ),
+ IS_WIN32 => ( $^O eq 'MSWin32' ),
+};
+
+use overload (
+ q{""} => sub { $_[0]->[PATH] },
+ bool => sub () { 1 },
+ fallback => 1,
+);
+
+# FREEZE/THAW per Sereal/CBOR/Types::Serialiser protocol
+sub FREEZE { return $_[0]->[PATH] }
+sub THAW { return path( $_[2] ) }
+{ no warnings 'once'; *TO_JSON = *FREEZE };
+
+my $HAS_UU; # has Unicode::UTF8; lazily populated
+
+sub _check_UU {
+ !!eval { require Unicode::UTF8; Unicode::UTF8->VERSION(0.58); 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?$}{/};
+ # 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$/ ) : ( $_[0] eq '/' );
+}
+
+# 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. 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 if Path::Tiny::IS_BSD(), 'warnings::register' }
+#>>>
+
+my $WARNED_BSD_NFS = 0;
+
+sub _throw {
+ my ( $self, $function, $file ) = @_;
+ if ( IS_BSD()
+ && $function =~ /^flock/
+ && $! =~ /operation not supported/i
+ && !warnings::fatal_enabled('flock') )
+ {
+ if ( !$WARNED_BSD_NFS ) {
+ warnings::warn( flock => "No flock for NFS on BSD: continuing in unsafe mode" );
+ $WARNED_BSD_NFS++;
+ }
+ }
+ else {
+ Path::Tiny::Error->throw( $function, ( defined $file ? $file : $self->[PATH] ), $! );
+ }
+ 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 $path = path("~user/file.txt"); # tilde processing
+#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 If the first component of the path is a tilde ('~') then the component will be
+#pod replaced with the output of C<glob('~')>. If the first component of the path
+#pod is a tilde followed by a user name then the component will be replaced with
+#pod output of C<glob('~username')>. Behaviour for non-existent users depends on
+#pod the output of C<glob> on the system.
+#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";
+
+ # 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|$)};
+ $path .= "/" if $path =~ m{^$UNC_VOL$};
+ }
+
+ # 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 IS_WIN32() && $path =~ m{^$UNC_VOL$};
+
+ # root paths must always have a trailing slash, but other paths must not
+ if ( _is_root($path) ) {
+ $path =~ s{/?$}{/};
+ }
+ else {
+ $path =~ s{/$}{};
+ }
+
+ # do any tilde expansions
+ if ( $path =~ m{^(~[^/]*).*} ) {
+ require File::Glob;
+ my ($homedir) = File::Glob::bsd_glob($1);
+ $path =~ s{^(~[^/]*)}{$homedir};
+ }
+
+ 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 = 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 C<Path::Tiny>
+#pod object with the file name. The C<TMPDIR> option is enabled by default.
+#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>.
+#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 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 Current API available since 0.018.
+#pod
+#pod =cut
+
+sub tempfile {
+ shift if @_ && $_[0] eq 'Path::Tiny'; # called as method
+ my ( $maybe_template, $args ) = _parse_file_temp_args(@_);
+ # 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 = path($temp)->absolute;
+ $self->[TEMP] = $temp; # keep object alive while we are
+ return $self;
+}
+
+sub tempdir {
+ shift if @_ && $_[0] eq 'Path::Tiny'; # called as method
+ my ( $maybe_template, $args ) = _parse_file_temp_args(@_);
+
+ # File::Temp->newdir demands leading template
+ require File::Temp;
+ my $temp = File::Temp->newdir( @$maybe_template, TMPDIR => 1, %$args );
+ my $self = 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 $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 ( \@template, \%args );
+}
+
+#--------------------------------------------------------------------------#
+# Private methods
+#--------------------------------------------------------------------------#
+
+sub _splitpath {
+ my ($self) = @_;
+ @{$self}[ VOL, DIR, FILE ] = File::Spec->splitpath( $self->[PATH] );
+}
+
+#--------------------------------------------------------------------------#
+# 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). Unless an argument is given, the current directory is used as the
+#pod absolute base path. The argument must be absolute or you won't get an absolute
+#pod result.
+#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.001.
+#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;
+ }
+
+ # relative path on any OS
+ require Cwd;
+ return path( ( defined($base) ? $base : Cwd::getcwd() ), $_[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. An
+#pod optional hash reference may be used to pass 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 fast,
+#pod unbuffered, raw write.
+#pod
+#pod C<append_utf8> is like C<append> with a C<binmode> of
+#pod C<:unix:encoding(UTF-8)>. If L<Unicode::UTF8> 0.58+ is installed, a raw
+#pod append will be done instead on the data encoded with 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;
+ 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 );
+ }
+ 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$/ : qr/\Q$s\E$/;
+ 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 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 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$/ );
+#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 a file using L<File::Copy>'s C<copy> function. Upon
+#pod success, returns the C<Path::Tiny> object for the newly copied
+#pod 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;
+ $digest->add($buf) while read $fh, $buf, $args->{chunk_size};
+ }
+ 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 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} ) {
+ 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 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
+#pod C<:raw:encoding(UTF-8)>. If L<Unicode::UTF8> 0.58+ is installed, a raw
+#pod UTF-8 slurp will be done and then the lines will be split. This is
+#pod actually faster than relying on C<:encoding(UTF-8)>, though a bit memory
+#pod intensive. If memory use is a concern, consider C<openr_utf8> and
+#pod 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} ) );
+ while ( my $line = <$fh> ) {
+ $line =~ s/(?:\x{0d}?\x{0a}|\x{0d})$// 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) {
+ return map { s/(?:\x{0d}?\x{0a}|\x{0d})$//; $_ } <$fh>; ## no critic
+ }
+ else {
+ return wantarray ? <$fh> : ( my $count =()= <$fh> );
+ }
+}
+
+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 );
+ }
+}
+
+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} )
+ {
+ return split /(?:\x{0d}?\x{0a}|\x{0d})/, slurp_utf8($self); ## no critic
+ }
+ else {
+ $args->{binmode} = ":raw:encoding(UTF-8)";
+ return lines( $self, $args );
+ }
+}
+
+#pod =method mkpath
+#pod
+#pod path("foo/bar/baz")->mkpath;
+#pod path("foo/bar/baz")->mkpath( \%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 list of directories created or an empty list if
+#pod the directories already exist, just like C<make_path>.
+#pod
+#pod Current API available since 0.001.
+#pod
+#pod =cut
+
+sub mkpath {
+ my ( $self, $args ) = @_;
+ $args = {} unless ref $args eq 'HASH';
+ my $err;
+ $args->{err} = \$err unless defined $args->{err};
+ 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 Just like C<rename>.
+#pod
+#pod Current API available since 0.001.
+#pod
+#pod =cut
+
+sub move {
+ my ( $self, $dst ) = @_;
+
+ return rename( $self->[PATH], $dst )
+ || $self->_throw( 'rename', $self->[PATH] . "' -> '$dst" );
+}
+
+#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 C<:raw> and
+#pod C<:raw:encoding(UTF-8)>, respectively.
+#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/ );
+ $self->filehandle( $args, $v, ":raw:encoding(UTF-8)" );
+ };
+}
+
+#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{(?:^\.\./|/\.\./|/\.\.$)} ) {
+ $parent = path( $self->[VOL] . $self->[DIR] . "/.." );
+ }
+ else {
+ ( my $dir = $self->[DIR] ) =~ s{/[^\/]+/$}{/};
+ $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;
+ 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 relative path name.
+#pod Given the trickiness of this, it's a thin wrapper around
+#pod C<< File::Spec->abs2rel() >>.
+#pod
+#pod Current API available since 0.001.
+#pod
+#pod =cut
+
+# Easy to get wrong, so wash it through File::Spec (sigh)
+sub relative { path( File::Spec->abs2rel( $_[0]->[PATH], $_[1] ) ) }
+
+#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->{err} = \$err unless defined $args->{err};
+ $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 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 may be
+#pod used to pass options. The only option is C<binmode>, which is passed to
+#pod 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)>. If L<Unicode::UTF8> 0.58+ is installed, a raw
+#pod slurp will be done instead and the result decoded with C<Unicode::UTF8>.
+#pod This is just as strict and is roughly an order of magnitude faster than
+#pod 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;
+ read $fh, $buf, $size; # File::Slurp in a nutshell
+ return $buf;
+ }
+ else {
+ local $/;
+ return scalar <$fh>;
+ }
+}
+
+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" } ) );
+ }
+ else {
+ $_[1] = { binmode => ":raw: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 If L<Unicode::UTF8> 0.58+ is installed, a raw spew will be done instead on
+#pod the data 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
+
+# XXX add "unsafe" option to disable flocking and atomic? Check benchmarks on append() first.
+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;
+ my $temp = path( $self->[PATH] . $$ . int( rand( 2**31 ) ) );
+ my $fh = $temp->filehandle( { exclusive => 1, locked => 1 }, ">", $binmode );
+ print {$fh} map { ref eq 'ARRAY' ? @$_ : $_ } @data;
+ close $fh or $self->_throw( 'close', $temp->[PATH] );
+
+ # spewing need to follow the link
+ # and replace the destination instead
+ my $resolved_path = $self->[PATH];
+ $resolved_path = readlink $resolved_path while -l $resolved_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($_) } @_ );
+ }
+ 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] }
+
+#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(?:/|$)};
+ }
+}
+
+#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');
+ }
+ $epoch = defined($epoch) ? $epoch : time();
+ utime $epoch, $epoch, $self->[PATH]
+ or $self->_throw("utime ($epoch)");
+ return $self;
+}
+
+#pod =method touchpath
+#pod
+#pod path("bar/baz/foo.txt")->touchpath;
+#pod
+#pod Combines C<mkpath> 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 Current API available since 0.022.
+#pod
+#pod =cut
+
+sub touchpath {
+ my ($self) = @_;
+ my $parent = $self->parent;
+ $parent->mkpath unless $parent->exists;
+ $self->touch;
+}
+
+#pod =method visit
+#pod
+#pod path("/tmp")->visit( \&callback, \%options );
+#pod
+#pod Wraps the L</iterator> method to execute a callback for each directory entry.
+#pod It returns a hash reference with any state accumulated during
+#pod iteration.
+#pod
+#pod The options are the same as for L</iterator>: C<recurse> and
+#pod 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 equivalent 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.070
+
+=head1 SYNOPSIS
+
+ use Path::Tiny;
+
+ # creating Path::Tiny objects
+
+ $dir = path("/tmp");
+ $foo = path("foo.txt");
+
+ $subdir = $dir->child("foo");
+ $bar = $subdir->child("bar.txt");
+
+ # stringifies as cleaned up path
+
+ $file = path("./foo.txt");
+ print $file; # "foo.txt"
+
+ # reading files
+
+ $guts = $file->slurp;
+ $guts = $file->slurp_utf8;
+
+ @lines = $file->lines;
+ @lines = $file->lines_utf8;
+
+ ($head) = $file->lines( {count => 1} );
+ ($tail) = $file->lines( {count => -1} );
+
+ # writing files
+
+ $bar->spew( @data );
+ $bar->spew_utf8( @data );
+
+ # reading directories
+
+ for ( $dir->children ) { ... }
+
+ $iter = $dir->iterator;
+ while ( my $next = $iter->() ) { ... }
+
+=head1 DESCRIPTION
+
+This module provide 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).
+
+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.
+
+=head1 CONSTRUCTORS
+
+=head2 path
+
+ $path = path("foo/bar");
+ $path = path("/tmp", "file.txt"); # list
+ $path = path("."); # cwd
+ $path = path("~user/file.txt"); # tilde processing
+
+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 >>.
+
+If the first component of the path is a tilde ('~') then the component will be
+replaced with the output of C<glob('~')>. If the first component of the path
+is a tilde followed by a user name then the component will be replaced with
+output of C<glob('~username')>. Behaviour for non-existent users depends on
+the output of C<glob> on the system.
+
+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 = 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 is enabled by default.
+
+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>.
+
+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.
+
+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.
+
+Current API available since 0.018.
+
+=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). Unless an argument is given, the current directory is used as the
+absolute base path. The argument must be absolute or you won't get an absolute
+result.
+
+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.001.
+
+=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. 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 fast,
+unbuffered, raw write.
+
+C<append_utf8> is like C<append> with a C<binmode> of
+C<:unix:encoding(UTF-8)>. If L<Unicode::UTF8> 0.58+ is installed, a 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 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.
+
+Current API available since 0.001.
+
+=head2 children
+
+ @paths = path("/tmp")->children;
+ @paths = path("/tmp")->children( qr/\.txt$/ );
+
+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 a file 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 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 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)>. If L<Unicode::UTF8> 0.58+ is installed, a raw
+UTF-8 slurp will be done and then the lines will be split. This is
+actually faster than relying on C<:encoding(UTF-8)>, 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 mkpath
+
+ path("foo/bar/baz")->mkpath;
+ path("foo/bar/baz")->mkpath( \%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 list of directories created or an empty list if
+the directories already exist, just like C<make_path>.
+
+Current API available since 0.001.
+
+=head2 move
+
+ path("foo.txt")->move("bar.txt");
+
+Just like C<rename>.
+
+Current API available since 0.001.
+
+=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 C<:raw> and
+C<:raw:encoding(UTF-8)>, respectively.
+
+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 relative path name.
+Given the trickiness of this, it's a thin wrapper around
+C<< File::Spec->abs2rel() >>.
+
+Current API available since 0.001.
+
+=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 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 may be
+used to pass options. The only 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)>. If L<Unicode::UTF8> 0.58+ is installed, a 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)>.
+If L<Unicode::UTF8> 0.58+ is installed, a raw 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<mkpath> and C<touch>. Creates the parent directory if it doesn't exist,
+before touching the file. Returns the path object like C<touch> does.
+
+Current API available since 0.022.
+
+=head2 visit
+
+ path("/tmp")->visit( \&callback, \%options );
+
+Wraps the L</iterator> method to execute a callback for each directory entry.
+It returns a hash reference with any state accumulated during
+iteration.
+
+The options are the same as for L</iterator>: 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
+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_BSD IS_WIN32 FREEZE THAW TO_JSON
+
+=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 CAVEATS
+
+=head2 File locking
+
+If flock is not supported on a platform, it will not be used, even if
+locking is requested.
+
+See additional caveats below.
+
+=head3 NFS and BSD
+
+On BSD, Perl's flock implementation may not work to lock files on an
+NFS filesystem. Path::Tiny has some heuristics to detect this
+and will warn once and let you continue in an unsafe mode. If you
+want this failure to be fatal, you can fatalize the 'flock' warnings
+category:
+
+ use warnings FATAL => 'flock';
+
+=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 use C<:encoding(UTF-8)> -- either as
+C<:unix:encoding(UTF-8)> (unbuffered) or C<:raw:encoding(UTF-8)> (buffered) --
+which is 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.
+
+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
+
+Consider L<PerlIO::utf8_strict> for a faster L<PerlIO> layer alternative to
+C<:encoding(UTF-8)>, though it does not appear to be as fast as the
+C<Unicode::UTF8> approach.
+
+=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>.
+
+=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 annocpan anno 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 Chris Williams David Steinbrunner Doug Bell Gabor Szabo Gabriel Andrade George Hartzell Geraud Continsouzas Goro Fuji Graham Knop James Hunt Karen Etheridge Martin Kjeldsen Michael G. Schwern Philippe Bruhat (BooK) Regina Verbae regina-verbae Smylers Tatsuhiko Miyagawa Toby Inkster Yanick Champoux κΉ€λ„ν˜• - Keedi Kim
+
+=over 4
+
+=item *
+
+Alex Efros <powerman@powerman.name>
+
+=item *
+
+Chris Williams <bingos@cpan.org>
+
+=item *
+
+David Steinbrunner <dsteinbrunner@pobox.com>
+
+=item *
+
+Doug Bell <madcityzen@gmail.com>
+
+=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 *
+
+James Hunt <james@niftylogic.com>
+
+=item *
+
+Karen Etheridge <ether@cpan.org>
+
+=item *
+
+Martin Kjeldsen <mk@bluepipe.dk>
+
+=item *
+
+Michael G. Schwern <mschwern@cpan.org>
+
+=item *
+
+Philippe Bruhat (BooK) <book@cpan.org>
+
+=item *
+
+Regina Verbae <regina-verbae@users.noreply.github.com>
+
+=item *
+
+regina-verbae <regina-verbae@users.noreply.github.com>
+
+=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
diff --git a/perlcritic.rc b/perlcritic.rc
new file mode 100644
index 0000000..bcbbb45
--- /dev/null
+++ b/perlcritic.rc
@@ -0,0 +1,26 @@
+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]
+
diff --git a/t/00-report-prereqs.dd b/t/00-report-prereqs.dd
new file mode 100644
index 0000000..45b5c4e
--- /dev/null
+++ b/t/00-report-prereqs.dd
@@ -0,0 +1,74 @@
+do { my $x = {
+ 'configure' => {
+ 'requires' => {
+ 'ExtUtils::MakeMaker' => '6.17',
+ 'perl' => '5.008001'
+ }
+ },
+ 'develop' => {
+ 'requires' => {
+ 'Dist::Zilla' => '5',
+ 'Dist::Zilla::Plugin::MinimumPerl' => '0',
+ 'Dist::Zilla::Plugin::OnlyCorePrereqs' => '0',
+ 'Dist::Zilla::Plugin::Prereqs' => '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',
+ 'Test::CPAN::Meta' => '0',
+ 'Test::More' => '0',
+ 'Test::Pod' => '1.41',
+ 'Test::Pod::Coverage' => '1.08',
+ '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',
+ 'Exporter' => '5.57',
+ 'Fcntl' => '0',
+ 'File::Copy' => '0',
+ 'File::Glob' => '0',
+ 'File::Path' => '2.07',
+ 'File::Spec' => '3.40',
+ 'File::Temp' => '0.19',
+ 'File::stat' => '0',
+ 'constant' => '0',
+ 'if' => '0',
+ 'overload' => '0',
+ 'perl' => '5.008001',
+ 'strict' => '0',
+ 'warnings' => '0'
+ }
+ },
+ 'test' => {
+ 'recommends' => {
+ 'CPAN::Meta' => '2.120900',
+ 'Test::FailWarnings' => '0'
+ },
+ 'requires' => {
+ 'ExtUtils::MakeMaker' => '0',
+ 'File::Basename' => '0',
+ 'File::Spec' => '3.40',
+ 'File::Spec::Functions' => '0',
+ 'File::Spec::Unix' => '0',
+ 'File::Temp' => '0.19',
+ 'Test::More' => '0.96',
+ 'lib' => '0',
+ 'open' => '0',
+ 'perl' => '5.008001'
+ }
+ }
+ };
+ $x;
+ } \ No newline at end of file
diff --git a/t/00-report-prereqs.t b/t/00-report-prereqs.t
new file mode 100644
index 0000000..d8d15ba
--- /dev/null
+++ b/t/00-report-prereqs.t
@@ -0,0 +1,183 @@
+#!perl
+
+use strict;
+use warnings;
+
+# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021
+
+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';
+if ( $source && $HAS_CPAN_META ) {
+ if ( my $meta = eval { CPAN::Meta->load_file($source) } ) {
+ $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
+ }
+}
+else {
+ $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 $mod eq 'perl';
+ next if grep { $_ eq $mod } @exclude;
+
+ my $file = $mod;
+ $file =~ s{::}{/}g;
+ $file .= ".pm";
+ my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
+
+ my $want = $req_hash->{$phase}{$type}{$mod};
+ $want = "undef" unless defined $want;
+ $want = "any" if !$want && $want == 0;
+
+ my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
+
+ 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 ( @dep_errors ) {
+ diag join("\n",
+ "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n",
+ "The following REQUIRED prerequisites were not satisfied:\n",
+ @dep_errors,
+ "\n"
+ );
+}
+
+pass;
+
+# vim: ts=4 sts=4 sw=4 et:
diff --git a/t/README b/t/README
new file mode 100644
index 0000000..84b6b79
--- /dev/null
+++ b/t/README
@@ -0,0 +1,3 @@
+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.
diff --git a/t/basename.t b/t/basename.t
new file mode 100644
index 0000000..58a0bda
--- /dev/null
+++ b/t/basename.t
@@ -0,0 +1,39 @@
+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
+#
diff --git a/t/basic.t b/t/basic.t
new file mode 100644
index 0000000..7793cef
--- /dev/null
+++ b/t/basic.t
@@ -0,0 +1,185 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+use File::Spec;
+use Path::Tiny;
+use Cwd;
+
+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';
+}
+
+{
+ 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
+{
+ my ($homedir) = glob('~');
+ my $username = path($homedir)->basename;
+ my ($root_homedir) = glob('~root');
+ my ($missing_homedir) = glob('~idontthinkso');
+
+ 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', $homedir.'/foo/bar', 'Test my homedir with longer path' ],
+ ['~/foo/bar/', $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', $root_homedir.'/foo/bar', 'Test root homedir with longer path' ],
+ ['~root/foo/bar/', $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\'' ],
+ );
+
+ for my $test (@tests) {
+ is(path($test->[0]), defined $test->[1] ? $test->[1] : $test->[0], $test->[2]);
+ }
+}
+
+# freeze/thaw
+{
+ my $path = path("/foo/bar/baz");
+ is( Path::Tiny->THAW( "fake", $path->FREEZE("fake") ),
+ $path, "FREEZE-THAW roundtrip" );
+}
+
+# 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();
diff --git a/t/children.t b/t/children.t
new file mode 100644
index 0000000..4c0e266
--- /dev/null
+++ b/t/children.t
@@ -0,0 +1,51 @@
+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';
+
+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
+#
diff --git a/t/chmod.t b/t/chmod.t
new file mode 100644
index 0000000..91eb046
--- /dev/null
+++ b/t/chmod.t
@@ -0,0 +1,48 @@
+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:
diff --git a/t/data/chmod.txt b/t/data/chmod.txt
new file mode 100644
index 0000000..225cabb
--- /dev/null
+++ b/t/data/chmod.txt
@@ -0,0 +1,1171 @@
+ 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
diff --git a/t/digest.t b/t/digest.t
new file mode 100644
index 0000000..276add6
--- /dev/null
+++ b/t/digest.t
@@ -0,0 +1,51 @@
+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;
+
+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
+#
diff --git a/t/exception.t b/t/exception.t
new file mode 100644
index 0000000..6c1043b
--- /dev/null
+++ b/t/exception.t
@@ -0,0 +1,46 @@
+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:
diff --git a/t/exports.t b/t/exports.t
new file mode 100644
index 0000000..5598ebc
--- /dev/null
+++ b/t/exports.t
@@ -0,0 +1,27 @@
+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:
diff --git a/t/filesystem.t b/t/filesystem.t
new file mode 100644
index 0000000..ec5146c
--- /dev/null
+++ b/t/filesystem.t
@@ -0,0 +1,415 @@
+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/;
+
+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->mkpath, "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->mkpath;
+ ok $dir->child('dir')->mkpath;
+ 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->mkpath;
+ ok chdir($dir);
+ my $dir2 = path(".");
+ ok $dir2->child('0')->mkpath;
+ 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->mkpath;
+ 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 "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 nto 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"
+ );
+}
+
+SKIP: {
+ my $newtmp = Path::Tiny->tempdir;
+ my $file = $newtmp->child("foo.txt");
+ my $link = $newtmp->child("bar.txt");
+ $file->spew("Hello World\n");
+ eval { symlink $file => $link };
+ skip "symlink unavailable", 1 if $@;
+ ok( $link->lstat->size, "lstat" );
+
+ 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->mkpath;
+ 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->mkpath;
+ 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->mkpath;
+## 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;
diff --git a/t/input_output.t b/t/input_output.t
new file mode 100644
index 0000000..ae10015
--- /dev/null
+++ b/t/input_output.t
@@ -0,0 +1,497 @@
+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 (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, 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" );
+};
+
+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
+#
diff --git a/t/input_output_no_UU.t b/t/input_output_no_UU.t
new file mode 100644
index 0000000..012f28d
--- /dev/null
+++ b/t/input_output_no_UU.t
@@ -0,0 +1,23 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+
+# Tiny equivalent of Devel::Hide
+BEGIN {
+ $INC{'Unicode/UTF8.pm'} = undef;
+}
+
+note "Hiding Unicode::UTF8";
+
+do "t/input_output.t";
+
+#
+# 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
+#
diff --git a/t/lib/TestUtils.pm b/t/lib/TestUtils.pm
new file mode 100644
index 0000000..d91bedb
--- /dev/null
+++ b/t/lib/TestUtils.pm
@@ -0,0 +1,51 @@
+use 5.008001;
+use strict;
+use warnings;
+
+package TestUtils;
+
+use Carp;
+use Cwd qw/getcwd/;
+use File::Temp 0.19 ();
+
+use Exporter;
+our @ISA = qw/Exporter/;
+our @EXPORT = qw(
+ exception
+ tempd
+);
+
+# If we have Test::FailWarnings, use it
+BEGIN {
+ eval { require Test::FailWarnings; 1 } and do { Test::FailWarnings->import };
+}
+
+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 {
+ my $guard = TestUtils::_Guard->new(
+ {
+ temp => File::Temp->newdir,
+ 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;
diff --git a/t/locking.t b/t/locking.t
new file mode 100644
index 0000000..0c56f29
--- /dev/null
+++ b/t/locking.t
@@ -0,0 +1,45 @@
+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;
+
+my $IS_BSD = $^O =~ /bsd$/;
+
+if ($IS_BSD) {
+ # 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";
+}
+
+subtest 'write locks blocks read lock' => sub {
+ 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" );
+ is( $rc >> 8, 0, "process failed to get lock" );
+};
+
+done_testing;
diff --git a/t/mkpath.t b/t/mkpath.t
new file mode 100644
index 0000000..d6b29fd
--- /dev/null
+++ b/t/mkpath.t
@@ -0,0 +1,37 @@
+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" );
+ 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
+#
diff --git a/t/mutable_tree_while_iterating.t b/t/mutable_tree_while_iterating.t
new file mode 100644
index 0000000..c411ab8
--- /dev/null
+++ b/t/mutable_tree_while_iterating.t
@@ -0,0 +1,59 @@
+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;
diff --git a/t/normalize.t b/t/normalize.t
new file mode 100644
index 0000000..9dd8364
--- /dev/null
+++ b/t/normalize.t
@@ -0,0 +1,45 @@
+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
+#
diff --git a/t/overloading.t b/t/overloading.t
new file mode 100644
index 0000000..f67208b
--- /dev/null
+++ b/t/overloading.t
@@ -0,0 +1,26 @@
+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
+#
diff --git a/t/parent.t b/t/parent.t
new file mode 100644
index 0000000..340fc6e
--- /dev/null
+++ b/t/parent.t
@@ -0,0 +1,114 @@
+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
+#
diff --git a/t/recurse.t b/t/recurse.t
new file mode 100644
index 0000000..e62c302
--- /dev/null
+++ b/t/recurse.t
@@ -0,0 +1,163 @@
+use 5.006;
+use strict;
+use warnings;
+use Test::More 0.92;
+use File::Temp;
+use Config;
+
+use lib 't/lib';
+use TestUtils qw/exception tempd/;
+
+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 $Config{d_symlink};
+
+ 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
+#
diff --git a/t/rel-abs.t b/t/rel-abs.t
new file mode 100644
index 0000000..540d5b4
--- /dev/null
+++ b/t/rel-abs.t
@@ -0,0 +1,29 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+
+use lib 't/lib';
+use TestUtils qw/exception/;
+
+use Path::Tiny;
+
+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" );
+
+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
+#
diff --git a/t/subsumes.t b/t/subsumes.t
new file mode 100644
index 0000000..87e5690
--- /dev/null
+++ b/t/subsumes.t
@@ -0,0 +1,105 @@
+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
+#
diff --git a/t/temp.t b/t/temp.t
new file mode 100644
index 0000000..91b40dd
--- /dev/null
+++ b/t/temp.t
@@ -0,0 +1,71 @@
+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;
+ my $string = $tempdir->stringify;
+ ok( $tempdir->exists, "tempdir exists" );
+ undef $tempdir;
+ ok( !-e $string, "tempdir destroyed" );
+};
+
+subtest "tempfile" => sub {
+ my $tempfile = Path::Tiny->tempfile;
+ 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" );
+};
+
+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
+#
diff --git a/t/visit.t b/t/visit.t
new file mode 100644
index 0000000..1afdd7c
--- /dev/null
+++ b/t/visit.t
@@ -0,0 +1,22 @@
+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";
+
diff --git a/t/zz-atomic.t b/t/zz-atomic.t
new file mode 100644
index 0000000..240dc72
--- /dev/null
+++ b/t/zz-atomic.t
@@ -0,0 +1,35 @@
+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();
diff --git a/t/zzz-spec.t b/t/zzz-spec.t
new file mode 100644
index 0000000..33146b5
--- /dev/null
+++ b/t/zzz-spec.t
@@ -0,0 +1,223 @@
+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('A:/d1','d2','d3')", 'A:/d1/d2/d3' ],
+ [ "path('A:/')", 'A:/' ],
+ [ "path('\\', 'foo')", '/foo' ],
+ [ "path('A:', 'foo')", 'A:/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:', 'foo')", 'A:/foo' ],
+ [ "path('a:/')", 'A:/' ],
+ [ "path('A:f')", 'A:/f' ],
+ [ "path('A:/')", 'A:/' ],
+ [ "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/b/d' ],
+ [ "path('/a/b/c/../../d')", '/a/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/' ],
+ );
+}
+
+# XXX not sure how to adapt this sanely for use with Path::Tiny testing, so
+# I'll punt for now
+
+##
+### FakeWin32 subclass (see below) just sets CWD to C:\one\two and getdcwd('D') to D:\alpha\beta
+##
+##[ "FakeWin32->abs2rel('/t1/t2/t3','/t1/t2/t3')", '.' ],
+##[ "FakeWin32->abs2rel('/t1/t2/t4','/t1/t2/t3')", '..\\t4' ],
+##[ "FakeWin32->abs2rel('/t1/t2','/t1/t2/t3')", '..' ],
+##[ "FakeWin32->abs2rel('/t1/t2/t3/t4','/t1/t2/t3')", 't4' ],
+##[ "FakeWin32->abs2rel('/t4/t5/t6','/t1/t2/t3')", '..\\..\\..\\t4\\t5\\t6' ],
+##[ "FakeWin32->abs2rel('../t4','/t1/t2/t3')", '..\\..\\..\\one\\t4' ], # Uses _cwd()
+##[ "FakeWin32->abs2rel('/','/t1/t2/t3')", '..\\..\\..' ],
+##[ "FakeWin32->abs2rel('///','/t1/t2/t3')", '..\\..\\..' ],
+##[ "FakeWin32->abs2rel('/.','/t1/t2/t3')", '..\\..\\..' ],
+##[ "FakeWin32->abs2rel('/./','/t1/t2/t3')", '..\\..\\..' ],
+##[ "FakeWin32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')", '\\\\a\\t1\\t2\\t4' ],
+##[ "FakeWin32->abs2rel('//a/t1/t2/t4','/t2/t3')", '\\\\a\\t1\\t2\\t4' ],
+##[ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3')", '.' ],
+##[ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','A:/t1/t2/t3')", 't4' ],
+##[ "FakeWin32->abs2rel('A:/t1/t2/t3','A:/t1/t2/t3/t4')", '..' ],
+##[ "FakeWin32->abs2rel('A:/t1/t2/t3','B:/t1/t2/t3')", 'A:\\t1\\t2\\t3' ],
+##[ "FakeWin32->abs2rel('A:/t1/t2/t3/t4','B:/t1/t2/t3')", 'A:\\t1\\t2\\t3\\t4' ],
+##[ "FakeWin32->abs2rel('E:/foo/bar/baz')", 'E:\\foo\\bar\\baz' ],
+##[ "FakeWin32->abs2rel('C:/one/two/three')", 'three' ],
+##[ "FakeWin32->abs2rel('C:\\Windows\\System32', 'C:\\')", 'Windows\System32' ],
+##[ "FakeWin32->abs2rel('\\\\computer2\\share3\\foo.txt', '\\\\computer2\\share3')", 'foo.txt' ],
+##[ "FakeWin32->abs2rel('C:\\one\\two\\t\\asd1\\', 't\\asd\\')", '..\\asd1' ],
+##[ "FakeWin32->abs2rel('\\one\\two', 'A:\\foo')", 'C:\\one\\two' ],
+##
+##[ "FakeWin32->rel2abs('temp','C:/')", 'C:\\temp' ],
+##[ "FakeWin32->rel2abs('temp','C:/a')", 'C:\\a\\temp' ],
+##[ "FakeWin32->rel2abs('temp','C:/a/')", 'C:\\a\\temp' ],
+##[ "FakeWin32->rel2abs('../','C:/')", 'C:\\' ],
+##[ "FakeWin32->rel2abs('../','C:/a')", 'C:\\' ],
+##[ "FakeWin32->rel2abs('\\foo','C:/a')", 'C:\\foo' ],
+##[ "FakeWin32->rel2abs('temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
+##[ "FakeWin32->rel2abs('../temp','//prague_main/work/')", '\\\\prague_main\\work\\temp' ],
+##[ "FakeWin32->rel2abs('temp','//prague_main/work')", '\\\\prague_main\\work\\temp' ],
+##[ "FakeWin32->rel2abs('../','//prague_main/work')", '\\\\prague_main\\work' ],
+##[ "FakeWin32->rel2abs('D:foo.txt')", 'D:\\alpha\\beta\\foo.txt' ],
+
+##
+##can_ok('File::Spec::Win32', '_cwd');
+##
+##{
+## package File::Spec::FakeWin32;
+## use vars qw(@ISA);
+## @ISA = qw(File::Spec::Win32);
+##
+## sub _cwd { 'C:\\one\\two' }
+##
+## # Some funky stuff to override Cwd::getdcwd() for testing purposes,
+## # in the limited scope of the rel2abs() method.
+## if ($Cwd::VERSION && $Cwd::VERSION gt '2.17') { # Avoid a 'used only once' warning
+## local $^W;
+## *rel2abs = sub {
+## my $self = shift;
+## local $^W;
+## local *Cwd::getdcwd = sub {
+## return 'D:\alpha\beta' if $_[0] eq 'D:';
+## return 'C:\one\two' if $_[0] eq 'C:';
+## return;
+## };
+## *Cwd::getdcwd = *Cwd::getdcwd; # Avoid a 'used only once' warning
+## return $self->SUPER::rel2abs(@_);
+## };
+## *rel2abs = *rel2abs; # Avoid a 'used only once' warning
+## }
+##}
+
+# 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
+#
diff --git a/tidyall.ini b/tidyall.ini
new file mode 100644
index 0000000..91aa246
--- /dev/null
+++ b/tidyall.ini
@@ -0,0 +1,5 @@
+; 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}
diff --git a/xt/author/00-compile.t b/xt/author/00-compile.t
new file mode 100644
index 0000000..e52668a
--- /dev/null
+++ b/xt/author/00-compile.t
@@ -0,0 +1,57 @@
+use 5.006;
+use strict;
+use warnings;
+
+# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.053
+
+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 $inc_switch = -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;
+
+ my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-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 { 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) );
+
+
diff --git a/xt/author/critic.t b/xt/author/critic.t
new file mode 100644
index 0000000..d5b4c96
--- /dev/null
+++ b/xt/author/critic.t
@@ -0,0 +1,12 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use English qw(-no_match_vars);
+
+eval "use Test::Perl::Critic";
+plan skip_all => 'Test::Perl::Critic required to criticise code' if $@;
+Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc";
+all_critic_ok();
diff --git a/xt/author/pod-spell.t b/xt/author/pod-spell.t
new file mode 100644
index 0000000..5dcce22
--- /dev/null
+++ b/xt/author/pod-spell.t
@@ -0,0 +1,103 @@
+use strict;
+use warnings;
+use Test::More;
+
+# generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006009
+use Test::Spelling 0.12;
+use Pod::Wordlist;
+
+
+add_stopwords(<DATA>);
+all_pod_files_spelling_ok( qw( bin lib ) );
+__DATA__
+AIX
+BENCHMARKING
+CRLF
+SHA
+NFS
+canonpath
+codepoints
+cwd
+dirname
+fatalize
+lstat
+mkpath
+opena
+openr
+openrw
+openw
+realpath
+stringifying
+subclasses
+touchpath
+UNC
+unlinked
+utf
+David
+Golden
+dagolden
+Alex
+Efros
+powerman
+Chris
+Williams
+bingos
+Steinbrunner
+dsteinbrunner
+Doug
+Bell
+madcityzen
+Gabor
+Szabo
+szabgab
+Gabriel
+Andrade
+gabiruh
+George
+Hartzell
+hartzell
+Geraud
+Continsouzas
+geraud
+Goro
+Fuji
+gfuji
+Graham
+Knop
+haarg
+James
+Hunt
+james
+Karen
+Etheridge
+ether
+Martin
+Kjeldsen
+mk
+Michael
+Schwern
+mschwern
+Philippe
+Bruhat
+BooK
+book
+Regina
+Verbae
+regina
+Smylers
+Tatsuhiko
+Miyagawa
+miyagawa
+Toby
+Inkster
+tobyink
+Yanick
+Champoux
+yanick
+κΉ€λ„ν˜•
+Keedi
+Kim
+keedi
+lib
+Path
+Tiny
diff --git a/xt/release/distmeta.t b/xt/release/distmeta.t
new file mode 100644
index 0000000..c2280dc
--- /dev/null
+++ b/xt/release/distmeta.t
@@ -0,0 +1,6 @@
+#!perl
+# This file was automatically generated by Dist::Zilla::Plugin::MetaTests.
+
+use Test::CPAN::Meta;
+
+meta_yaml_ok();
diff --git a/xt/release/minimum-version.t b/xt/release/minimum-version.t
new file mode 100644
index 0000000..708ba15
--- /dev/null
+++ b/xt/release/minimum-version.t
@@ -0,0 +1,8 @@
+#!perl
+
+use Test::More;
+
+eval "use Test::MinimumVersion";
+plan skip_all => "Test::MinimumVersion required for testing minimum versions"
+ if $@;
+all_minimum_version_ok( qq{5.010} );
diff --git a/xt/release/pod-coverage.t b/xt/release/pod-coverage.t
new file mode 100644
index 0000000..66b3b64
--- /dev/null
+++ b/xt/release/pod-coverage.t
@@ -0,0 +1,7 @@
+#!perl
+# This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests.
+
+use Test::Pod::Coverage 1.08;
+use Pod::Coverage::TrustPod;
+
+all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' });
diff --git a/xt/release/pod-syntax.t b/xt/release/pod-syntax.t
new file mode 100644
index 0000000..f0468f1
--- /dev/null
+++ b/xt/release/pod-syntax.t
@@ -0,0 +1,6 @@
+#!perl
+# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests.
+use Test::More;
+use Test::Pod 1.41;
+
+all_pod_files_ok();
diff --git a/xt/release/portability.t b/xt/release/portability.t
new file mode 100644
index 0000000..58dbc20
--- /dev/null
+++ b/xt/release/portability.t
@@ -0,0 +1,12 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval 'use Test::Portability::Files';
+plan skip_all => 'Test::Portability::Files required for testing portability'
+ if $@;
+options(test_one_dot => 0);
+run_tests();
diff --git a/xt/release/test-version.t b/xt/release/test-version.t
new file mode 100644
index 0000000..4c3278d
--- /dev/null
+++ b/xt/release/test-version.t
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use Test::More;
+
+# generated by Dist::Zilla::Plugin::Test::Version 1.04
+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;