Subject: | declarators don't work in s//.../e |
% cat Foo.pm
package Foo;
use strict;
use warnings;
use Devel::Declare;
sub import {
my $class = shift;
my $caller = caller;
Devel::Declare->setup_for(
$caller, {
flub => { const => \&parser },
}
);
no strict 'refs';
*{$caller . '::flub'} = sub (&) { $_[0]() };
}
sub parser {
my ($declarator, $offset) = @_;
$offset += Devel::Declare::toke_move_past_token($offset);
my $line = Devel::Declare::get_linestr;
substr($line, $offset) =~ s/^\s*(\S)(.*?)\1/ { q\x01<<$2>>\x01 }/;
Devel::Declare::set_linestr $line;
}
'ok'
__END__
% cat try.pl
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use Foo;
BEGIN {
say flub |one|;
}
BEGIN {
$_ = "";
s/^/eval 'say flub |two|'/e;
}
BEGIN {
$_ = "";
s/^/say flub |three|/e;
}
__END__
% perl try.pl
<<one>>
<<two>>
Not enough arguments for main::flub at try.pl line 20, near "flub |"
syntax error at try.pl line 20, near "|}"
BEGIN not safe after errors--compilation aborted at try.pl line 21.
Expected output:
<<one>>
<<two>>
<<three>>