- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何指定为我的原始脚本以及它直接加载的任何模块加载 Smart::Comments。然而,由于它是一个源过滤器,如果应用于每个其他加载模块加载的每个模块,它可能会造成严重破坏。
例如,我的脚本包括
use Neu::Image;
我想加载Smart::Comments
对于 Neu::Image
也是如此,但指定
$ perl -MSmart::Comments script.pl
未加载 Neu::Image
的 Smart::Comments
。
Smart::Comments documentation 中描述了此行为:
If you're debugging an application you can also invoke it with the module from the command-line:
perl -MSmart::Comments $application.pl
Of course, this only enables smart comments in the application file itself, not in any modules that the application loads.
我已经看过的其他一些内容:
解决方法正如 gbacon 提到的,Smart::Comments 提供了一个环境变量选项,允许打开或关闭它。但是,如果可能的话,我希望能够在不修改原始源的情况下打开它。
最佳答案
您几乎肯定希望将 use Smart::Comments
添加到包含此类内容的模块中,然后 flip the switch in your environment通过适当设置$Smart_Comments
。
隐藏修改、导入
-劫持猴子补丁是疯狂的。
但也许你喜欢这类事情。假设您有 Foo.pm
:
package Foo;
use Exporter 'import';
our @EXPORT = qw/ foo /;
#use Smart::Comments;
sub foo {
my @result;
for (my $i = 0; $i < 5; $i++) {
### $i
push @result => $i if $i % 2 == 0;
}
wantarray ? @result : \@result;
}
1;
普通用法:
$ perl -MFoo -e 'print foo, "\n"'024
Ordinary is dull and boring, of course. With run-foo
, we take bold, dashing steps!
#! /usr/bin/perl
use warnings;
use strict;
BEGIN {
unshift @INC => \&inject_smart_comments;
my %direct;
open my $fh, "<", $0 or die "$0: open: $!";
while (<$fh>) {
++$direct{$1} if /^\s*use\s+([A-Z][:\w]*)/;
}
close $fh;
sub inject_smart_comments {
my(undef,$path) = @_;
s/[\/\\]/::/g, s/\.pm$// for my $mod = $path;
if ($direct{$mod}) {
open my $fh, "<", $path or die "$0: open $path: $!";
return sub {
return 0 unless defined($_ = <$fh>);
s{^(\s*package\s+[A-Z][:\w]*\s*;\s*)$}
{$1 use Smart::Comments;\n};
return 1;
};
}
}
}
use Foo;
print foo, "\n";
(请原谅它的紧凑性:我缩小了它,以便它全部适合一个未滚动的 block 。)
输出:
$ ./run-foo### $i: 0### $i: 1### $i: 2### $i: 3### $i: 4024
万岁!
与 @INC
hooks我们可以替换我们自己的或修改过的来源。该代码监视对程序直接使用的 require
模块的尝试。命中时,inject_smart_comments
返回一个迭代器,一次生成一行。当这个狡猾、巧妙的迭代器看到包声明时,它会向该 block 附加一个看起来无辜的 use Smart::Comments
,使其看起来好像它一直在模块的源代码中一样。
例如,通过尝试使用正则表达式解析 Perl 代码,如果包声明本身不在一行,则代码将会中断。调味。
关于perl - 如何在加载的模块中使用 Smart::Comments 而不更改其源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2156943/
有没有办法在 Brainfuck 中做包含句点('.')的评论? 我知道我基本上可以使用不是命令之一的每个字符,它会被忽略,但我想在文件顶部的注释中放置一个版本号,其中包含一个句点。 最佳答案 您可以
我不明白以下代码的 % comment.length 位: comment.charAt(i % comment.length()) 括号之间的部分是否会转换为整数,其值表示与评论长度相关的i? 例如
我终于找到了我的 PHP 脚本无法运行的原因。这是因为 MySQL "--comment"而不是 "-- comment"。我最近开始使用 PHP,直到那时,我一直使用“--comment”。现在,我
是否可以在项目中搜索用户在 checkin 文件后添加的评论? (手动可以通过选择一个文件,右键单击 --> 显示历史记录 --> 选择版本 --> 详细信息,在评论 Pane 中查看)。 是否可以自
我不完全确定这是否不是插件,但是在 .js 文件中开始一行注释之后,例如,当我按下回车键时,下一行也以“//”开头。这有点烦人。有没有简单的方法可以删除它? 最佳答案 在“首选项 -> 包设置 ->
我在网上搜索,没有找到解释这个评论 block 用法的结果。因此,我希望有人能向我解释这种评论风格背后的原因。 /// Text goes here. 最佳答案 它们是 XML 文档注释。 http
这有充分的理由吗?这是一个蹩脚的问题,但我只是想知道是否有原因。 最佳答案 因为 specification允许/**/但不允许//:) 不过,严重的是,CSS 像对待所有其他空格一样对待换行符,并且
我有一个评论模型,我看过使用 @comment, :comment, comment 来引用 MVC 中的对象的示例。我怎么知道哪个是哪个?有区别吗? 最佳答案 @comment指 Rails Con
我有一些使用 Drupal 实现的网站。然而,尽管 Drupal 很酷,但我从未对它的编码感到满意,主要是因为它是在 PHP 中的,而且我想使用 python。我曾与 Django 调情,但我最近才发
似乎我仍然没有完全转变为 mac 用户(来自 Windows),再次遇到键盘快捷键问题: 在 phpstorm 中,下拉菜单中显示了以下“带有行注释的注释”的快捷方式: 现在,问题是,我的键盘上没有“
我正在按照 here 所述使用 fb:comments| . 评论工作正常,但我找不到在添加新评论时收到通知的方法。有没有办法轻松找到新评论(无需每次都访问我的 3000 篇文章)? 我知道 FB 对
我正在尝试创建一个功能,用户可以在其中使用 Ajax 创建对文章的评论。但是,我不明白为什么只有存在一个评论才能通过 ajax 成功呈现评论。评论提交到数据库,没有任何回滚。 如果我重新加载页面并创建
我正在使用 mongodb native 驱动器来获取查询结果的游标。 我正在使用一个“评论”字段,它基本上是一个字符串,下面是我正在使用的代码片段 let leve1_n = 'labreports
如果我将此URL放入浏览器中:。Https://www.facebook.com/plugins/comments.php?api_key=MYAPID。它会显示注释框,但不会显示任何评论。谁能告诉我
我想显示每个项目的评论数量和最后评论的日期。 SELECT item.*, count(comments.itemid) AS commentcount, comments.created A
这个问题在这里已经有了答案: What is the second parameter of NSLocalizedString()? (5 个答案) 关闭 6 年前。 我搜索并阅读了 NSLoca
我希望我的 Wordpress 博客中的字幕能够计算我的帖子在 Facebook 上的评论数。插入Facebook的代码后 ID); ?>"> comments 我意识到当我只有 1
我在我的项目中收到以下 TsLint 消息: TsLint: comment must start with lowercase letter 这背后有什么依据吗?我同意我在 TsLint 中遇到的大
我正在使用以下代码完成教程: New Comment @comment = Comment.new, :locals => { :button_name => "Create" } %>
环境 适用于macOS的Visual Studio代码1.18.0。 主题hedinne.popping-and-locking-vscode,由 hedinne 组成。 问题 当我覆盖/*> edi
我是一名优秀的程序员,十分优秀!