This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
uni/cache.t: Fix to handle regex compile time Uni props
authorKarl Williamson <public@khwilliamson.com>
Mon, 21 Nov 2011 02:10:19 +0000 (19:10 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 13 Jan 2012 16:58:33 +0000 (09:58 -0700)
Future commits are planned to move the resolution of Unicode properties
from regex execution time to compile time.  By moving the code into a
BEGIN block, this .t can now handle both types.  Before this patch, it
wouldn't show any activity at all if things are done at compile time.

t/uni/cache.t

index df12f33..74ce1f0 100644 (file)
@@ -6,11 +6,17 @@ BEGIN {
 
 plan tests => 1;
 
-my $count = 0;
-unshift @INC, sub {
-       # XXX Kludge requires exact path, which might change
-       $count++ if $_[1] eq 'unicore/lib/Sc/Hira.pl';
-};
+# Looks to see if a "do 'unicore/lib/Sc/Hira.pl'" is called more than once, by
+# putting a compile sub first on the libary path;
+# XXX Kludge: requires exact path, which might change, and has deep knowledge
+# of how utf8_heavy.pl works, which might also change.
+
+BEGIN { # Make sure catches compile time references
+    $::count = 0;
+    unshift @INC, sub {
+       $::count++ if $_[1] eq 'unicore/lib/Sc/Hira.pl';
+    };
+}
 
 my $s = 'foo';
 
@@ -19,4 +25,4 @@ $s =~ m/[\p{Hiragana}]/;
 $s =~ m/[\p{Hiragana}]/;
 $s =~ m/[\p{Hiragana}]/;
 
-is($count, 1, "Swatch hash caching kept us from reloading swatch hash.");
+is($::count, 1, "Swatch hash caching kept us from reloading swatch hash.");