+my $is_debugging;
+
+sub is_debugging_perl {
+ return $is_debugging if defined $is_debugging;
+
+ my $source;
+
+ my $has_config_perl_v = do {
+ local $@;
+ eval { require Config::Perl::V; 1 };
+ };
+
+ if ($has_config_perl_v) {
+ $is_debugging = do {
+ local $@;
+ eval { Config::Perl::V::myconfig()->{build}{options}{DEBUGGING} };
+ };
+
+ if (defined $is_debugging) {
+ $source = "Config::Perl::V version $Config::Perl::V::VERSION";
+ }
+ }
+
+ unless (defined $is_debugging) {
+ $is_debugging = 0;
+ $source = "%Config";
+
+ require Config;
+ my @fields = qw<ccflags cppflags optimize>;
+
+ for my $field (@fields) {
+ my $content = $Config::Config{$field};
+
+ while ($content =~ /(-DD?EBUGGING((?:=\S*)?))/g) {
+ my $extra = $2 || '';
+ if ($extra ne '=none') {
+ $is_debugging = 1;
+ $source = "\$Config{$field} =~ /$1/";
+ }
+ }
+ }
+ }
+
+ my $maybe_is = $is_debugging ? "is" : "is NOT";
+ _diag("According to $source, this $maybe_is a debugging perl");
+
+ return $is_debugging;
+}
+