5 my $shadowed_called = 0;
9 is($name, 'fun', 'shadowed sub called with correct name');
10 is($sub->(), 'OH WHAT FUN', 'shadowed sub called with correct sub');
14 (our $Kw = Filter::Keyword->new(
15 target_package => __PACKAGE__,
16 keyword_name => 'method',
19 if (my ($stripped, $matches) = $kw->match_source('', '{')) {
20 my $name = $kw->current_match;
21 $stripped =~ s/{/sub ${name} { my \$self = shift;/;
22 return ($stripped, 1);
29 (our $Kw2 = Filter::Keyword->new(
30 target_package => __PACKAGE__,
31 keyword_name => 'shadowed',
34 if (my ($stripped, $matches) = $kw->match_source('', '{')) {
35 my $name = $kw->current_match;
36 $stripped =~ s/{/shadowed "${name}", sub { BEGIN { Filter::Keyword::inject_after_scope(';') } /;
37 return ($stripped, 1);
48 method yay { $line1 = __LINE__; "YAY $self" } $line2 = __LINE__;
49 is(__LINE__, 2, 'line number correct after first keyword');
51 is(__PACKAGE__->yay, 'YAY ' . __PACKAGE__, 'result of keyword correct');
52 is($line1, 1, 'line number correct in keyword');
53 is($line2, 1, 'line number correct on same line as keyword');
56 my $x = __LINE__ . " @{[ __LINE__ ]} method foo @{[ __LINE__ ]} " . __LINE__;
57 is(__LINE__, 2, 'line number correct after string with keyword');
58 is($x, '1 1 method foo 1 bar baz 1', 'line numbers in constructed string are correct');
68 is(__PACKAGE__->spoon, 'I HAZ A SPOON', 'result of multiline keyword');
69 is($line1, 2, 'line number correct in multiline keyword');
77 is(__PACKAGE__->spoon2, 'I HAZ A SPOON', 'result of second multiline keyword correct');
78 is($line2, 2, 'line number correct in second multiline keyword');
83 shadowed fun { $line1 = __LINE__; 'OH WHAT FUN' }
84 is($line1, 1, 'line number correct inside second keyword');
86 shadowed fun { $line2 = __LINE__; 'OH WHAT FUN' }
87 is($line1, 4, 'line number correct inside second keyword repeat');
96 is($line1, 2, 'line number correct inside second keyword multiline');
102 is($line2, 8, 'line number correct inside second keyword multiline');
104 is($shadowed_called, 4, 'shadowed sub called only by filter output');
106 is(__LINE__, 15, 'line number after shadowed correct');