我只能理解它在before/after情况下的作用,
它对around有什么作用
发布于 2011-08-28 02:23:09
根据实现,它似乎正在做类似于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);
}发布于 2011-08-25 18:11:45
看起来around就像before 和 after
从documentation
可选参数:
在subr之前调用了before => [subroutine(s)]。
around => [subroutine(s)]在subr附近调用。
在subr.之后调用after => [subroutine(s)]
https://stackoverflow.com/questions/7188429
复制相似问题