Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created August 8, 2013 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChinaXing/6183265 to your computer and use it in GitHub Desktop.
Save ChinaXing/6183265 to your computer and use it in GitHub Desktop.
use B::Deparse module get source code of subroutine from its reference
# --- use B::Deparse module --- #
use B::Deparse; # or -MO=Deparse
sub mysub {
my $x = 20;
print "The X is : ", $x, "\n";
}
my $deparse = B::Deparse->new;
my $source = $deparse->coderef2text(\&mysub);
print "The source code of mysub is : \n", $source, "\n";
__END__
# ------------------ result ----------------------- #
=begin result
The source code of mysub is :
{
use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
my $x = 20;
print 'The X is : ', $x, "\n";
}
=end result
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment