我找到的一种方法是通过检查已定义($ DB :: single)并假设Komodo处于活动状态来检查Perl调试器是否已“加载”,如果定义了$ DB :: single ..
但这也可能意味着该脚本在“独立”调试器下以 perl -d 合法运行。
#!/usr/local/ActivePerl-5.10/bin/perl
use strict;
use warnings;
use feature qw/say switch/;
# detect debugger ..
SayDebugerStatus();
sub SayDebugerStatus {
print "Debugger ";
given ($DB::single) {
when (undef) {
say "not loaded.";
}
when (0) {
say "loaded but inactive";
}
default {
say "loaded and active";
}
}
return defined($DB::single) ? 1:0;
}
zakovyrya 的建议导致:
if ( grep( /.*Komodo\ IDE\.app/g, values %INC) ){
say "Komodo is running"
} else {
say "Komodo is not running"
};
但还有另一种方法吗?
UPDATE 今天我的isKomodo()例程失败了。一些调查显示,IT将我的全局路径设置从“长”名称更改为“短名称”(这是在Windows下)..%INC哈希中不再是“KOMODO”字符串..
我正在寻找替代品。
答案 0 :(得分:2)
在Komodo下启动脚本时,%INC包含哪些内容?很有可能会加载一些特定于Komodo的模块。 最好用以下内容打印其内容:
use Data::Dumper;
print Dumper \%INC;
答案 1 :(得分:2)
似乎这样的事情比较容易(因为脚本知道它在Komodo下运行):
use Modern::Perl;
if (exists $ENV{'KOMODO_VERSION'}) {
say "Script is running under Komodo $ENV{'KOMODO_VERSION'} !";
} else {
say "script is not running in Komodo"
}
更新(由'lexu):KOMODO(7)现在将KOMODO_VERSION置于环境中