In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/c3890f9c66df165fa44ec6d4da220ab976c4d31d?hp=af352bf2fad22f15849580c84ed131e70e025d43>
- Log ----------------------------------------------------------------- commit c3890f9c66df165fa44ec6d4da220ab976c4d31d Author: David Mitchell <[email protected]> Date: Mon Feb 2 17:05:23 2015 +0000 add $B::OP::does_parent variable This will help people write B:: code that can, in a backwards-compatible way, handle the parent method that has recently been added, and whose behaviour varies depending on whether perl was built with PERL_OP_PARENT. ----------------------------------------------------------------------- Summary of changes: ext/B/B.pm | 5 +++++ ext/B/B.xs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/ext/B/B.pm b/ext/B/B.pm index f028d7c..5deaa2c 100644 --- a/ext/B/B.pm +++ b/ext/B/B.pm @@ -1139,6 +1139,11 @@ data structure. See top of C<op.h> for more info. Returns the OP's parent. If it has no parent, or if your perl wasn't built with C<-DPERL_OP_PARENT>, returns NULL. +Note that the global variable C<$B::OP::does_parent> is undefined on older +perls that don't support the C<parent> method, is defined but false on +perls that support the method but were built without C<-DPERL_OP_PARENT>, +and is true otherwise. + =item name This returns the op name as a string (e.g. "add", "rv2av"). diff --git a/ext/B/B.xs b/ext/B/B.xs index 31e855b..c4d218e 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -788,6 +788,7 @@ BOOT: { CV *cv; const char *file = __FILE__; + SV *sv; MY_CXT_INIT; B_init_my_cxt(aTHX_ &(MY_CXT)); cv = newXS("B::init_av", intrpvar_sv_common, file); @@ -820,6 +821,14 @@ BOOT: ASSIGN_COMMON_ALIAS(I, warnhook); cv = newXS("B::diehook", intrpvar_sv_common, file); ASSIGN_COMMON_ALIAS(I, diehook); + sv = get_sv("B::OP::does_parent", GV_ADDMULTI); + sv_setsv(sv, +#ifdef PERL_OP_PARENT + &PL_sv_yes +#else + &PL_sv_no +#endif + ); } #ifndef PL_formfeed -- Perl5 Master Repository
