Created
June 19, 2020 06:16
-
-
Save exodist/f9cd1a96f4b5adba70ec7d9928281591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Devel::NeedABetterName; | |
use strict; | |
use warnings; | |
our %files; | |
our $on; | |
BEGIN { | |
# Avoid adding [...] stuff to evals in stack traces | |
$^P ^= (0x200); | |
$on = 1; | |
} | |
sub off { $on = 0 } | |
sub on { $on = 1 } | |
sub state { $on } | |
sub files { | |
my %CNI = reverse %INC; | |
my %seen; | |
map { my $f = $CNI{$_} // $_; $seen{$f}++ ? () : ($f) } sort keys %files; | |
} | |
{ | |
package # | |
DB; | |
sub sub { | |
no strict qw/refs vars/; | |
if ($Devel::Prof::on) { | |
# Without this carp adds '(\d+)' in stack traces | |
local @DB::args; | |
my ($pkg, $file) = caller(0); | |
if ($file) { | |
# Do not use a regex as that will modify $1, $7, etc. | |
# Convert "(eval \d+)[FILENAME:LINE]" into "FILENAME" | |
if (substr($file, 0, 5) eq '(eval') { | |
substr($file, 0, 5) = ''; | |
substr($file, 0, index($file, '[') + 1) = ''; | |
substr($file, index($file, ':', -1)) = ''; | |
} | |
$Devel::Prof::files{$file}++; | |
} | |
} | |
&$sub; | |
} | |
sub DB { } | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment