0x1949 Team - FAZEMRX - MANAGER
Edit File: File::pushd.3pm
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "File::pushd 3pm" .TH File::pushd 3pm "2018-05-20" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::pushd \- change directory temporarily for a limited scope .SH "VERSION" .IX Header "VERSION" version 1.016 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use File::pushd; \& \& chdir $ENV{HOME}; \& \& # change directory again for a limited scope \& { \& my $dir = pushd( \*(Aq/tmp\*(Aq ); \& # 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( \*(Aq/tmp\*(Aq ); \& my $filename = File::Spec\->catfile( $dir, "somefile.txt" ); \& # gives /tmp/somefile.txt \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" File::pushd does a temporary \f(CW\*(C`chdir\*(C'\fR that is easily and automatically reverted, similar to \f(CW\*(C`pushd\*(C'\fR 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 \f(CW\*(C`chdir\*(C'\fR 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. .PP 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. .PP For convenience, the object stringifies as the canonical form of the absolute pathname of the directory entered. .PP \&\fBWarning\fR: if you create multiple \f(CW\*(C`pushd\*(C'\fR objects in the same lexical scope, their destruction order is not guaranteed and you might not wind up in the directory you expect. .SH "USAGE" .IX Header "USAGE" .Vb 1 \& use File::pushd; .Ve .PP Using File::pushd automatically imports the \f(CW\*(C`pushd\*(C'\fR and \f(CW\*(C`tempd\*(C'\fR functions. .SS "pushd" .IX Subsection "pushd" .Vb 3 \& { \& my $dir = pushd( $target_directory ); \& } .Ve .PP Caches the current working directory, calls \f(CW\*(C`chdir\*(C'\fR 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. .PP 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. .PP If the target directory does not exist or if the directory change fails for some reason, \f(CW\*(C`pushd\*(C'\fR will die with an error message. .PP Can be given a hashref as an optional second argument. The only supported option is \f(CW\*(C`untaint_pattern\*(C'\fR, which is used to untaint file paths involved. It defaults to {qr{^("" in \-+@\ew.+)$}}, 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. .SS "tempd" .IX Subsection "tempd" .Vb 3 \& { \& my $dir = tempd(); \& } .Ve .PP This function is like \f(CW\*(C`pushd\*(C'\fR but automatically creates and calls \f(CW\*(C`chdir\*(C'\fR 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 \f(CW\*(C`preserve\*(C'\fR.) A warning will be issued if the directory cannot be removed. .PP As with \f(CW\*(C`pushd\*(C'\fR, \f(CW\*(C`tempd\*(C'\fR will die if \f(CW\*(C`chdir\*(C'\fR fails. .PP It may be given a single options hash that will be passed internally to \f(CW\*(C`pushd\*(C'\fR. .SS "preserve" .IX Subsection "preserve" .Vb 5 \& { \& my $dir = tempd(); \& $dir\->preserve; # mark to preserve at end of scope \& $dir\->preserve(0); # mark to delete at end of scope \& } .Ve .PP Controls whether a temporary directory will be cleaned up when the object is destroyed. With no arguments, \f(CW\*(C`preserve\*(C'\fR 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 \f(CW\*(C`tempd\*(C'\fR objects may be marked for cleanup. (Target directories to \f(CW\*(C`pushd\*(C'\fR are always preserved.) \&\f(CW\*(C`preserve\*(C'\fR returns true if the directory will be preserved, and false otherwise. .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" \&\f(CW\*(C`pushd\*(C'\fR and \f(CW\*(C`tempd\*(C'\fR warn with message \&\f(CW"Useless use of File::pushd::\f(CI%s\f(CW in void context"\fR if called in void context and the warnings category \f(CW\*(C`void\*(C'\fR is enabled. .PP .Vb 2 \& { \& use warnings \*(Aqvoid\*(Aq; \& \& pushd(); \& } .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 File::chdir .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/File\-pushd/issues>. You will be notified automatically of any progress on your issue. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. .PP <https://github.com/dagolden/File\-pushd> .PP .Vb 1 \& git clone https://github.com/dagolden/File\-pushd.git .Ve .SH "AUTHOR" .IX Header "AUTHOR" David Golden <dagolden@cpan.org> .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Diab Jerius <djerius@cfa.harvard.edu> .IP "\(bu" 4 Graham Ollis <plicease@cpan.org> .IP "\(bu" 4 Olivier Mengué <dolmen@cpan.org> .IP "\(bu" 4 Shoichi Kaji <skaji@cpan.org> .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2018 by David A Golden. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve