develooper Front page | perl.perl5.porters | Postings from August 2016

Re: [PATCH] Alternative Fix for dot-in-INC mechanic.

Thread Previous | Thread Next
Aristotle Pagaltzis
August 25, 2016 06:11
Re: [PATCH] Alternative Fix for dot-in-INC mechanic.
Message ID:
* Smylers <> [2016-08-24 18:24]:
> Wait, why can't I get my suggested alternative to work? (I was just
> verifying it before pasting it in here.) Hmmm, actually, why can't
> I get Aristotle's code to work either?

It took me a while to figure out.

Because `bless` blesses the referent, not the reference. There can be
many references to the same object. In this case, the object is the
scalar also bound to $INC[-1]. Since @INC sticks around after $dotty is
gone, the scalar which is the object also sticks around.

So it’s necessary to pass `bless` a reference to some other thing – not
to $INC[-1]. Then $dotty is the only reference to *that* thing, so when
$dotty goes away at scope exit, the thing also goes away, so the thing’s
DESTROY fires. That thing can then have a reference to $INC[-1] inside.

Pointers can be a real mindfuck. (No arithmetic required. No matter what
you call them.)

Sorry I wasn’t clear that my code was not intended as any kind of actual
patch. I hacked it straight into the mail to illustrate the approach, as
I had found that code-free explanations are nearly incomprehensible. But
I did not write the code in the context of the actual code, much
less tested it. I should have disclaimed accordingly.

                                 — • —

That said, some notes in case a patch does ship:

• If a `package` statement is used, it needs the linebreak trick to hide
  it from PAUSE. (Riba’s patch had that. I switched to a fully-qualified
  sub name to avoid the need for that trick.)

• Haarg also pointed out that it ought to be `sub {()}`, not `sub {}`,
  because of a perl 5.8.early bug.

Aristotle Pagaltzis // <>

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