blob: 625896f602e5de91454bd0ae304568844937cf57 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
BEGIN {
if (!eval { require B::Hooks::EndOfScope }) {
plan skip_all => "B::Hooks::EndOfScope is required for this test";
}
}
BEGIN {
package My::Parser;
use Exporter 'import';
our @EXPORT = 'foo';
use Parse::Keyword { foo => \&parse_foo };
sub foo { $_[0]->() }
sub parse_foo {
lex_read_space;
die "syntax error" unless lex_peek eq '{';
lex_read;
lex_stuff(
'{'
. 'my $foo = 42;'
. '{'
. 'BEGIN { B::Hooks::EndOfScope::on_scope_end {'
. 'Parse::Keyword::lex_stuff(q[}])'
. '} }'
);
my $body = parse_block;
return sub { $body };
}
$INC{'My/Parser.pm'} = __FILE__;
}
use My::Parser;
is(foo { $foo }, 42);
{
my $warnings;
local $SIG{__WARN__} = sub { $warnings .= $_[0] };
is(foo { my $foo = 12; $foo }, 12);
is($warnings, undef);
}
done_testing;
|