How can a Perl script detect if it is running within the Komodo IDE?

1.1k Views Asked by At

One way I found is to check if the Perl Debugger is "loaded" by checking for defined($DB::single) and assuming Komodo is active, if $DB::single is defined..

But this might also mean the script is legitimately running as perl -d under the "standalone" debugger.

#!/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's suggestion leads to:

if ( grep( /.*Komodo\ IDE\.app/g,  values %INC) ){
    say "Komodo is running"
} else {
   say "Komodo is not running"
};

But is there another way?


UPDATE today my isKomodo() routine failed. Some investigation showed, that IT changed my global path settings from "long" to "short" names (this is under Windows) .. there nolonger is a "KOMODO" string in the %INC hash..

I'm looking for a replacement.

2

There are 2 best solutions below

3
On BEST ANSWER

What does your %INC contain when you launch script under Komodo? There is a good chance that some Komodo-specific modules are loaded. It's better to print its content with:

use Data::Dumper;
print Dumper \%INC;
1
On

Seems like something like this is easier (for the script to know it's running under 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"
}

UPDATE(by 'lexu): KOMODO (7) now places KOMODO_VERSION in the environment