Skip to content

Instantly share code, notes, and snippets.

@exodist
Created June 19, 2020 04:41
Show Gist options
  • Save exodist/f2975353a4639a52c09af1ceb79a6a90 to your computer and use it in GitHub Desktop.
Save exodist/f2975353a4639a52c09af1ceb79a6a90 to your computer and use it in GitHub Desktop.
package Devel::Prof;
use strict;
use warnings;
our %files;
no warnings 'redefine';
our $on;
BEGIN { $on = 1 };
sub off { $on = 0 };
# uncommenting this causes the main script to say Dumper is not defined.
#sub DB::sub {
# return unless $on;
# my ($pkg, $file) = caller(0);
# $Devel::Prof::files{$file}++;
# return;
#};
sub DB::DB {
return unless $on;
my ($pkg, $file, $line, $sub) = caller(0);
$Devel::Prof::files{$file}++;
return;
}
sub files { \%files }
1;
perl -Ilib -d:Prof yyy.pl
$VAR1 = {
'lib/Devel/Prof.pm' => 1,
'yyy.pl' => 7
};
# If I uncomment sub DB::sub
perl -Ilib -d:Prof yyy.pl
Use of uninitialized value $file in hash element at lib/Devel/Prof.pm line 18.
Use of uninitialized value $file in hash element at lib/Devel/Prof.pm line 18.
Use of uninitialized value $file in hash element at lib/Devel/Prof.pm line 18.
Undefined subroutine &main::Dumper called at yyy.pl line 14.
use strict;
use warnings;
use Data::Dumper;
use YYY;
sub Bar { eval { Foo::Bar() } }
sub Foo::Bar { Foo::Bar::Bar() }
sub Foo::Bar::Bar { sub { 'BAR' }->() }
Bar();
Devel::Prof->off();
local $Data::Dumper::Sortkeys = 1;
print Dumper(Devel::Prof->files);
use XXX;
sub xxx { 1 };
xxx();
sub import { 1 }
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment