develooper Front page | perl.perl5.porters | Postings from September 2010

[perl #77974] [PATCH] Record method calls in the context stack

Thread Next
Ben Morrow
September 22, 2010 03:37
[perl #77974] [PATCH] Record method calls in the context stack
Message ID:
# New Ticket Created by  Ben Morrow 
# Please include the string:  [perl #77974]
# in the subject line of all future correspondence about this issue. 
# <URL: >

These patches record whether a given stack frame is for a function or a
method call, by adding a new OPpENTERSUB_PRIVATE bit. I need this for
PRE and POST blocks, which have different behaviour depending on whether
a sub is called as a method or not.

I looked at Devel::Caller::called_as_method, but unfortunately it gets
all but the simplest cases wrong; for instance:

    ~% perl -MDevel::Caller::called_as_method
        -E'sub foo { say "method: " . called_as_method } 
           foo and main->foo'

While this particular bug could possibly be fixed, the general approach
(starting at the previous COP and tracing forward to find the right
entersub OP) will necessarily fail in the case of calls made through
call_* (from the core or from XS), since the OPs created there aren't
in the optree at all.

I haven't attempted to export the flag to Perl, since I don't see
anything wrong with leaving Devel::Caller::called_as_method as the way
to get at this. I have, however, added a $DB::method variable, which is
set whenever $DB::sub is and indicates whether this is a method or a
function call.

I'm not entirely sure about the parts of this which touch B: it's in
ext/, so I presume it's not dual-life, but there seem to be lots of
dual-life-ish bits of code in there. I haven't made any attempt to
preserve compat with older perls; is this wrong?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About