/usr/share/perl5/Cwd/Guard.pm is in libcwd-guard-perl 0.05-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | package Cwd::Guard;
use strict;
use warnings;
use parent 'Exporter';
our @EXPORT_OK = qw/cwd_guard/;
our $Error;
our $VERSION = '0.05';
use constant USE_FCHDIR => eval { opendir my $dh, '.'; chdir $dh; 1 };
use if !USE_FCHDIR, Cwd => qw/getcwd/;
sub cwd_guard {
my $dir = shift;
__PACKAGE__->new($dir);
}
sub new {
my $class = shift;
my $dir = shift;
my $cwd;
if (USE_FCHDIR) { opendir $cwd, '.' } else { $cwd = getcwd() }
my $callback = sub {
chdir $cwd;
};
my $result = defined $dir ? chdir($dir) : chdir();
$Error = $!;
return unless $result;
bless $callback, $class;
}
sub DESTROY {
$_[0]->();
}
1;
__END__
=head1 NAME
Cwd::Guard - Temporary changing working directory (chdir)
=head1 SYNOPSIS
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
=head1 DESCRIPTION
CORE::chdir Cwd:: Guard can change the current directory (chdir) using a limited scope.
=head1 FUNCTIONS
=over 4
=item cwd_guard($dir);
chdir to $dir and returns Cwd::Guard object. return to current working directory, if this object destroyed.
if failed to chdir, cwd_guard return undefined value. You can get error messages with $Gwd::Guard::Error.
=back
=head1 AUTHOR
Masahiro Nagano E<lt>kazeburo {at} gmail.comE<gt>
=head1 SEE ALSO
L<File::chdir>, L<File::pushd>
=head1 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.
=cut
|