Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Release history of PerlOnJava. See [Roadmap](roadmap.md) for future plans.
CFB128, OFB, and CTR compatibility.
- Preserve string-compatible scalar channels for arithmetic results derived
from string operands on both execution backends.
- Honor imported overrides of the core `chmod` and `lock` built-ins.

## v5.44.1: Regex, Threads, Async/Await, and CPAN Compatibility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class ParserTables {
public static final Set<String> OVERRIDABLE_OP = Set.of(
"bless",
"atan2",
"caller", "chdir", "close", "connect",
"caller", "chdir", "chmod", "close", "connect",
"die", "do", "dump",
"exec", "exit",
"fork",
"getgrgid", "gethostbyname", "getpwuid", "glob",
"hex",
"kill",
"kill", "lock",
"localtime", "log",
"oct", "open",
"rand", "readline", "readpipe", "rename", "require",
Expand Down
41 changes: 41 additions & 0 deletions src/test/resources/unit/imported_core_builtin_override.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use strict;
use warnings;
use Test::More;

# Model the way a pure-Perl module exports a subroutine: assigning its CODE
# slot into the caller's package during import must make the imported sub win
# over a same-named core builtin.
BEGIN {
package ImportedCoreBuiltins;

sub chmod {
return 'imported chmod';
}

sub lock {
return 'imported lock';
}

sub import {
my ($class, $caller) = @_;
$caller //= caller;
no strict 'refs';
*{"${caller}::chmod"} = \&chmod;
*{"${caller}::lock"} = \&lock;
}

__PACKAGE__->import('main');
}

is(chmod('+r', 'unused'), 'imported chmod',
'imported chmod overrides the core builtin');
my $lock_name = 'unused';
is(lock($lock_name), 'imported lock',
'imported lock overrides the core builtin');
is(CORE::chmod(0, 'unused'), 0,
'CORE::chmod still selects the core builtin');
my $lock_target = 'unused';
is(CORE::lock($lock_target), 'unused',
'CORE::lock still selects the core builtin');

done_testing();
Loading