diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-03 05:19:56 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-10-03 05:19:56 +0000 |
commit | 78ca652eaf12f3ab6d7714883eec614d257f666a (patch) | |
tree | 6bbe81a261abeb34caf5651b686d45f2eb395c5f | |
parent | 39e216bc90d449c29ecedac1a04e0b8d579b806c (diff) | |
download | perl-78ca652eaf12f3ab6d7714883eec614d257f666a.tar.gz |
make C<use> recognize C<require> overrides; allow C<do EXPR> to be
overridden
p4raw-id: //depot/perl@1923
-rw-r--r-- | embed.h | 1 | ||||
-rw-r--r-- | global.sym | 1 | ||||
-rw-r--r-- | objXSUB.h | 2 | ||||
-rw-r--r-- | objpp.h | 2 | ||||
-rw-r--r-- | op.c | 41 | ||||
-rw-r--r-- | perly.c | 2 | ||||
-rw-r--r-- | perly.y | 2 | ||||
-rw-r--r-- | proto.h | 1 | ||||
-rw-r--r-- | vms/perly_c.vms | 2 |
9 files changed, 49 insertions, 5 deletions
@@ -159,6 +159,7 @@ #define do_trans Perl_do_trans #define do_vecset Perl_do_vecset #define do_vop Perl_do_vop +#define dofile Perl_dofile #define dofindlabel Perl_dofindlabel #define dopoptoeval Perl_dopoptoeval #define dounwind Perl_dounwind diff --git a/global.sym b/global.sym index 2536965135..8dff0fcc2d 100644 --- a/global.sym +++ b/global.sym @@ -270,6 +270,7 @@ do_tell do_trans do_vecset do_vop +dofile dofindlabel dopoptoeval dounwind @@ -911,6 +911,8 @@ #define do_vecset pPerl->Perl_do_vecset #undef do_vop #define do_vop pPerl->Perl_do_vop +#undef dofile +#define dofile pPerl->Perl_dofile #undef dowantarray #define dowantarray pPerl->Perl_dowantarray #undef dump_all @@ -299,6 +299,8 @@ #define do_report_used CPerlObj::do_report_used #undef docatch #define docatch CPerlObj::docatch +#undef dofile +#define dofile CPerlObj::Perl_dofile #undef dowantarray #define dowantarray CPerlObj::Perl_dowantarray #undef dump @@ -2580,6 +2580,7 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) OP *rqop; OP *imop; OP *veop; + GV *gv; if (id->op_type != OP_CONST) croak("Module name must be constant"); @@ -2631,8 +2632,21 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) newUNOP(OP_METHOD, 0, meth))); } - /* Fake up a require */ - rqop = newUNOP(OP_REQUIRE, 0, id); + /* Fake up a require, handle override, if any */ + gv = gv_fetchpv("require", FALSE, SVt_PVCV); + if (!(gv && GvIMPORTED_CV(gv))) + gv = gv_fetchpv("CORE::GLOBAL::require", FALSE, SVt_PVCV); + + if (gv && GvIMPORTED_CV(gv)) { + rqop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, id, + scalar(newUNOP(OP_RV2CV, 0, + newGVOP(OP_GV, 0, + gv)))))); + } + else { + rqop = newUNOP(OP_REQUIRE, 0, id); + } /* Fake up the BEGIN {}, which does its thing immediately. */ newSUB(floor, @@ -2649,6 +2663,29 @@ utilize(int aver, I32 floor, OP *version, OP *id, OP *arg) } OP * +dofile(OP *term) +{ + OP *doop; + GV *gv; + + gv = gv_fetchpv("do", FALSE, SVt_PVCV); + if (!(gv && GvIMPORTED_CV(gv))) + gv = gv_fetchpv("CORE::GLOBAL::do", FALSE, SVt_PVCV); + + if (gv && GvIMPORTED_CV(gv)) { + doop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, term, + scalar(newUNOP(OP_RV2CV, 0, + newGVOP(OP_GV, 0, + gv)))))); + } + else { + doop = newUNOP(OP_DOFILE, 0, scalar(term)); + } + return doop; +} + +OP * newSLICEOP(I32 flags, OP *subscript, OP *listval) { return newBINOP(OP_LSLICE, flags, @@ -2110,7 +2110,7 @@ case 134: break; case 135: #line 515 "perly.y" -{ yyval.opval = newUNOP(OP_DOFILE, 0, scalar(yyvsp[0].opval)); } +{ yyval.opval = dofile(yyvsp[0].opval); } break; case 136: #line 517 "perly.y" @@ -512,7 +512,7 @@ term : term ASSIGNOP term { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, append_elem(OP_LIST, $3, scalar($2))); } | DO term %prec UNIOP - { $$ = newUNOP(OP_DOFILE, 0, scalar($2)); } + { $$ = dofile($2); } | DO block %prec '(' { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); } | DO WORD '(' ')' @@ -129,6 +129,7 @@ VIRTUAL Off_t do_tell _((GV* gv)); VIRTUAL I32 do_trans _((SV* sv)); VIRTUAL void do_vecset _((SV* sv)); VIRTUAL void do_vop _((I32 optype, SV* sv, SV* left, SV* right)); +VIRTUAL OP* dofile _((OP* term)); VIRTUAL I32 dowantarray _((void)); VIRTUAL void dump_all _((void)); VIRTUAL void dump_eval _((void)); diff --git a/vms/perly_c.vms b/vms/perly_c.vms index 1583f61a10..1ff29a4716 100644 --- a/vms/perly_c.vms +++ b/vms/perly_c.vms @@ -2114,7 +2114,7 @@ case 134: break; case 135: #line 515 "perly.y" -{ yyval.opval = newUNOP(OP_DOFILE, 0, scalar(yyvsp[0].opval)); } +{ yyval.opval = dofile(yyvsp[0].opval); } break; case 136: #line 517 "perly.y" |