| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| |
| 6 |
16 |
| static int call_remove(pTHX_ SV* var, MAGIC* magic) { |
| 7 |
16 |
| sv_unmagic(var, PERL_MAGIC_ext); |
| 8 |
16 |
| } |
| 9 |
|
| |
| 10 |
7 |
| static int call_get(pTHX_ SV* var, MAGIC* magic) { |
| 11 |
7 |
| dSP; |
| 12 |
|
| int i; |
| 13 |
7 |
| AV* arguments = (AV*)magic->mg_ptr; |
| 14 |
7 |
| ENTER; |
| 15 |
7 |
| SAVETMPS; |
| 16 |
7 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
7 |
7 |
|
| 17 |
7 |
▶ | for(i = 0; i < av_len(arguments); i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for(i = 0; i < av_len(arguments); i++) |
0 |
7 |
7 |
|
| 18 |
0 |
▶ | XPUSHs(*av_fetch(arguments, i, FALSE)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(*av_fetch(arguments, i, FALSE)); |
0 |
0 |
0 |
|
| 19 |
7 |
| PUTBACK; |
| 20 |
7 |
| call_sv(magic->mg_obj, G_SCALAR); |
| 21 |
7 |
| SPAGAIN; |
| 22 |
7 |
| call_remove(aTHX_ var, magic); |
| 23 |
7 |
| sv_setsv_mg(var, POPs); |
| 24 |
7 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
7 |
0 |
7 |
|
| 25 |
7 |
| LEAVE; |
| 26 |
7 |
| } |
| 27 |
|
| |
| 28 |
|
| static const MGVTBL magic_table = { call_get, call_remove, 0, call_remove, 0}; |
| 29 |
|
| |
| 30 |
|
| MODULE = Variable::Lazy::Guts PACKAGE = Variable::Lazy::Guts |
| 31 |
|
| |
| 32 |
|
| SV* |
| 33 |
|
| lazy(variable, arguments, subref) |
| 34 |
|
| SV* variable; |
| 35 |
|
| SV* arguments = SvRV(ST(1)); |
| 36 |
|
| SV* subref; |
| 37 |
|
| CODE: |
| 38 |
8 |
| SvREFCNT_inc(arguments); |
| 39 |
8 |
| call_remove(aTHX_ variable, NULL); |
| 40 |
8 |
| sv_magicext(variable, (SV*)subref, PERL_MAGIC_ext, &magic_table, (char*)arguments, HEf_SVKEY); |
| 41 |
|
| /* Returns its own first argument */ |