Skip to content

Commit 5fb4138

Browse files
committed
Split the guts of pp_require into two static fns
S_require_version() and S_require_file() do the 'require 5.010001' and 'require Foo::Bar' actions respectively. This makes it clear that pp_require is effectively 2 disjoint functions, and that all the local variables previously declared at the start of pp_require actually belong exclusively to the file loading functionality. This is based on a patch by Nicholas from 4 years ago, except that I did the split from scratch since pp_require has been touched quite a bit since then. This commit splits it in such a way that the diff is kept as small as possible. The next commit will re-indent.
1 parent da7cf1c commit 5fb4138

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

pp_ctl.c

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,38 +3582,13 @@ S_path_is_searchable(const char *name)
35823582
}
35833583

35843584

3585-
/* also used for: pp_dofile() */
3585+
/* implement 'require 5.010001' */
35863586

3587-
PP(pp_require)
3587+
static OP *
3588+
S_require_version(pTHX_ SV *sv)
35883589
{
3589-
dSP;
3590-
PERL_CONTEXT *cx;
3591-
SV *sv;
3592-
const char *name;
3593-
STRLEN len;
3594-
char * unixname;
3595-
STRLEN unixlen;
3596-
#ifdef VMS
3597-
int vms_unixname = 0;
3598-
char *unixdir;
3599-
#endif
3600-
const char *tryname = NULL;
3601-
SV *namesv = NULL;
3602-
const U8 gimme = GIMME_V;
3603-
int filter_has_file = 0;
3604-
PerlIO *tryrsfp = NULL;
3605-
SV *filter_cache = NULL;
3606-
SV *filter_state = NULL;
3607-
SV *filter_sub = NULL;
3608-
SV *hook_sv = NULL;
3609-
OP *op;
3610-
int saved_errno;
3611-
bool path_searchable;
3612-
I32 old_savestack_ix;
3590+
dVAR; dSP;
36133591

3614-
sv = POPs;
3615-
SvGETMAGIC(sv);
3616-
if ( (SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) {
36173592
sv = sv_2mortal(new_version(sv));
36183593
if (!Perl_sv_derived_from_pvn(aTHX_ PL_patchlevel, STR_WITH_LEN("version"), 0))
36193594
upg_version(PL_patchlevel, TRUE);
@@ -3669,7 +3644,40 @@ PP(pp_require)
36693644
}
36703645

36713646
RETPUSHYES;
3672-
}
3647+
}
3648+
3649+
/* Handle C<require Foo::Bar>, C<require "Foo/Bar.pm"> and C<do "Foo.pm">.
3650+
* The first form will have already been converted at compile time to
3651+
* the second form */
3652+
3653+
static OP *
3654+
S_require_file(pTHX_ SV *const sv)
3655+
{
3656+
dVAR; dSP;
3657+
3658+
PERL_CONTEXT *cx;
3659+
const char *name;
3660+
STRLEN len;
3661+
char * unixname;
3662+
STRLEN unixlen;
3663+
#ifdef VMS
3664+
int vms_unixname = 0;
3665+
char *unixdir;
3666+
#endif
3667+
const char *tryname = NULL;
3668+
SV *namesv = NULL;
3669+
const U8 gimme = GIMME_V;
3670+
int filter_has_file = 0;
3671+
PerlIO *tryrsfp = NULL;
3672+
SV *filter_cache = NULL;
3673+
SV *filter_state = NULL;
3674+
SV *filter_sub = NULL;
3675+
SV *hook_sv = NULL;
3676+
OP *op;
3677+
int saved_errno;
3678+
bool path_searchable;
3679+
I32 old_savestack_ix;
3680+
36733681
if (!SvOK(sv))
36743682
DIE(aTHX_ "Missing or undefined argument to require");
36753683
name = SvPV_nomg_const(sv, len);
@@ -4062,6 +4070,21 @@ PP(pp_require)
40624070
return op;
40634071
}
40644072

4073+
4074+
/* also used for: pp_dofile() */
4075+
4076+
PP(pp_require)
4077+
{
4078+
dSP;
4079+
SV *sv = POPs;
4080+
SvGETMAGIC(sv);
4081+
PUTBACK;
4082+
return ((SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE)
4083+
? S_require_version(aTHX_ sv)
4084+
: S_require_file(aTHX_ sv);
4085+
}
4086+
4087+
40654088
/* This is a op added to hold the hints hash for
40664089
pp_entereval. The hash can be modified by the code
40674090
being eval'ed, so we return a copy instead. */

0 commit comments

Comments
 (0)