develooper Front page | perl.perl5.porters | Postings from June 2021

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
Paul "LeoNerd" Evans
June 17, 2021 20:41
Re: RFC 0004 - defer {} syntax
Message ID:
On Thu, 17 Jun 2021 22:32:46 +0200
Branislav ZahradnĂ­k <> wrote:

> words like __PACKAGE__, 

__PACKAGE__, along with __FUNC__, __LINE__, __FILE__, etc.. are all
dunder-shouties, as they are constants. The parser literally replaces
them with a string (or number, in the case of __LINE__):

  $ perl -MO=Deparse -ce 'my $file = __FILE__';
  my $file = '-e';


AUTOLOAD is one of those weird things that probably should be specified
with `sub`; it's supposed to be

  sub AUTOLOAD {

just that the parser lets you get away without the `sub`.

> or taken from Ovid's Corinna, ADJUST

Ah; but ADJUST _is_ a phaser. It's a block of code whose _mere
presence at compile time_ is sufficient:

  LOOP: {
    class AClass {
      has $slot;
      last LOOP;

      ADJUST { $slot = 123; }
      method greet { say "Slot is $slot" }

  Slot is 123

Even though the line on which the ADJUST phaser was declared was never
dynamically reached (because we `last`ed out before it got there),
nevertheless the mere declaration of it was sufficient for it to be
active; much like the subsequent `method`.

Paul "LeoNerd" Evans      |  |

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