diff --git a/ListUtil.xs b/ListUtil.xs index a4790dd..717f0fa 100644 --- a/ListUtil.xs +++ b/ListUtil.xs @@ -1717,6 +1717,7 @@ CODE: ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv))); XSRETURN(1); +#if !PERL_VERSION_GE(5, 40, 0) SV * blessed(sv) SV *sv @@ -1820,6 +1821,8 @@ CODE: ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv)); XSRETURN(1); +#endif /* !PERL_VERSION_GE(5, 40, 0) */ + int readonly(sv) SV *sv diff --git a/lib/Scalar/Util.pm b/lib/Scalar/Util.pm index 760e641..7ee4c42 100644 --- a/lib/Scalar/Util.pm +++ b/lib/Scalar/Util.pm @@ -23,6 +23,19 @@ $VERSION =~ tr/_//d; require List::Util; # List::Util loads the XS List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863) +if( $] >= 5.040 ) { + # On Perl 5.40 and above, these builtins are stable, so we can use them + # instead of our own XS implementation + + # Using this instead of a globref means we don't create an empty + # "builtins::" glob on older perls + no strict 'refs'; + my $builtins = \%{"builtin::"}; + + *$_ = \&{ $builtins->{$_} } for (qw( blessed refaddr reftype weaken unweaken )); + *isweak = \&{ $builtins->{is_weak} }; # renamed +} + # populating @EXPORT_FAIL is done in the XS code sub export_fail { if (grep { /^isvstring$/ } @_ ) {