【发布时间】:2011-08-08 20:58:56
【问题描述】:
我正在尝试学习Devel::Declare,以便尝试在没有源过滤器的情况下重新实现PDL::NiceSlice 之类的东西。当我注意到它正在从我的脚本中删除下一行时,我正在到达某个地方。为了说明这一点,我做了一个最小的示例,其中可以使用 comment 关键字从代码中删除整行,即使该行上有很多裸词也允许编译。
#Comment.pm
package Comment;
use strict;
use warnings;
use Devel::Declare ();
sub import {
my $class = shift;
my $caller = caller;
Devel::Declare->setup_for(
$caller,
{ comment => { const => \&parser } }
);
no strict 'refs';
*{$caller.'::comment'} = sub {};
}
sub parser {
#my $linestr = Devel::Declare::get_linestr;
#print $linestr;
Devel::Declare::set_linestr("");
}
1
和
#!/usr/bin/env perl
#test.pl
use strict;
use warnings;
use Comment;
comment stuff;
print "Print 1\n";
print "Print 2\n";
只产生
Print 2
我错过了什么?
附:如果我应该解决这个问题,我可能会在D::D 上提出更多问题,所以提前谢谢!
【问题讨论】: