Created
August 8, 2013 09:43
-
-
Save ChinaXing/6183265 to your computer and use it in GitHub Desktop.
use B::Deparse module get source code of subroutine from its reference
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
# --- 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