in reply to Re^2: Possible to change package of code reference?
in thread Possible to change package of code reference?

I told you how, regex the new package into the text and eval it.

$func= eval qq( sub {$newtext} );

Another possibility is to temporarily patch &run before executing $func.

local *Spin::Command::spin::run = sub { "new code" }

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^4: Possible to change package of code reference?
by nysus (Parson) on Oct 21, 2018 at 21:10 UTC

    Ok, well, if you were suggesting that I modify the output of the deparser, that's what I did and was able to get things working. Thanks!

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      Be warned that this works just in your simple case.

      Any closure vars would lose their share and B::Deparse fails at some edge cases.

      It's not a fool save technique.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^4: Possible to change package of code reference?
by nysus (Parson) on Oct 21, 2018 at 20:46 UTC

    Are you talking about re-evaluating the output from B::Deparse?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks