It seems I need to explain more about the "why" of what I'm doing. Here's an example:
sub initialize { return shift->call_super_before(\@_, sub { my($self) = @_; $self->die($self->get('values'), undef, 'number of elements mu +st be even') unless @{$self->get('values')} % 2 == 0; return; }); }

call_super_before uses code_ref_for_subroutine to figure out what the SUPER is from a $proto/$self and caller. I want SUPER to do something (put "values" on $self) and then I'm going to check the result. With call_super_before I don't need to know what SUPER returns or what it takes, it's all transparent to the subclass.

One suggestion was to use ->can, but this doesn't work, because it will return the subclass's method, not SUPER's method.

As to "what global lexicals" disappear, it's all of them as near as I can tell. A global lexical is one which is declared in the package scope so properly "package lexicals disappear". The difficulty is that the lexicals are undefined after they are initialized, that is,

my($_BAR) = 1; sub foo { return shift->call_super_before(\@_, sub { die('gone') unless $_BAR; return; }); }

During the first call to foo, $_BAR is false, even though it was initialized to 1.

Here's another tidbit, which is probably related:

package T1; sub s1 {print("T1:s1\n")} package T2; use base T1; package T3; use base T2; sub s1 {shift->SUPER::s1} package main; no strict 'refs'; exists($T2::{s1}) && die('not here'); T3->s1; exists($T2::{s1}) && die('here');

During the search for SUPER methods, $T2::{s1} is created with an empty value for *{$T2::{s1}}{CODE}. It's there, but not there. This is what I mean by semi-autovivification: the typeglob is created, but it doesn't contain anything.

Rob


In reply to Re: typeglob reference deletes global lexical by robnagler
in thread typeglob reference deletes global lexical by robnagler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.