xref: /openbsd-src/gnu/usr.bin/perl/cpan/NEXT/t/dynamically_scoped_regex_vars.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1use strict;
2use warnings;
3use Test::More tests => 7;
4
5BEGIN { use_ok('NEXT') };
6
7package A;
8use base qw(B);
9use NEXT;
10sub test_next { shift->NEXT::test_next(@_); }
11sub test_next_distinct { shift->NEXT::DISTINCT::test_next_distinct(@_); }
12sub test_next_actual { shift->NEXT::ACTUAL::test_next_actual(@_); }
13sub test_next_actual_distinct { shift->NEXT::ACTUAL::DISTINCT::test_next_actual_distinct(@_); }
14sub test_every { shift->EVERY::test_every(@_); }
15sub test_every_last { shift->EVERY::LAST::test_every_last(@_); }
16
17package B;
18sub test_next { $_[1]; }
19sub test_next_distinct { $_[1]; }
20sub test_next_actual { $_[1]; }
21sub test_next_actual_distinct { $_[1]; }
22sub test_every { $_[1]; }
23sub test_every_last { $_[1]; }
24
25package main;
26
27my $foo = bless {}, 'A';
28
29"42" =~ /(.*)/;
30is($foo->test_next($&), $&, "The value of '\$&' was not overwritten in NEXT.");
31
32"42" =~ /(.*)/;
33is($foo->test_next_distinct($&), $&, "The value of '\$&' was not overwritten in NEXT::DISTINCT.");
34
35"42" =~ /(.*)/;
36is($foo->test_next_actual($&), $&, "The value of '\$&' was not overwritten in NEXT::ACTUAL.");
37
38"42" =~ /(.*)/;
39is($foo->test_next_actual_distinct($&), $&, "The value of '\$&' was not overwritten in NEXT::ACTUAL::DISTINCT.");
40
41"42" =~ /(.*)/;
42is($foo->test_every($&)->{'B::test_every'}, $&, "The value of '\$&' was not overwritten in EVERY.");
43
44"42" =~ /(.*)/;
45is($foo->test_every_last($&)->{'B::test_every_last'}, $&, "The value of '\$&' was not overwritten in EVERY::LAST.");
46