Data :: Util :: modify_subroutine为“around”做了什么?

时间:2011-08-25 09:59:44

标签: perl

我只能理解它在before / after个案例中的作用,

它对around做了什么?

2 个答案:

答案 0 :(得分:2)

看起来around就像before after


来自documentation

  

可选参数:

     在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);
}