File-pushd-1.009/000755 000765 000024 00000000000 12355310100 013743 5ustar00davidstaff000000 000000 File-pushd-1.009/Changes000644 000765 000024 00000006520 12355310100 015241 0ustar00davidstaff000000 000000 Revision history for Perl module File::pushd 1.009 2014-07-03 13:17:48-04:00 America/New_York [FIXED] - s/0.95/0.96/ in t/File_pushd.t 1.008 2014-07-03 13:03:30-04:00 America/New_York [FIXED] - Require a newer version of Test::More 1.007 2014-05-30 23:59:02-04:00 America/New_York [FIXED] - Fixed a testing edge case on Windows 1.006 2014-03-27 15:29:36-04:00 America/New_York [DOCUMENTED] - Noted that multiple pushd objects in a lexical scope are not destroyed in a predictable order [CHANGED] - Modernized Dist::Zilla configuration and repo support files 1.005 2013-03-22 09:58:20 America/New_York [BUG FIXES] - Fix failing test for changing to non-existent directory on some older Perls for some platforms 1.004 2013-03-05 17:59:08 America/New_York [BUG FIXES] - Object destruction won't clobber $@ [SUPPORT] - Changed issue tracker to Github - Dropped support for Perl 5.005 1.003 2012-11-27 17:49:03 America/New_York [BUG FIXES] - Fix test failures on Win32 when using perl.exe that must link to gcc DLL [rt.cpan.org #81476] 1.002 2011-12-07 11:40:26 EST5EDT [BUG FIXES] - Fix failures on cygwin [rt.cpan.org #73072 Reini Urban] 1.001 2011-09-14 22:49:56 America/New_York - updated docs to clarify that pushd() and tempd() croak on errors - if tempd() croaks, error appears at tempd()'s caller, not from within tempd() itself - warnings enabled if perl version >= 5.006 - adds 'untaint_pattern' option with a passable default 1.00 Tue Sep 25 08:19:30 EDT 2007 - changed to the Apache License, version 2.0; (it's clearer, relicensable, and is explicit about contributions) - moved pod/coverage tests to xt/ - preserve() will preserve a temporary directory beyond the program end (by design rather than due to bug RT#21953 in File::Temp); added tests to confirm this behavior after File::Temp is fixed 0.99 Sat Oct 21 08:56:07 EDT 2006 - bumped version for pre-release before 1.00 - updated Pod and converted to wikidoc style - added example directory 0.32 Sat Feb 4 23:41:33 EST 2006 - eliminated syntax that prevented backwards compatibility to 5.004 - adjusted Build.PL to lesser dependencies - added optional pod/pod-coverage test (skipped by default) - switching to development-odd/release-even version numbering 0.30 Sat Dec 3 10:24:16 EST 2005 - eliminated subclassing of Path::Class to eliminate this non-core dependency and improve cross platform compatibility - improved portability of tests 0.24 Tue Nov 8 09:40:02 EST 2005 - added Exporter to @ISA for backwards compatibility [Anton Berezin] 0.23 Mon Nov 7 22:14:51 EST 2005 - derived directories revert to Path::Class::Dir objects instead of File::pushd objects 0.22 Mon Nov 7 18:26:50 EST 2005 - fixed bug in Win32 tests for changing to root directory (work around a Path::Class/File::Spec bug) 0.21 Mon Nov 7 15:08:17 EST 2005 - objects created are now subclasses of Path::Class::Dir - added ability to preserve temporary directories after creation - fixed overloading bug (added fallback) 0.20 Fri Sep 2 06:47:07 EDT 2005 - added tempd function 0.10 Thu Sep 1 23:53:46 EDT 2005 - Initial release File-pushd-1.009/CONTRIBUTING000644 000765 000024 00000006512 12355310100 015601 0ustar00davidstaff000000 000000 ## 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 (e.g. Makefile.PL). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball and/or install from the repository. See below for guidance. ### Getting dependencies See the included `cpanfile` file for a list of dependencies. If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, you can install Module::CPANfile 1.0002 or later and then satisfy dependencies with the regular `cpan` client and `cpanfile-dump`: $ cpan `cpanfile-dump` ### 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. Depending on the distribution, some of my documentation may be written in a Pod dialect called WikiDoc. (See Pod::WikiDoc on CPAN.) 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 from the repository If you want to install directly from the repository, you need to have Dist::Zilla installed (see below). If this is a burden to you, I welcome patches against a CPAN tarball instead of the repository. ### 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 To install from the repository, use: $ dzil install You can learn more about Dist::Zilla at http://dzil.org/ File-pushd-1.009/cpanfile000644 000765 000024 00000002232 12355310100 015446 0ustar00davidstaff000000 000000 requires "Carp" => "0"; requires "Cwd" => "0"; requires "Exporter" => "0"; requires "File::Path" => "0"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "overload" => "0"; requires "perl" => "5.006"; requires "strict" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Basename" => "0"; requires "File::Spec::Functions" => "0"; requires "List::Util" => "0"; requires "Test::More" => "0.96"; requires "version" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "0"; recommends "CPAN::Meta::Requirements" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.060"; 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"; }; File-pushd-1.009/dist.ini000644 000765 000024 00000000317 12355310100 015410 0ustar00davidstaff000000 000000 name = File-pushd author = David Golden license = Apache_2_0 copyright_holder = David A Golden [@DAGOLDEN] :version = 0.060 stopwords = destructor stopwords = pathname stopwords = tempd File-pushd-1.009/examples/000755 000765 000024 00000000000 12355310100 015561 5ustar00davidstaff000000 000000 File-pushd-1.009/lib/000755 000765 000024 00000000000 12355310100 014511 5ustar00davidstaff000000 000000 File-pushd-1.009/LICENSE000644 000765 000024 00000026356 12355310100 014764 0ustar00davidstaff000000 000000 This software is Copyright (c) 2014 by David A 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. File-pushd-1.009/Makefile.PL000644 000765 000024 00000003136 12355310100 015720 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.019. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "change directory temporarily for a limited scope", "AUTHOR" => "David Golden ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "File-pushd", "EXE_FILES" => [], "LICENSE" => "apache", "NAME" => "File::pushd", "PREREQ_PM" => { "Carp" => 0, "Cwd" => 0, "Exporter" => 0, "File::Path" => 0, "File::Spec" => 0, "File::Temp" => 0, "overload" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Spec::Functions" => 0, "List::Util" => 0, "Test::More" => "0.96", "version" => 0 }, "VERSION" => "1.009", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Cwd" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Basename" => 0, "File::Path" => 0, "File::Spec" => 0, "File::Spec::Functions" => 0, "File::Temp" => 0, "List::Util" => 0, "Test::More" => "0.96", "overload" => 0, "strict" => 0, "version" => 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); File-pushd-1.009/MANIFEST000644 000765 000024 00000000777 12355310100 015107 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.019. CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README Todo cpanfile dist.ini examples/example.pl lib/File/pushd.pm perlcritic.rc t/00-report-prereqs.t t/File_pushd.t t/exception.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 File-pushd-1.009/META.json000644 000765 000024 00000005204 12355310100 015365 0ustar00davidstaff000000 000000 { "abstract" : "change directory temporarily for a limited scope", "author" : [ "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.141170", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "File-pushd", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.060", "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" } }, "runtime" : { "requires" : { "Carp" : "0", "Cwd" : "0", "Exporter" : "0", "File::Path" : "0", "File::Spec" : "0", "File::Temp" : "0", "overload" : "0", "perl" : "5.006", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "0", "CPAN::Meta::Requirements" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Basename" : "0", "File::Spec::Functions" : "0", "List::Util" : "0", "Test::More" : "0.96", "version" : "0" } } }, "provides" : { "File::pushd" : { "file" : "lib/File/pushd.pm", "version" : "1.009" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/File-pushd/issues" }, "homepage" : "https://github.com/dagolden/File-pushd", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/File-pushd.git", "web" : "https://github.com/dagolden/File-pushd" } }, "version" : "1.009", "x_authority" : "cpan:DAGOLDEN", "x_contributors" : [ "Diab Jerius ", "Graham Ollis " ] } File-pushd-1.009/META.yml000644 000765 000024 00000002237 12355310100 015220 0ustar00davidstaff000000 000000 --- abstract: 'change directory temporarily for a limited scope' author: - 'David Golden ' build_requires: ExtUtils::MakeMaker: '0' File::Basename: '0' File::Spec::Functions: '0' List::Util: '0' Test::More: '0.96' version: '0' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.019, CPAN::Meta::Converter version 2.141170' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: File-pushd no_index: directory: - t - xt - examples - corpus package: - DB provides: File::pushd: file: lib/File/pushd.pm version: '1.009' requires: Carp: '0' Cwd: '0' Exporter: '0' File::Path: '0' File::Spec: '0' File::Temp: '0' overload: '0' perl: '5.006' strict: '0' warnings: '0' resources: bugtracker: https://github.com/dagolden/File-pushd/issues homepage: https://github.com/dagolden/File-pushd repository: https://github.com/dagolden/File-pushd.git version: '1.009' x_authority: cpan:DAGOLDEN x_contributors: - 'Diab Jerius ' - 'Graham Ollis ' File-pushd-1.009/perlcritic.rc000644 000765 000024 00000001166 12355310100 016435 0ustar00davidstaff000000 000000 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] File-pushd-1.009/README000644 000765 000024 00000011542 12355310100 014626 0ustar00davidstaff000000 000000 NAME File::pushd - change directory temporarily for a limited scope VERSION version 1.009 SYNOPSIS use File::pushd; chdir $ENV{HOME}; # change directory again for a limited scope { my $dir = pushd( '/tmp' ); # working directory changed to /tmp } # working directory has reverted to $ENV{HOME} # tempd() is equivalent to pushd( File::Temp::tempdir ) { my $dir = tempd(); } # object stringifies naturally as an absolute path { my $dir = pushd( '/tmp' ); my $filename = File::Spec->catfile( $dir, "somefile.txt" ); # gives /tmp/somefile.txt } DESCRIPTION File::pushd does a temporary "chdir" that is easily and automatically reverted, similar to "pushd" in some Unix command shells. It works by creating an object that caches the original working directory. When the object is destroyed, the destructor calls "chdir" to revert to the original working directory. By storing the object in a lexical variable with a limited scope, this happens automatically at the end of the scope. This is very handy when working with temporary directories for tasks like testing; a function is provided to streamline getting a temporary directory from File::Temp. For convenience, the object stringifies as the canonical form of the absolute pathname of the directory entered. Warning: if you create multiple "pushd" objects in the same lexical scope, their destruction order is not guaranteed and you might not wind up in the directory you expect. USAGE use File::pushd; Using File::pushd automatically imports the "pushd" and "tempd" functions. pushd { my $dir = pushd( $target_directory ); } Caches the current working directory, calls "chdir" to change to the target directory, and returns a File::pushd object. When the object is destroyed, the working directory reverts to the original directory. The provided target directory can be a relative or absolute path. If called with no arguments, it uses the current directory as its target and returns to the current directory when the object is destroyed. If the target directory does not exist or if the directory change fails for some reason, "pushd" will die with an error message. Can be given a hashref as an optional second argument. The only supported option is "untaint_pattern", which is used to untaint file paths involved. It defaults to {qr{^("" in -+@\w.+)$}}, which is reasonably restrictive (e.g. it does not even allow spaces in the path). Change this to suit your circumstances and security needs if running under taint mode. *Note*: you must include the parentheses in the pattern to capture the untainted portion of the path. tempd { my $dir = tempd(); } This function is like "pushd" but automatically creates and calls "chdir" to a temporary directory created by File::Temp. Unlike normal File::Temp cleanup which happens at the end of the program, this temporary directory is removed when the object is destroyed. (But also see "preserve".) A warning will be issued if the directory cannot be removed. As with "pushd", "tempd" will die if "chdir" fails. It may be given a single options hash that will be passed internally to "pushd". preserve { my $dir = tempd(); $dir->preserve; # mark to preserve at end of scope $dir->preserve(0); # mark to delete at end of scope } Controls whether a temporary directory will be cleaned up when the object is destroyed. With no arguments, "preserve" sets the directory to be preserved. With an argument, the directory will be preserved if the argument is true, or marked for cleanup if the argument is false. Only "tempd" objects may be marked for cleanup. (Target directories to "pushd" are always preserved.) "preserve" returns true if the directory will be preserved, and false otherwise. SEE ALSO * File::chdir SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . 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. git clone https://github.com/dagolden/File-pushd.git AUTHOR David Golden CONTRIBUTORS * Diab Jerius * Graham Ollis COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David A Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 File-pushd-1.009/t/000755 000765 000024 00000000000 12355310100 014206 5ustar00davidstaff000000 000000 File-pushd-1.009/tidyall.ini000644 000765 000024 00000000240 12355310100 016102 0ustar00davidstaff000000 000000 ; 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} File-pushd-1.009/Todo000644 000765 000024 00000000372 12355310100 014575 0ustar00davidstaff000000 000000 TODO list for Perl module File::pushd - Add some sort of flag that avoids fatal errors changing directories. Either a flag on pushd( $dir, { %opts } ) or else on use (but make it calling package specific) "use File::pushd qw/pushd :non_fatal/;" File-pushd-1.009/xt/000755 000765 000024 00000000000 12355310100 014376 5ustar00davidstaff000000 000000 File-pushd-1.009/xt/author/000755 000765 000024 00000000000 12355310100 015700 5ustar00davidstaff000000 000000 File-pushd-1.009/xt/release/000755 000765 000024 00000000000 12355310100 016016 5ustar00davidstaff000000 000000 File-pushd-1.009/xt/release/distmeta.t000644 000765 000024 00000000172 12355310100 020015 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); File-pushd-1.009/xt/release/minimum-version.t000644 000765 000024 00000000266 12355310100 021345 0ustar00davidstaff000000 000000 #!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} ); File-pushd-1.009/xt/release/pod-coverage.t000644 000765 000024 00000000334 12355310100 020556 0ustar00davidstaff000000 000000 #!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' }); File-pushd-1.009/xt/release/pod-syntax.t000644 000765 000024 00000000220 12355310100 020303 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); File-pushd-1.009/xt/release/portability.t000644 000765 000024 00000000332 12355310100 020543 0ustar00davidstaff000000 000000 #!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(); File-pushd-1.009/xt/release/test-version.t000644 000765 000024 00000000643 12355310100 020650 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; File-pushd-1.009/xt/author/00-compile.t000644 000765 000024 00000002034 12355310100 017731 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.043 use Test::More tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'File/pushd.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 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"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') if $ENV{AUTHOR_TESTING}; File-pushd-1.009/xt/author/critic.t000644 000765 000024 00000000435 12355310100 017344 0ustar00davidstaff000000 000000 #!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(); File-pushd-1.009/xt/author/pod-spell.t000644 000765 000024 00000000516 12355310100 017766 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006008 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ destructor pathname tempd David Golden dagolden Diab Jerius djerius Graham Ollis plicease lib File pushd File-pushd-1.009/t/00-report-prereqs.t000644 000765 000024 00000014416 12355310100 017610 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.013 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec::Functions; use List::Util qw/max/; use version; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_req = "CPAN::Meta::Requirements"; my $HAS_CPAN_META = eval "require $cpan_meta"; ## no critic my $HAS_CPAN_META_REQ = eval "require $cpan_meta_req; $cpan_meta_req->VERSION('2.120900')"; # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _merge_requires { my ($collector, $prereqs) = @_; for my $phase ( qw/configure build test runtime develop/ ) { next unless exists $prereqs->{$phase}; if ( my $req = $prereqs->{$phase}{'requires'} ) { my $cmr = CPAN::Meta::Requirements->from_string_hash( $req ); $collector->add_requirements( $cmr ); } } } my %include = map {; $_ => 1 } qw( ); my %exclude = map {; $_ => 1 } qw( ); # Add static prereqs to the included modules list my $static_prereqs = do { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.17' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.060', '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' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Cwd' => '0', 'Exporter' => '0', 'File::Path' => '0', 'File::Spec' => '0', 'File::Temp' => '0', 'overload' => '0', 'perl' => '5.006', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '0', 'CPAN::Meta::Requirements' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Basename' => '0', 'File::Spec::Functions' => '0', 'List::Util' => '0', 'Test::More' => '0.96', 'version' => '0' } } }; $x; }; delete $static_prereqs->{develop} if not $ENV{AUTHOR_TESTING}; $include{$_} = 1 for map { keys %$_ } map { values %$_ } values %$static_prereqs; # Merge requirements for major phases (if we can) my $all_requires; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META_REQ ) { $all_requires = $cpan_meta_req->new; _merge_requires($all_requires, $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) } ) { my $dynamic_prereqs = $meta->prereqs; delete $dynamic_prereqs->{develop} if not $ENV{AUTHOR_TESTING}; $include{$_} = 1 for map { keys %$_ } map { values %$_ } values %$dynamic_prereqs; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META_REQ ) { _merge_requires($all_requires, $dynamic_prereqs); } } } else { $source = 'static metadata'; } my @modules = sort grep { ! $exclude{$_} } keys %include; my @reports = [qw/Version Module/]; my @dep_errors; my $req_hash = defined($all_requires) ? $all_requires->as_string_hash : {}; for my $mod ( @modules ) { next if $mod eq 'perl'; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e catfile($_, $file) } @INC; if ( $prefix ) { my $ver = MM->parse_version( catfile($prefix, $file) ); $ver = "undef" unless defined $ver; # Newer MM should do this anyway push @reports, [$ver, $mod]; if ( $DO_VERIFY_PREREQS && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { if ( ! defined eval { version->parse($ver) } ) { push @dep_errors, "$mod version '$ver' cannot be parsed (version '$req' required)"; } elsif ( ! $all_requires->accepts_module( $mod => $ver ) ) { push @dep_errors, "$mod version '$ver' is not in required range '$req'"; } } } } else { push @reports, ["missing", $mod]; if ( $DO_VERIFY_PREREQS && $all_requires ) { my $req = $req_hash->{$mod}; if ( defined $req && length $req ) { push @dep_errors, "$mod is not installed (version '$req' required)"; } } } } if ( @reports ) { my $vl = max map { length $_->[0] } @reports; my $ml = max map { length $_->[1] } @reports; splice @reports, 1, 0, ["-" x $vl, "-" x $ml]; diag "\nVersions for all modules listed in $source (including optional ones):\n", map {sprintf(" %*s %*s\n",$vl,$_->[0],-$ml,$_->[1])} @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: File-pushd-1.009/t/exception.t000644 000765 000024 00000000645 12355310100 016376 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More 0.96; use File::pushd; eval { my $dir = tempd; die("error\n"); }; my $err = $@; is( $err, "error\n", "destroy did not clobber \$@\n" ); done_testing; # # This file is part of File-pushd # # This software is Copyright (c) 2014 by David A Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: File-pushd-1.009/t/File_pushd.t000644 000765 000024 00000017135 12355310100 016464 0ustar00davidstaff000000 000000 # File::pushd - check module loading and create testing directory use strict; #use warnings; use Test::More 0.96; use File::Path 'rmtree'; use File::Basename 'dirname'; use Cwd 'abs_path'; use File::Spec::Functions qw( catdir curdir updir canonpath rootdir ); use File::Temp; # abs_path necessary to pick up the volume on Win32, e.g. C:\ sub absdir { canonpath( abs_path( shift || curdir() ) ); } #--------------------------------------------------------------------------# # Test import #--------------------------------------------------------------------------# BEGIN { use_ok('File::pushd'); } can_ok( 'main', 'pushd', 'tempd' ); #--------------------------------------------------------------------------# # Setup #--------------------------------------------------------------------------# my ( $new_dir, $temp_dir, $err ); my $original_dir = absdir(); my $target_dir = 't'; my $expected_dir = absdir( catdir( $original_dir, $target_dir ) ); my $nonexistant = 'DFASDFASDFASDFAS'; #--------------------------------------------------------------------------# # Test error handling on bad target #--------------------------------------------------------------------------# eval { $new_dir = pushd($nonexistant) }; $err = $@; like( $@, '/\\ACan\'t/', "pushd to nonexistant directory croaks" ); #--------------------------------------------------------------------------# # Test changing to relative path directory #--------------------------------------------------------------------------# $new_dir = pushd($target_dir); isa_ok( $new_dir, 'File::pushd' ); is( absdir(), $expected_dir, "change directory on pushd (relative path)" ); #--------------------------------------------------------------------------# # Test stringification #--------------------------------------------------------------------------# is( "$new_dir", $expected_dir, "object stringifies" ); #--------------------------------------------------------------------------# # Test reverting directory #--------------------------------------------------------------------------# undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test changing to absolute path directory and reverting #--------------------------------------------------------------------------# $new_dir = pushd($expected_dir); is( absdir(), $expected_dir, "change directory on pushd (absolute path)" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test changing upwards #--------------------------------------------------------------------------# $expected_dir = absdir( updir() ); $new_dir = pushd( updir() ); is( absdir(), $expected_dir, "change directory on pushd (upwards)" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test changing to root #--------------------------------------------------------------------------# $new_dir = pushd( rootdir() ); is( absdir(), absdir( rootdir() ), "change directory on pushd (rootdir)" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test with options #--------------------------------------------------------------------------# $new_dir = pushd( $expected_dir, { untaint_pattern => qr{^([-\w./]+)$} } ); is( absdir(), $expected_dir, "change directory on pushd (custom untaint)" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test changing in place #--------------------------------------------------------------------------# $new_dir = pushd(); is( absdir(), $original_dir, "pushd with no argument doesn't change directory" ); chdir "t"; is( absdir(), absdir( catdir( $original_dir, "t" ) ), "changing manually to another directory" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); #--------------------------------------------------------------------------# # Test changing to temporary dir #--------------------------------------------------------------------------# $new_dir = tempd(); $temp_dir = "$new_dir"; ok( absdir() ne $original_dir, "tempd changes to new temporary directory" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); ok( !-e $temp_dir, "temporary directory removed" ); #--------------------------------------------------------------------------# # Test changing to temporary dir but preserving it #--------------------------------------------------------------------------# $new_dir = tempd(); $temp_dir = "$new_dir"; ok( absdir() ne $original_dir, "tempd changes to new temporary directory" ); ok( $new_dir->preserve(1), "mark temporary directory for preservation" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); ok( -e $temp_dir, "temporary directory preserved" ); ok( rmtree($temp_dir), "temporary directory manually cleaned up" ); #--------------------------------------------------------------------------# # Test changing to temporary dir but preserving it *outside the process* #--------------------------------------------------------------------------# my $program_file = File::Temp->new(); my $lib = absdir("lib"); $lib =~ s{\\}{/}g; print {$program_file} <<"END_PROGRAM"; use lib "$lib"; use File::pushd; my \$tempd = tempd() or exit; \$tempd->preserve(1); print "\$tempd\n"; END_PROGRAM $program_file->close; # for when I manually test with "perl -t", must untaint things for my $key (qw(IFS CDPATH ENV BASH_ENV PATH)) { next unless defined $ENV{$key}; $ENV{$key} =~ /^(.*)$/; $ENV{$key} = $1; } $temp_dir = `$^X $program_file`; chomp($temp_dir); $temp_dir =~ /(.*)/; my $clean_tmp = $1; ok( length $clean_tmp, "got a temp directory name from subproces" ); ok( -e $clean_tmp, "temporary directory preserved outside subprocess" ); ok( rmtree($clean_tmp), "temporary directory manually cleaned up" ); #--------------------------------------------------------------------------# # Test changing to temporary dir, preserve it, then revert #--------------------------------------------------------------------------# $new_dir = tempd(); $temp_dir = "$new_dir"; ok( absdir() ne $original_dir, "tempd changes to new temporary directory" ); ok( $new_dir->preserve, "mark temporary directory for preservation" ); ok( !$new_dir->preserve(0), "mark temporary directory for removal" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); ok( !-e $temp_dir, "temporary directory removed" ); #--------------------------------------------------------------------------# # Test preserve failing on non temp directory #--------------------------------------------------------------------------# $new_dir = pushd( catdir( $original_dir, $target_dir ) ); is( absdir(), absdir( catdir( $original_dir, $target_dir ) ), "change directory on pushd" ); $temp_dir = "$new_dir"; ok( $new_dir->preserve, "regular pushd is automatically preserved" ); ok( $new_dir->preserve(0), "can't mark regular pushd for deletion" ); undef $new_dir; is( absdir(), $original_dir, "revert directory when variable goes out of scope" ); ok( -e $expected_dir, "original directory not removed" ); done_testing; File-pushd-1.009/lib/File/000755 000765 000024 00000000000 12355310100 015370 5ustar00davidstaff000000 000000 File-pushd-1.009/lib/File/pushd.pm000644 000765 000024 00000017350 12355310100 017057 0ustar00davidstaff000000 000000 use strict; use warnings; package File::pushd; # ABSTRACT: change directory temporarily for a limited scope our $VERSION = '1.009'; # VERSION our @EXPORT = qw( pushd tempd ); our @ISA = qw( Exporter ); use Exporter; use Carp; use Cwd qw( getcwd abs_path ); use File::Path qw( rmtree ); use File::Temp qw(); use File::Spec; use overload q{""} => sub { File::Spec->canonpath( $_[0]->{_pushd} ) }, fallback => 1; #--------------------------------------------------------------------------# # pushd() #--------------------------------------------------------------------------# sub pushd { my ( $target_dir, $options ) = @_; $options->{untaint_pattern} ||= qr{^([-+@\w./]+)$}; $target_dir = "." unless defined $target_dir; croak "Can't locate directory $target_dir" unless -d $target_dir; my $tainted_orig = getcwd; my $orig; if ( $tainted_orig =~ $options->{untaint_pattern} ) { $orig = $1; } else { $orig = $tainted_orig; } my $tainted_dest; eval { $tainted_dest = $target_dir ? abs_path($target_dir) : $orig }; croak "Can't locate absolute path for $target_dir: $@" if $@; my $dest; if ( $tainted_dest =~ $options->{untaint_pattern} ) { $dest = $1; } else { $dest = $tainted_dest; } if ( $dest ne $orig ) { chdir $dest or croak "Can't chdir to $dest\: $!"; } my $self = bless { _pushd => $dest, _original => $orig }, __PACKAGE__; return $self; } #--------------------------------------------------------------------------# # tempd() #--------------------------------------------------------------------------# sub tempd { my ($options) = @_; my $dir; eval { $dir = pushd( File::Temp::tempdir( CLEANUP => 0 ), $options ) }; croak $@ if $@; $dir->{_tempd} = 1; return $dir; } #--------------------------------------------------------------------------# # preserve() #--------------------------------------------------------------------------# sub preserve { my $self = shift; return 1 if !$self->{"_tempd"}; if ( @_ == 0 ) { return $self->{_preserve} = 1; } else { return $self->{_preserve} = $_[0] ? 1 : 0; } } #--------------------------------------------------------------------------# # DESTROY() # Revert to original directory as object is destroyed and cleanup # if necessary #--------------------------------------------------------------------------# sub DESTROY { my ($self) = @_; my $orig = $self->{_original}; chdir $orig if $orig; # should always be so, but just in case... if ( $self->{_tempd} && !$self->{_preserve} ) { # don't destroy existing $@ if there is no error. my $err = do { local $@; eval { rmtree( $self->{_pushd} ) }; $@; }; carp $err if $err; } } 1; =pod =encoding UTF-8 =head1 NAME File::pushd - change directory temporarily for a limited scope =head1 VERSION version 1.009 =head1 SYNOPSIS use File::pushd; chdir $ENV{HOME}; # change directory again for a limited scope { my $dir = pushd( '/tmp' ); # working directory changed to /tmp } # working directory has reverted to $ENV{HOME} # tempd() is equivalent to pushd( File::Temp::tempdir ) { my $dir = tempd(); } # object stringifies naturally as an absolute path { my $dir = pushd( '/tmp' ); my $filename = File::Spec->catfile( $dir, "somefile.txt" ); # gives /tmp/somefile.txt } =head1 DESCRIPTION File::pushd does a temporary C that is easily and automatically reverted, similar to C in some Unix command shells. It works by creating an object that caches the original working directory. When the object is destroyed, the destructor calls C to revert to the original working directory. By storing the object in a lexical variable with a limited scope, this happens automatically at the end of the scope. This is very handy when working with temporary directories for tasks like testing; a function is provided to streamline getting a temporary directory from L. For convenience, the object stringifies as the canonical form of the absolute pathname of the directory entered. B: if you create multiple C objects in the same lexical scope, their destruction order is not guaranteed and you might not wind up in the directory you expect. =head1 USAGE use File::pushd; Using File::pushd automatically imports the C and C functions. =head2 pushd { my $dir = pushd( $target_directory ); } Caches the current working directory, calls C to change to the target directory, and returns a File::pushd object. When the object is destroyed, the working directory reverts to the original directory. The provided target directory can be a relative or absolute path. If called with no arguments, it uses the current directory as its target and returns to the current directory when the object is destroyed. If the target directory does not exist or if the directory change fails for some reason, C will die with an error message. Can be given a hashref as an optional second argument. The only supported option is C, which is used to untaint file paths involved. It defaults to {qr{^(L<-+@\w./>+)$}}, which is reasonably restrictive (e.g. it does not even allow spaces in the path). Change this to suit your circumstances and security needs if running under taint mode. *Note*: you must include the parentheses in the pattern to capture the untainted portion of the path. =head2 tempd { my $dir = tempd(); } This function is like C but automatically creates and calls C to a temporary directory created by L. Unlike normal L cleanup which happens at the end of the program, this temporary directory is removed when the object is destroyed. (But also see C.) A warning will be issued if the directory cannot be removed. As with C, C will die if C fails. It may be given a single options hash that will be passed internally to C. =head2 preserve { my $dir = tempd(); $dir->preserve; # mark to preserve at end of scope $dir->preserve(0); # mark to delete at end of scope } Controls whether a temporary directory will be cleaned up when the object is destroyed. With no arguments, C sets the directory to be preserved. With an argument, the directory will be preserved if the argument is true, or marked for cleanup if the argument is false. Only C objects may be marked for cleanup. (Target directories to C are always preserved.) C returns true if the directory will be preserved, and false otherwise. =head1 SEE ALSO =over 4 =item * L =back =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. 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 git clone https://github.com/dagolden/File-pushd.git =head1 AUTHOR David Golden =head1 CONTRIBUTORS =over 4 =item * Diab Jerius =item * Graham Ollis =back =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David A Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut __END__ # vim: ts=4 sts=4 sw=4 et: File-pushd-1.009/examples/example.pl000644 000765 000024 00000001064 12355310100 017552 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Cwd qw/cwd/; use File::pushd qw/tempd pushd/; print "Starting directory:\n " . cwd() . "\n"; # tempd() is equivalent to pushd( File::Temp::tempdir ) { my $tempdir = tempd(); print "Directory after tempd():\n " . cwd() . "\n"; mkdir "new_dir"; { my $new_dir = pushd "new_dir"; print "Directory after pushd('new_dir'):\n " . cwd() . "\n"; } print "Directory after pushd object destroyed:\n " . cwd() . "\n"; } print "Directory after tempd object destroyed:\n " . cwd() . "\n";