mob mob - 6 months ago 12
Perl Question

How to detect ActiveState version of perl?

One of my CPAN modules is not available on ActivePerl through its

ppm
utility. Apparently my unit testing for this module is too thorough and ActiveState's build process times out when it attempts to build it.

So what I would like to do in my tests is to detect when my module is being built on ActivePerl, and if so, to provide the build process with a smaller and faster set of tests.

One way I've found to do this is:

($is_activestate) = grep /provided by ActiveState/, qx($^X -v)


but I'm wondering if there is a more lightweight option. An environment variable that is always (and only) set in ActivePerl? Something in
Config
? Any other suggestions?

Answer

Checking if it's running under an ActivePerl build is not optimal. Ideally, you want to check if it's running in ActiveState's build environment. I would dump the env in t/00-use.t to see if they set some variable indicating this.

info("$_=$ENV{$_}") for sort keys %ENV;

You could also contact ActiveState and ask them what they recommend.


Alternatively, you could make it so the slowest tests only run on demand. 5 minutes of testing might seem a bit excessive to others as well.


As for checking if you're running an ActiveState build, here are some possibilities:

  • use Config; print Config::local_patches(); returns a string that includes ActivePerl Build.
  • $Config{cf_email} is set to support@ActiveState.com
  • The ActivePerl::Config module exists.
  • The ActivePerl::PPM module exists.

Could always check all of them.

use Config qw( %Config );

my $is_activeperl = 0;
$is_activeperl ||= eval { Config::local_patches() =~ /ActivePerl/i };
$is_activeperl ||= $Config{cf_email} =~ /ActiveState/i;
$is_activeperl ||= eval { require ActivePerl::Config };
$is_activeperl ||= eval { require ActivePerl::PPM };
Comments