This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re_eval and closures: add lots of TODO tests
authorDavid Mitchell <davem@iabyn.com>
Mon, 8 Aug 2011 16:56:10 +0000 (17:56 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Jun 2012 12:25:49 +0000 (13:25 +0100)
commita39c66b9916c518396f68150e865c9d8e4d14018
tree0127cfd9858cc7dc5598f02c76343fac7caaac1f
parent3a21f53641810a6a40f55b82df4830150c373441
re_eval and closures: add lots of TODO tests

re_evals currently almost always do the wrong thing as regards what
lexical variable they refer to. This commit adds lots of TODO tests that
show what behaviour I think there should be. Note that because hardly any
of these tests pass yet, I haven't been able to verify whether they have
any subtle typos etc.

The basic philosophy behind these tests is:

* literal code is compiled once at compile-time and shares the same
  lexical environment as its surroundings; i.e.

    /A(?{..$x..})B/

  is like

    /A/ && do {..$x..} && /B/

* qr is treated as a closure: compiling once, but capturing its
  environment anew each time it is instantiated; i.e.

    for my $x (...) { push @r, qr/A(?{..$x..}B)/ }

  is like

    for my $x (...) { push @r, sub { /A/ && do {..$x..} && /B/ } }

* run-time code is recompiled each time the regex is compiled; literal
  code in the same expression isn't recompiled; i.e.

    $code = '(?{ BEGIN{$y++} })';
    for (1..3) { /(?{ BEGIN{$x++}})$code/ }
    # x==1, y==3

* an embedded qr is not stringified, so the qr retains its original
  lexical environment; i.e.

  $x = 1;
  { my $x = 2: $r = qr/(??{$x})/ }
  /A$r/; # matches A2, not A1
t/re/pat_re_eval.t