summaryrefslogtreecommitdiff
path: root/lib/overload.t
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-11-04 10:12:20 +0000
committerDavid Mitchell <davem@iabyn.com>2012-06-13 13:25:52 +0100
commit9f141731d83a1ac6294a5580a5b11ff41490309a (patch)
treee71949f74544a981f3b594d10dc601589aa91740 /lib/overload.t
parent867940b89f1d3f001a6df1d888925b9ca246fe96 (diff)
downloadperl-9f141731d83a1ac6294a5580a5b11ff41490309a.tar.gz
Move bulk of pp_regcomp() into re_op_compile()
When called, pp_regcomp() is presented with a list of SVs on the stack. Previously, it would perform (amongst other things): * overloading those SVs; * concatenating them; * detection of bare /$qr/; * detection of unchanged pattern; optionally followed by a call to the built-in or an external regexp compiler. Since we want to avoid premature concatenation (so that we can handle /$runtime(?{...})/), move all these activities from pp_regcomp() into re_op_compile(). This makes re_op_compile() a bit cumbersome, with a large arg list, but I haven't found any way of only moving only a subset of the above. Note that a side-effect of this is that qr-overloading now works for all regex compilations, not just those reached via pp_regcomp(); in particular this now invokes the qr method rather than the "" method if available: /(??{ $overloaded_object })/
Diffstat (limited to 'lib/overload.t')
-rw-r--r--lib/overload.t11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/overload.t b/lib/overload.t
index 16a7486877..d5c1833ef2 100644
--- a/lib/overload.t
+++ b/lib/overload.t
@@ -48,7 +48,7 @@ package main;
$| = 1;
BEGIN { require './test.pl' }
-plan tests => 5049;
+plan tests => 5055;
use Scalar::Util qw(tainted);
@@ -1188,17 +1188,26 @@ foreach my $op (qw(<=> == != < <= > >=)) {
# doesn't look like a regex
ok("x" =~ $x, "qr-only matches");
ok("y" !~ $x, "qr-only doesn't match what it shouldn't");
+ ok("x" =~ /^(??{$x})$/, "qr-only with ?? matches");
+ ok("y" !~ /^(??{$x})$/, "qr-only with ?? doesn't match what it shouldn't");
ok("xx" =~ /x$x/, "qr-only matches with concat");
like("$x", qr/^QRonly=ARRAY/, "qr-only doesn't have string overload");
my $qr = bless qr/y/, "QRonly";
ok("x" =~ $qr, "qr with qr-overload uses overload");
ok("y" !~ $qr, "qr with qr-overload uses overload");
+ {
+ local $::TODO = '?? fails with "qr with qr"' ;
+ ok("x" =~ /^(??{$qr})$/, "qr with qr-overload with ?? uses overload");
+ ok("y" !~ /^(??{$qr})$/, "qr with qr-overload with ?? uses overload");
+ }
is("$qr", "".qr/y/, "qr with qr-overload stringify");
my $rx = $$qr;
ok("y" =~ $rx, "bare rx with qr-overload doesn't overload match");
ok("x" !~ $rx, "bare rx with qr-overload doesn't overload match");
+ ok("y" =~ /^(??{$rx})$/, "bare rx with qr-overload with ?? doesn't overload match");
+ ok("x" !~ /^(??{$rx})$/, "bare rx with qr-overload with ?? doesn't overload match");
is("$rx", "".qr/y/, "bare rx with qr-overload stringify");
}
{