perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

add `&CORE::chdir` (properly)

Open mauke opened this issue 1 year ago • 0 comments

Previously, CORE::chdir was not "ampable", i.e. it could not be called through a coderef or with a sigil: &CORE::chdir($dir);

The only thing allowed was to make a compile-time alias, whose calls would then be inlined to chdir again:

BEGIN { *foo = \&CORE::chdir; }
foo ".";  # actually does chdir "."

However, this was broken if the function call used parentheses, in which case chdir would always try to use its argument as a filehandle, not the name of a directory:

BEGIN { *foo = \&CORE::chdir; }
foo(".");
# Triggers a warning:
# chdir() on unopened filehandle . at file line 2.

This commit fixes the problem and makes chdir fully "ampable", so &CORE::chdir() no longer triggers the &CORE::chdir cannot be called directly error.

mauke avatar Jun 30 '24 11:06 mauke