Hi all
Recently,
someone asked how to turn code back into source. The possibility of doing this, combined with the possibility of
evaluate source into code during execution time permits editing code
in situ, like in this dummy example:
use strict;
use warnings;
use B::Deparse;
my $subref = sub {print "Hello\n"};
$subref->();
my $code = B::Deparse->new->coderef2text($subref);
$code =~ s/print\s\S+/die "Bye";/;
$subref = eval "sub $code";
$subref->();
Outputs:
Hello
Bye at (eval 6) line 4.
I find this possibility amazing, and potentially useful, but apart from the module Sub::Compose (where this technique is used to combine several subroutines into one), I didn't find any other code that uses it. Have you ever seen this technique used in real code (apart from the commented example)? Is there any case where you can anticipate that this technique could be specially useful?
citromatik