Skip to content

Commit

Permalink
use VERSION implies use builtin :VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Jan 17, 2024
1 parent fb8fa88 commit 669c2a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -8046,6 +8046,12 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
PL_hints &= ~HINT_STRICT_VARS;
}

if (shortver >= SHORTVER(5, 39)) {
prepare_export_lexical();
import_builtin_bundle(shortver);
finish_export_lexical();
}

PL_prevailing_version = shortver;
}

Expand Down
18 changes: 12 additions & 6 deletions pod/perlfunc.pod
Original file line number Diff line number Diff line change
Expand Up @@ -10161,12 +10161,18 @@ Compare with L<C<require>|/require VERSION>, which can do a similar check
at run time.

If the specified Perl version is 5.12 or higher, strictures are enabled
lexically as with L<C<use strict>|strict>. Similarly, if the specified
Perl version is 5.35.0 or higher, L<warnings> are enabled. Later use of
C<use VERSION> will override all behavior of a previous C<use VERSION>,
possibly removing the C<strict>, C<warnings>, and C<feature> added by it.
C<use VERSION> does not load the F<feature.pm>, F<strict.pm>, or
F<warnings.pm> files.
lexically as with L<C<use strict>|strict>.

If the specified Perl version is 5.35.0 or higher, L<warnings> are enabled.

If the specified Perl version is 5.39.0 or higher, builtin functions are
imported lexically as with L<C<use builtin>|builtin> with a corresponding
version bundle.

Later use of C<use VERSION> will override all behavior of a previous
C<use VERSION>, possibly removing the C<strict>, C<warnings>, and C<feature>
added by it. C<use VERSION> does not load the F<feature.pm>, F<strict.pm>,
F<warnings.pm> or F<builtin.pm> files.

In the current implementation, any explicit use of C<use strict> or
C<no strict> overrides C<use VERSION>, even if it comes before it.
Expand Down
8 changes: 7 additions & 1 deletion t/comp/use.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm
}

print "1..85\n";
print "1..87\n";

# Can't require test.pl, as we're testing the use/require mechanism here.

Expand Down Expand Up @@ -170,6 +170,12 @@ ok $@, 'no strict vars allows ver decl to enable refs';
eval 'no strict "vars"; use 5.012; ursine_word';
ok $@, 'no strict vars allows ver decl to enable subs';

# check that "use 5.39.0" and higher imports builtins
{
my $result = eval 'use 5.39.0; my $t = true; $t eq "1"';
is ($@, "", 'builtin funcs available after use 5.39.0');
ok ($result, 'imported true is eq "1"');
}

{ use test_use } # check that subparse saves pending tokens

Expand Down

0 comments on commit 669c2a2

Please sign in to comment.