我只能理解它在before
/ after
个案例中的作用,
它对around
做了什么?
答案 0 :(得分:2)
看起来around
就像before
和 after
可选参数:
在subr。之前调用
before => [subroutine(s)]
around => [subroutine(s)]
在subr。周围调用。之后调用
after => [subroutine(s)]
在subr。
答案 1 :(得分:1)
根据实施情况,似乎正在执行Sub::Curry
之类的操作:
static SV*
my_build_around_code(pTHX_ SV* code_ref, AV* const around){
I32 i;
for(i = av_len(around); i >= 0; i--){
CV* current;
MAGIC* mg;
SV* const sv = validate(*av_fetch(around, i, TRUE), T_CV);
AV* const params = newAV();
AV* const placeholders = newAV();
av_store(params, 0, newSVsv(sv)); /* base proc */
av_store(params, 1, newSVsv(code_ref)); /* first argument (next proc) */
av_store(params, 2, &PL_sv_undef); /* placeholder hole */
av_store(placeholders, 2, (SV*)PL_defgv); // *_
SvREFCNT_inc_simple_void_NN(PL_defgv);
current = newXS(NULL /* anonymous */, XS_Data__Util_curried, __FILE__);
mg = sv_magicext((SV*)current, (SV*)params, PERL_MAGIC_ext, &curried_vtbl, (const char*)placeholders, HEf_SVKEY);
SvREFCNT_dec(params); /* because: refcnt++ in sv_magicext() */
SvREFCNT_dec(placeholders); /* because: refcnt++ in sv_magicext() */
CvXSUBANY(current).any_ptr = (void*)mg;
code_ref = newRV_noinc((SV*)current);
sv_2mortal(code_ref);
}
return newSVsv(code_ref);
}