Cwd::Guard(3pm)

πŸ’– Cwd::Guard(3pm) πŸ’–

okay so bestie, this is the manual page for Cwd::Guard, and it's literally about temporary changing working directory (chdir). No cap. ✨

🌸 NAME 🌸

Cwd::Guard β€” Temporary changing working directory (chdir). πŸ¦‹

✨ SYNOPSIS ✨

Here's the vibe in code, bestie:

use Cwd::Guard qw/cwd_guard/;
use Cwd;

my $dir = getcwd;
MYBLOCK: {
    my $guard = cwd_guard('/tmp/xxxxx') or die "failed chdir: $Cwd::Guard::Error";
    # chdir to /tmp/xxxxx
}
# back to $dir

πŸ¦‹ DESCRIPTION πŸ¦‹

CORE::chdir? okay so Cwd::Guard can change the current directory (chdir) using a limited scope. It's giving scoped chdir energy, and honestly? Iconic. πŸ’…

πŸŽ€ FUNCTIONS πŸŽ€

🫢 cwd_guard($dir);

This is the main character function, fr fr. It does chdir to $dir and returns a Cwd::Guard object. When this object gets destroyed, it returns to the current working directory. the way that scope just cleans up after itself, periodt. πŸ‘‘

If chdir fails, cwd_guard returns an undefined value. You can get error messages with $Gwd::Guard::Error. yes bestie, that's exactly how it's spelled in the docs β€” keep it. And in the synopsis you'll see $Cwd::Guard::Error inside the die string, so both are living here, no cap. 😭

πŸ‘‘ AUTHOR πŸ‘‘

Masahiro Nagano <kazeburo {at} gmail.com> β€” absolute legend. 🫢

🌈 SEE ALSO 🌈

  • File::chdir
  • File::pushd

πŸ’œ LICENSE πŸ’œ

Copyright (C) Masahiro Nagano

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


mwah πŸ’‹ β€” this page comes from perl v5.42.2, dated 2023-07-03, bestie. periodt. βœ¨πŸŽ€

πŸ“¦ where this page comes from