Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Re Class::MOP::Method::Wrapped: Out of curiosity, does it gather all the before/after/around stuff into one thoughtful list, or does it just keep chaining things with more single-use wrappers?

No, the Class::MOP::Method::Wrapped object keeps 3 ordered lists, one of befores, one of arounds and one of afters and it makes sure to apply them in the order you defined them. The docs actually go into a lot of detail about how this works.

And I was wondering... how does an 'after' method get called without having the wrapper show up in the call stack?

It does show up actually, they are named ":before", ":around" and ":after", here is a comment from the source explaining some of this:

# NOTE: # the methods above used to be named like this: # ${pkg}::${method}:(before|after|around) # but this proved problematic when using one modifier # to wrap multiple methods (something which is likely # to happen pretty regularly IMO). So instead of naming # it like this, I have chosen to just name them purely # with their modifier names, like so: # :(before|after|around) # The fact is that in a stack trace, it will be fairly # evident from the context what method they are attached # to, and so don't need the fully qualified name.

If the original is chained to with a GOTO, it won't get control back again.

It isn't done with GOTO actually, for exactly that reason, it is all quite controlled. If you look at the source you will see the $_build_wrapped_method method which does much of the dirty work.

o, the method enumerator does the same thing as autoclean, ...

Yes, but the method enumerator did it long before autoclean existed and way before autoclean was stable/sane.

Let me see if I'm following... for code that's been generated or otherwise not created using the classic 'sub' at package level, it won't record that origin and would always look like it was imported, even for generated methods like the accessors. So what that passage was trying to say is that a fully-quallified name in the Sub::Name or the natural origin of the function is used to determine if it was imported. Right?

Yes, but Sub::Name alters the internal (C-level) structure of the CV data structure to basically add the fully-qualified name. It then appears just as if it was originally defined in that package.

You talk about "B" and "stash" and other things not in my namespace, ...

B is the "The Perl Compiler Backend", it is a way to access all the C-level data structures from Perl. The "stash" is the name for an element of those data structures, specifically the place where I go to find the actual fully-qualified name of the sub.

... which makes me think now that the determination of the natural born name was not something it was originally meant to do.

Right, we had to get all sneaky and use XS to get at this stuff, it is not normally exposed in Perl.

So Sub::Name is a newer thing and Carp et al. were updated to look at it, but defining a sub still doesn't populate that itself?

No, Sub::Name alters the underly C-level structure such that when Carp gets to it,... it is just there. No changes had to be made to other modules.


In reply to Re^3: A couple questions on Moose::MOP::Class by stvn
in thread A couple questions on Moose::MOP::Class by John M. Dlugosz

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2021-10-19 12:22 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (76 votes). Check out past polls.